-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectWalletButton.tsx
62 lines (56 loc) · 1.82 KB
/
ConnectWalletButton.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
import { useTranslation } from '@pancakeswap/localization'
import { WalletModalV2 } from '@pancakeswap/ui-wallets'
import { Button, ButtonProps } from '@pancakeswap/uikit'
import { createWallets, getDocLink } from 'config/wallet'
import { useActiveChainId } from 'hooks/useActiveChainId'
import useAuth from 'hooks/useAuth'
// @ts-ignore
// eslint-disable-next-line import/extensions
import { useActiveHandle } from 'hooks/useEagerConnect.bmp.ts'
import { useMemo, useState } from 'react'
import { useConnect } from 'wagmi'
import { logGTMWalletConnectEvent } from 'utils/customGTMEventTracking'
import Trans from './Trans'
const ConnectWalletButton = ({ children, ...props }: ButtonProps) => {
const handleActive = useActiveHandle()
const { login } = useAuth()
const {
t,
currentLanguage: { code },
} = useTranslation()
const { connectAsync } = useConnect()
const { chainId } = useActiveChainId()
const [open, setOpen] = useState(false)
const docLink = useMemo(() => getDocLink(code), [code])
const handleClick = () => {
if (typeof __NEZHA_BRIDGE__ !== 'undefined' && !window.ethereum) {
handleActive()
} else {
setOpen(true)
}
}
const wallets = useMemo(() => createWallets(chainId, connectAsync), [chainId, connectAsync])
return (
<>
<Button onClick={handleClick} {...props}>
{children || <Trans>Connect Wallet</Trans>}
</Button>
<style jsx global>{`
w3m-modal {
position: relative;
z-index: 99;
}
`}</style>
<WalletModalV2
docText={t('Learn How to Connect')}
docLink={docLink}
isOpen={open}
wallets={wallets}
login={login}
onDismiss={() => setOpen(false)}
onWalletConnectCallBack={logGTMWalletConnectEvent}
/>
</>
)
}
export default ConnectWalletButton