mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Allow locally hosted RPC and Block Explorer Urls with wallet_addEthereumChain
(#14272)
* add function to check if url is localhost * allow localhost rpcUrls in `wallet_addEthereumChain` * allow localhost blockExplorerUrls * wrap new URL in try/catch
This commit is contained in:
parent
1e64ef419b
commit
8930df7951
@ -77,13 +77,26 @@ async function addEthereumChainHandler(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isLocalhost = (strUrl) => {
|
||||||
|
try {
|
||||||
|
const url = new URL(strUrl);
|
||||||
|
return url.hostname === 'localhost' || url.hostname === '127.0.0.1';
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const firstValidRPCUrl = Array.isArray(rpcUrls)
|
const firstValidRPCUrl = Array.isArray(rpcUrls)
|
||||||
? rpcUrls.find((rpcUrl) => validUrl.isHttpsUri(rpcUrl))
|
? rpcUrls.find(
|
||||||
|
(rpcUrl) => isLocalhost(rpcUrl) || validUrl.isHttpsUri(rpcUrl),
|
||||||
|
)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const firstValidBlockExplorerUrl =
|
const firstValidBlockExplorerUrl =
|
||||||
blockExplorerUrls !== null && Array.isArray(blockExplorerUrls)
|
blockExplorerUrls !== null && Array.isArray(blockExplorerUrls)
|
||||||
? blockExplorerUrls.find((blockExplorerUrl) =>
|
? blockExplorerUrls.find(
|
||||||
|
(blockExplorerUrl) =>
|
||||||
|
isLocalhost(blockExplorerUrl) ||
|
||||||
validUrl.isHttpsUri(blockExplorerUrl),
|
validUrl.isHttpsUri(blockExplorerUrl),
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
|
Loading…
Reference in New Issue
Block a user