-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathethereum-wallet.ts
107 lines (96 loc) · 2.5 KB
/
ethereum-wallet.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* ETHEREUM WALLET
*
* This prepares an EVM NEAR wallet option to be made available to the near-wallet
* It is NOT configured to login to an specific contract.
*
* Make sure to configure your REOWN_PROJECT_ID
*/
import { NETWORK_ID } from "@/config";
import { injected, walletConnect } from "@wagmi/connectors";
import {
// Config as WagmiConfig,
createConfig,
http,
reconnect
} from "@wagmi/core";
import { createWeb3Modal } from "@web3modal/wagmi";
// MODIFY WITH YOUR OWN PROJECT_ID HERE : https://cloud.reown.com/sign-in
export const REOWN_PROJECT_ID = "8d5dd3e6eda55e2e0adffb629fd52c27";
// Chains for EVM Wallets
export const evmWalletChains = {
mainnet: {
chainId: 397,
name: "Near Mainnet",
explorer: "https://eth-explorer.near.org",
rpc: "https://eth-rpc.mainnet.near.org"
},
testnet: {
chainId: 398,
name: "Near Testnet",
explorer: "https://eth-explorer-testnet.near.org",
rpc: "https://near-wallet-relayer.testnet.aurora.dev"
},
localnet: {
chainId: 398,
name: "Near Testnet",
explorer: "https://eth-explorer-testnet.near.org",
rpc: "https://eth-rpc.testnet.near.org"
}
};
export const EVMWalletChain = evmWalletChains[NETWORK_ID];
export const NEARProtocol = {
id: EVMWalletChain.chainId,
name: EVMWalletChain.name,
nativeCurrency: {
decimals: 18,
name: "NEAR",
symbol: "NEAR"
},
rpcUrls: {
default: { http: [EVMWalletChain.rpc] },
public: { http: [EVMWalletChain.rpc] }
},
blockExplorers: {
default: {
name: "NEAR Explorer",
url: EVMWalletChain.explorer
}
},
testnet: NETWORK_ID === "testnet"
};
export const wagmiConfig = createConfig({
chains: [NEARProtocol],
transports: {
[NEARProtocol.id]: http()
},
connectors: [
walletConnect({
projectId: REOWN_PROJECT_ID,
showQrModal: false
}),
injected({ shimDisconnect: true })
]
});
reconnect(wagmiConfig);
export const web3Modal = createWeb3Modal({
wagmiConfig,
projectId: REOWN_PROJECT_ID
});
export const transformedWeb3Modal = {
...web3Modal,
getState: () => {
const state = web3Modal.getState();
const selectedNetworkIdString = state.selectedNetworkId;
const selectedNetworkId = selectedNetworkIdString
? parseInt(selectedNetworkIdString.split(":")[1], 10)
: undefined;
return {
...state,
selectedNetworkId
};
},
open: web3Modal.open.bind(web3Modal),
close: web3Modal.close.bind(web3Modal),
subscribeEvents: web3Modal.subscribeEvents.bind(web3Modal)
};