Skip to content

Commit d064137

Browse files
fix: simplify how to get explorer url
1 parent 87ea6fb commit d064137

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

app/components/UI/Swaps/utils/useBlockExplorer.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import { strings } from '../../../../../locales/i18n';
99
import { getEtherscanBaseUrl } from '../../../../util/etherscan';
1010
import { useSelector } from 'react-redux';
1111
import {
12-
selectEvmChainId,
1312
selectProviderConfig,
1413
} from '../../../../selectors/networkController';
15-
import { selectNetworkName } from '../../../../selectors/networkInfos';
1614

1715
function useBlockExplorer(networkConfigurations, providerConfigTokenExplorer) {
1816
const [explorer, setExplorer] = useState({
@@ -23,30 +21,23 @@ function useBlockExplorer(networkConfigurations, providerConfigTokenExplorer) {
2321
baseUrl: '',
2422
});
2523
const providerConfig = useSelector(selectProviderConfig);
26-
const chainId = useSelector(selectEvmChainId);
27-
const networkName = useSelector(selectNetworkName);
2824

2925
useEffect(() => {
3026
const definitiveProviderConfig =
3127
providerConfigTokenExplorer ?? providerConfig;
3228
try {
33-
const networkConfigurationsByChainId = networkConfigurations?.[chainId]
34-
let blockExplorer = networkConfigurationsByChainId.blockExplorerUrls?.[
35-
networkConfigurationsByChainId.defaultBlockExplorerUrlIndex
36-
]
37-
38-
if (!blockExplorer) {
39-
// If no block explorer URL is found in the network configurations,
40-
// we attempt to retrieve it using a hardcoded Etherscan URL mapping.
41-
// Additionally, since `definitiveProviderConfig.type` defaults to `rpc` for non-built-in networks,
42-
// the fallback is applied only to built-in networks, as they all use Etherscan.
43-
if (definitiveProviderConfig.type !== RPC) {
44-
blockExplorer = getEtherscanBaseUrl(definitiveProviderConfig.type)
45-
}
29+
const { rpcUrl , type } = definitiveProviderConfig;
30+
31+
let blockExplorer;
4632

47-
if (!blockExplorer) {
48-
throw new Error('No block explorer url');
49-
}
33+
if (type === RPC && rpcUrl) {
34+
blockExplorer = findBlockExplorerForRpc(rpcUrl, networkConfigurations)
35+
} else {
36+
blockExplorer = getEtherscanBaseUrl(type);
37+
}
38+
39+
if (!blockExplorer) {
40+
throw new Error('No block explorer url');
5041
}
5142

5243
const url = new URL(blockExplorer);
@@ -77,8 +68,6 @@ function useBlockExplorer(networkConfigurations, providerConfigTokenExplorer) {
7768
networkConfigurations,
7869
providerConfig,
7970
providerConfigTokenExplorer,
80-
chainId,
81-
networkName,
8271
]);
8372

8473
const tx = useCallback(

0 commit comments

Comments
 (0)