Skip to content

Commit 1c6c5a3

Browse files
authored
feat: use snowscan for avalanche (#133)
1 parent 17f862c commit 1c6c5a3

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/utils/chains.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ export const initialRpcUrls: Record<number, string[]> = {
122122
};
123123

124124
export function setChain(chain: Chain, url?: string) {
125+
const explorers: Record<number, { name: string; url: string }> = {
126+
[gnosis.id]: {
127+
name: 'Gnosis chain explorer',
128+
url: 'https://gnosisscan.io',
129+
},
130+
[avalanche.id]: { name: 'Snowscan', url: 'https://snowscan.xyz' },
131+
[avalancheFuji.id]: {
132+
name: 'Snowscan Fuji',
133+
url: 'https://testnet.snowscan.xyz',
134+
},
135+
};
136+
137+
const defaultExplorer = explorers[chain.id] || chain.blockExplorers?.default;
138+
125139
return {
126140
...chain,
127141
rpcUrls: {
@@ -133,10 +147,7 @@ export function setChain(chain: Chain, url?: string) {
133147
},
134148
blockExplorers: {
135149
...chain.blockExplorers,
136-
default:
137-
chain.id === gnosis.id
138-
? { name: 'Gnosis chain explorer', url: 'https://gnosisscan.io' }
139-
: chain.blockExplorers?.default || mainnet.blockExplorers.default,
150+
default: defaultExplorer,
140151
},
141152
};
142153
}

src/utils/getScanLink.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import { Address } from 'viem';
2-
31
import { appConfig } from './appConfig';
4-
import { chainInfoHelper } from './configs';
2+
import { CHAINS } from './chains';
53

64
export function getScanLink({
75
chainId = appConfig.govCoreChainId,
86
address,
97
type = 'address',
108
}: {
119
chainId?: number;
12-
address: Address | string;
10+
address: string;
1311
type?: 'address' | 'tx';
1412
}) {
15-
return `${
16-
chainInfoHelper.getChainParameters(chainId).blockExplorers?.default.url
17-
}/${type}/${address}`;
13+
const baseUrl = CHAINS[chainId]?.blockExplorers?.default.url || '';
14+
const url = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
15+
return `${url}${type}/${address}`;
1816
}

0 commit comments

Comments
 (0)