This commit is contained in:
yuyongdong 2024-06-27 20:03:54 +08:00
commit 9029b39ddb

View File

@ -2,6 +2,23 @@ import {Deferred} from '../utils/promise.util.js'
const MINT_CONTRACT_ADDRESS=import.meta.env.VITE_CLAIMWL_ADDRESS const MINT_CONTRACT_ADDRESS=import.meta.env.VITE_CLAIMWL_ADDRESS
const RPC=import.meta.env.VITE_RPC_API const RPC=import.meta.env.VITE_RPC_API
const chainCfgs = [{
name: 'Immutable zkEVM',
type: 'Mainnet',
rpc: 'https://rpc.immutable.com',
id: 13371,
symbol: 'IMX',
explorerurl: 'https://explorer.immutable.com'
},
{
name: 'Immutable zkEVM Testnet',
type: 'Testnet',
rpc: 'https://rpc.testnet.immutable.com',
id: 13473,
symbol: 'tIMX',
explorerurl: 'https://explorer.testnet.immutable.com'
}]
const requestChain = async (rpc, method, params) => { const requestChain = async (rpc, method, params) => {
const data = { const data = {
id: Date.now(), id: Date.now(),
@ -122,7 +139,8 @@ export const switchEthereumChain = async (provider, targetChainId) => {
console.log('error switch chain: ', e) console.log('error switch chain: ', e)
if (e.code === 4902 || e.message.indexOf('Unrecognized chain ID') >= 0) { if (e.code === 4902 || e.message.indexOf('Unrecognized chain ID') >= 0) {
try { try {
const data = chainCfg const chainIdNum = parseInt(hexChainId)
const data = chainCfgs.find(o => o.id === chainIdNum)
await provider.request({ await provider.request({
method: 'wallet_addEthereumChain', method: 'wallet_addEthereumChain',
params: [ params: [