feat: connecting app with wallet with button
This commit is contained in:
parent
6510ede5ba
commit
b693043701
|
@ -1,13 +1,30 @@
|
||||||
import { Avatar, Button } from '@status-im/components'
|
import { Avatar, Button } from '@status-im/components'
|
||||||
|
import { useConnectWallet } from '@web3-onboard/react'
|
||||||
import { XStack } from 'tamagui'
|
import { XStack } from 'tamagui'
|
||||||
|
import { ethers } from 'ethers'
|
||||||
|
|
||||||
const ConnectWallet = () => {
|
const ConnectWallet = () => {
|
||||||
const onConnectWalletClick = () => {}
|
const [{ wallet, connecting }, connect, disconnect] = useConnectWallet()
|
||||||
|
|
||||||
|
const onConnectWalletClick = () => {
|
||||||
|
if (wallet) {
|
||||||
|
disconnect(wallet)
|
||||||
|
} else {
|
||||||
|
connect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let ethersProvider
|
||||||
|
if (wallet) {
|
||||||
|
ethersProvider = new ethers.BrowserProvider(wallet.provider, 'any')
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<XStack space={'$2'} alignItems={'center'}>
|
<XStack space={'$2'} alignItems={'center'}>
|
||||||
<Avatar type="icon" size={32} icon={<img src={'/icons/eth-logo.svg'} alt="eth-logo" />} />
|
<Avatar type="icon" size={32} icon={<img src={'/icons/eth-logo.svg'} alt="eth-logo" />} />
|
||||||
<Button onPress={onConnectWalletClick}>Connect Wallet</Button>
|
<Button disabled={connecting} onPress={onConnectWalletClick}>
|
||||||
|
{connecting ? 'Connecting' : wallet ? 'Disconnect Wallet' : 'Connect Wallet'}
|
||||||
|
</Button>
|
||||||
</XStack>
|
</XStack>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue