Skip to content

Commit

Permalink
fix: select correct wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu committed Aug 1, 2023
1 parent 0df6caf commit 54f7ee4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/components/common/ConnectWallet/AccountCenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const AccountCenter = ({ wallet }: { wallet: ConnectedWallet }) => {
const addressBook = useAddressBook()
const prefix = chainInfo?.shortName

const handleSwitchWallet = () => {
const handleSwitchWallet = async () => {
await privy.logout()
privy.login()
handleClose()
}

Expand Down
14 changes: 6 additions & 8 deletions src/hooks/wallets/useWallet.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { useWallets, type ConnectedWallet, type EIP1193Provider, usePrivy } from '@privy-io/react-auth'
import { useWallets, usePrivy, type ConnectedWallet, type EIP1193Provider } from '@privy-io/react-auth'
import { useMemo } from 'react'
import useAsync, { type AsyncResult } from '../useAsync'

const useWallet = (): AsyncResult<(ConnectedWallet & { provider: EIP1193Provider }) | null> => {
const { wallets } = useWallets()
const privy = usePrivy()

console.log('useWallet', wallets, privy)

const embeddedWallet = useMemo(() => wallets.find((wallet) => wallet.linked), [wallets])
const embeddedWallet = useMemo(
() => wallets.find((wallet) => wallet.address === privy.user?.wallet?.address),
[wallets, privy.user?.wallet?.address],
)

return useAsync(async () => {
const provider = await embeddedWallet?.getEthereumProvider()
Expand All @@ -17,11 +18,8 @@ const useWallet = (): AsyncResult<(ConnectedWallet & { provider: EIP1193Provider
return null
}

const chainId = await provider.request({ method: 'eth_chainId' })
console.log('eth_chainId', chainId)

return embeddedWallet
? { ...embeddedWallet, provider, chainId: chainId ?? embeddedWallet.chainId.replace('eip155:', '') }
? { ...embeddedWallet, provider, chainId: embeddedWallet.chainId.replace('eip155:', '') }
: null
}, [embeddedWallet])
}
Expand Down

0 comments on commit 54f7ee4

Please sign in to comment.