-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet-connect.js
65 lines (49 loc) · 1.8 KB
/
wallet-connect.js
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
// https://docs.walletconnect.com/web3modal/upgrade
import React, {useEffect,useState} from 'react';
import { createWeb3Modal } from '@web3modal/wagmi/react'
import { defaultWagmiConfig } from '@web3modal/wagmi/react/config'
import { WagmiConfig, WagmiProvider } from 'wagmi'
import { bsc, blast, arbitrum, mainnet } from 'viem/chains'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { useWeb3Modal } from '@web3modal/wagmi/react'
import { useAccount } from 'wagmi'
import bitgetConfig from './bitget-wallet-config.json';
const chains = [arbitrum, mainnet, bsc, blast];
const projectId = '300bd040f44518f10a001e8f020ffa05'
const queryClient = new QueryClient()
const metadata = {
name: 'Web3Modal',
description: 'Web3Modal Example',
url: 'https://web3modal.com',
icons: ['https://avatars.githubusercontent.com/u/37784886']
}
const wagmiConfig = defaultWagmiConfig({ chains, projectId, metadata })
//is not install,show icon for install guide.
let customWallets = [];
if(!window.bitkeep){
customWallets.push(bitgetConfig);
}
createWeb3Modal({
wagmiConfig,
projectId,
chains,
defaultChain: bsc,
enableAnalytics: true,
customWallets: customWallets
})
export default function WalletConnectDemo() {
const { open, selectedNetworkId } = useWeb3Modal();
// const { address, isConnecting, isDisconnected } = useAccount()
console.log(selectedNetworkId, chains)
useEffect(()=>{
open();
}, []);
return (<>
<div style={{ padding: '20px 0' }}>官网demo <a href="https://web3modal.com/">https://web3modal.com/</a></div>
<WagmiConfig config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<button style={{ fontSize: '20px' }} onClick={() => open()}>Wallet Connect Demo</button>
</QueryClientProvider>
</WagmiConfig>
</>);
}