forked from reown-com/appkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wagmiTools.ts
86 lines (78 loc) · 2.52 KB
/
wagmiTools.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { chain, InjectedConnector } from '@wagmi/core'
import { CoinbaseWalletConnector } from '@wagmi/core/connectors/coinbaseWallet'
import { MetaMaskConnector } from '@wagmi/core/connectors/metaMask'
import { WalletConnectConnector } from '@wagmi/core/connectors/walletConnect'
import { alchemyProvider } from '@wagmi/core/providers/alchemy'
import { infuraProvider } from '@wagmi/core/providers/infura'
import { jsonRpcProvider } from '@wagmi/core/providers/jsonRpc'
import { publicProvider } from '@wagmi/core/providers/public'
import type { GetDefaultConnectorsOpts, GetWalletConnectProviderOpts } from '../../types/apiTypes'
import {
avalanche,
avalancheFuji,
binanceSmartChain,
binanceSmartChainTestnet,
fantom,
fantomTestnet
} from './chains'
import { NAMESPACE } from './constants'
// -- utilities ------------------------------------------------------- //
const customChains = [
avalanche,
avalancheFuji,
binanceSmartChain,
binanceSmartChainTestnet,
fantom,
fantomTestnet
]
// -- providers ------------------------------------------------------- //
function walletConnectProvider({ projectId }: GetWalletConnectProviderOpts) {
return jsonRpcProvider({
rpc: rpcChain => {
const customChain = customChains.find(c => c.id === rpcChain.id)
if (customChain)
return {
http: customChain.rpcUrls.default
}
return {
http: `https://rpc.walletconnect.com/v1/?chainId=${NAMESPACE}:${rpcChain.id}&projectId=${projectId}`
}
}
})
}
export const providers = {
alchemyProvider,
infuraProvider,
jsonRpcProvider,
publicProvider,
walletConnectProvider
}
// -- chains ---------------------------------------------------------- //
export const chains = {
...chain,
avalanche,
fantom,
binanceSmartChain,
avalancheFuji,
fantomTestnet,
binanceSmartChainTestnet
}
// -- connectors ------------------------------------------------------ //
export function defaultConnectors({ appName, chains: connectorChains }: GetDefaultConnectorsOpts) {
return [
new WalletConnectConnector({ chains: connectorChains, options: { qrcode: false } }),
new InjectedConnector({ chains: connectorChains, options: { shimDisconnect: true } }),
new CoinbaseWalletConnector({
chains: connectorChains,
options: { appName, headlessMode: true }
}),
new MetaMaskConnector({
chains: connectorChains,
options: {
shimDisconnect: true,
shimChainChangedDisconnect: false,
UNSTABLE_shimOnConnectSelectAccount: true
}
})
]
}