Skip to content

Commit

Permalink
Merge pull request #10562 from hassnian/issue-10559
Browse files Browse the repository at this point in the history
fix: Got into infinite loop with EVM
  • Loading branch information
Jarsen136 committed Jul 3, 2024
2 parents 068acc5 + 6e98e60 commit 01f8bf9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 3 additions & 2 deletions components/common/ConnectWallet/ConnectEvm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const { urlPrefix, setUrlPrefix } = usePrefix()
const { modal } = useWeb3Modal()
watch([address, isConnected, chainId], ([address, isConnected, chainId]) => {
if (address && isConnected && chainId) {
const chainPrefix = CHAIN_ID_TO_PREFIX[chainId]
const chainPrefix = CHAIN_ID_TO_PREFIX?.[chainId ?? '']
if (address && isConnected && chainId && chainPrefix) {
const isCorrectChainConnected = chainPrefix === urlPrefix.value
if (!isCorrectChainConnected) {
Expand Down
19 changes: 15 additions & 4 deletions composables/useWagmi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defaultWagmiConfig } from '@web3modal/wagmi/vue'
import { base, immutableZkEvm } from 'viem/chains'
import { reconnect } from '@wagmi/core'
import { reconnect as reconnectWagmi } from '@wagmi/core'
import { useAccount, useDisconnect } from 'use-wagmi'
import { DisconnectMutateAsync } from 'use-wagmi/query'

Expand All @@ -23,8 +23,12 @@ const buildWagmiConfig = () => {

const config = buildWagmiConfig() as any

export default () => {
reconnect(config)
export default (
{ reconnect }: { reconnect: boolean } = { reconnect: false },
) => {
if (reconnect) {
reconnectWagmi(config)
}

const { isConnected, address, isConnecting, chainId } = useAccount({
config,
Expand All @@ -34,5 +38,12 @@ export default () => {
() => useDisconnect({ config }).disconnectAsync,
) as Promise<DisconnectMutateAsync>

return { config, isConnected, isConnecting, address, disconnect, chainId }
return {
config,
isConnected,
isConnecting,
address,
disconnect,
chainId,
}
}
2 changes: 2 additions & 0 deletions composables/useWeb3Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const modal = ref()

export default () => {
const { config } = useWagmi()
const { urlPrefix } = usePrefix()

createWeb3Modal({
wagmiConfig: config,
projectId: useRuntimeConfig().public.walletConnectProjectId,
defaultChain: PREFIX_TO_CHAIN[urlPrefix.value],
})

if (!modal.value) {
Expand Down
7 changes: 7 additions & 0 deletions utils/wagmi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Prefix } from '@kodadot1/static'
import { base, immutableZkEvm } from 'viem/chains'
import { type Chain } from 'viem'

export const CHAIN_ID_TO_PREFIX: Record<number, Prefix> = {
8453: 'base',
13371: 'imx',
}

export const PREFIX_TO_CHAIN: Partial<Record<Prefix, Chain>> = {
base: base,
imx: immutableZkEvm,
}

0 comments on commit 01f8bf9

Please sign in to comment.