Skip to content

Commit

Permalink
feat: handle wallet instalation
Browse files Browse the repository at this point in the history
  • Loading branch information
pociej committed Feb 14, 2024
1 parent 70d1133 commit 6a7b185
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { useOnboarding } from 'hooks/useOnboarding'
import { Commands } from 'state/commands'
import { motion } from 'framer-motion'
import { useHasFocus } from 'hooks/useHasFocus'

import { InjectedConnector } from '@wagmi/connectors/injected'
import { connect } from '@wagmi/core'
import { polygon, mainnet } from 'viem/chains'
TooltipProvider.registerTooltip({
id: 'connect-wallet',
tooltip: {
Expand Down Expand Up @@ -98,6 +100,19 @@ export const ConnectWallet = () => {
const { send } = useOnboarding()
const hasFocus = useHasFocus()
const [shouldReload, setShouldReload] = useState(false)
const [shouldConnect, setShouldConnect] = useState(false)

useEffect(() => {
if (shouldConnect) {
connect({
chainId: polygon.id,
connector: new InjectedConnector({
chains: [polygon, mainnet],
}),
})
setShouldConnect(false)
}
}, [shouldConnect])
useEffect(() => {
if (address) {
send({ type: Commands.NEXT })
Expand All @@ -113,6 +128,7 @@ export const ConnectWallet = () => {
useEffect(() => {
if (hasFocus && shouldReload) {
setShouldReload(false)
setShouldConnect(true)
window.location.reload()
}
}, [hasFocus])
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/hooks/useNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useNetwork as useNetworkWagmi } from 'wagmi'
import { toHex } from 'viem'
import { Chain } from 'types/wagmi'
import { Chain as ChainWagmi } from 'wagmi'
import { assertSupportedChainId } from 'types/ethereum'

type GetNetworkResult = ReturnType<typeof useNetworkWagmi>

Expand Down Expand Up @@ -37,7 +36,6 @@ export const useNetwork = (): Omit<GetNetworkResult, 'chain' | 'chains'> & {
const network = useNetworkWagmi()
let chain = undefined
if (network.chain) {
console.log('network.chain', network.chain)
chain = formatChain(network.chain)
}

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/hooks/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export const useWallet = (): WalletProviderType => {
//for now we support only metamask or trust wallet
// so we rely on window.ethereum.isMetaMask

const isMetaMask = window.ethereum.isMetaMask
const isMetaMask = window?.ethereum?.isMetaMask
if (isMetaMask) {
return WalletProvider.METAMASK
}

return WalletProvider.TRUST_WALLET
}

0 comments on commit 6a7b185

Please sign in to comment.