generated from shuding/nextra-docs-template
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathEvmWalletConnect.tsx
86 lines (76 loc) · 2.84 KB
/
EvmWalletConnect.tsx
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
'use client';
import React from 'react';
import { DynamicContextProvider, useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { Box, Button } from '@radix-ui/themes';
import { IconLogout } from '@tabler/icons-react';
import useSeiAddress from '../../hooks/useSeiAddress';
import { getCosmosChainId } from '../../utils/chains';
import { CopyText } from '../CopyText';
import { SwitchNetwork } from '../SwitchNetwork';
import { EthereumWalletConnectors } from '@dynamic-labs/ethereum';
import { createConfig, http, WagmiProvider } from 'wagmi';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { DynamicWagmiConnector } from '@dynamic-labs/wagmi-connector';
import { sei, seiDevnet, seiTestnet } from 'viem/chains';
const wagmiConfig = createConfig({
chains: [sei, seiTestnet, seiDevnet],
multiInjectedProviderDiscovery: false,
transports: {
[sei.id]: http(),
[seiTestnet.id]: http(),
[seiDevnet.id]: http()
}
});
const queryClient = new QueryClient();
export default function EvmWalletConnect() {
return (
<DynamicContextProvider
settings={{
environmentId: '8974dcb9-89c7-4472-a988-e55c217a1020',
walletConnectors: [EthereumWalletConnectors]
}}>
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<DynamicWagmiConnector>
<WalletComponent />
</DynamicWagmiConnector>
</QueryClientProvider>
</WagmiProvider>
</DynamicContextProvider>
);
}
const WalletComponent = () => {
const { handleLogOut, network, primaryWallet, setShowAuthFlow } = useDynamicContext();
const response = useSeiAddress({ chainId: getCosmosChainId(Number(network)) });
const { data: seiAddress, isLoading } = response;
const renderContent = () => {
if (network) {
return (
<Button className='flex flex-row gap-4 !bg-neutral-700 !p-6 !rounded-2xl cursor-pointer hover:!bg-[#9e1f19aa]' onClick={handleLogOut}>
<IconLogout />
<p className='font-bold'>Disconnect Wallet</p>
</Button>
);
}
return (
<div className='flex flex-col gap-4 mt-8'>
<Button onClick={() => setShowAuthFlow(true)} className='flex flex-row gap-4 !bg-[#9e1f19] !p-6 !rounded-2xl cursor-pointer hover:!bg-[#9e1f19aa]'>
<p className='font-bold'>Connect & Link Wallet</p>
</Button>
</div>
);
};
if (!network) {
return <Box className='w-full'>{renderContent()}</Box>;
}
return (
<div className='flex flex-col gap-4 mt-4'>
<SwitchNetwork />
<div className='flex flex-col gap-2'>
<CopyText column={true} label='EVM Address:' value={primaryWallet?.address ? primaryWallet?.address : '---'} copyDisabled={!primaryWallet?.address} />
<CopyText column={true} label='Cosmos Address:' value={seiAddress && !isLoading ? seiAddress : '---'} copyDisabled={!seiAddress || isLoading} />
<Box className='w-full mt-4'>{renderContent()}</Box>
</div>
</div>
);
};