Skip to content

Commit

Permalink
Merge pull request #11086 from hassnian/issue-11024-1
Browse files Browse the repository at this point in the history
fix: Evm wallet chain not reacting to prefix change
  • Loading branch information
vikiival authored Oct 7, 2024
2 parents f58cda2 + 6f3ed25 commit cf89e8f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions composables/transaction/evm/useMetaTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Address, TransactionExecutionError } from 'viem'
import { simulateContract, waitForTransactionReceipt, writeContract } from '@wagmi/core'
import { useConfig } from '@wagmi/vue'
import { useChainId, useConfig, useSwitchChain } from '@wagmi/vue'
import type { Abi } from '../types'
import useTransactionStatus from '@/composables/useTransactionStatus'

Expand Down Expand Up @@ -33,13 +33,15 @@ export type EvmHowAboutToExecuteOnSuccessParam = {
*/
export default function useEvmMetaTransaction() {
const { $i18n } = useNuxtApp()
const { isLoading, initTransactionLoader, status, stopLoader }
= useTransactionStatus()
const { isLoading, initTransactionLoader, status, stopLoader } = useTransactionStatus()
const { switchChainAsync: switchChain } = useSwitchChain()
const { urlPrefix: prefix } = usePrefix()
const chainId = useChainId()
const wagmiConfig = useConfig()

const tx = ref<ExecResult>()
const isError = ref(false)

const wagmiConfig = useConfig()

const howAboutToExecute: EvmHowAboutToExecute = async ({
account,
functionName,
Expand All @@ -51,6 +53,8 @@ export default function useEvmMetaTransaction() {
onError,
}: EvmHowAboutToExecuteParam): Promise<void> => {
try {
await syncWalletChain()

const { request } = await simulateContract(wagmiConfig, {
account,
address,
Expand Down Expand Up @@ -79,6 +83,13 @@ export default function useEvmMetaTransaction() {
}
}

const syncWalletChain = async () => {
const chain = PREFIX_TO_CHAIN[prefix.value]
if (chain && chainId.value !== chain.id) {
await switchChain({ chainId: chain.id })
}
}

const successCb
= (onSuccess?: (param: EvmHowAboutToExecuteOnSuccessParam) => void) =>
async ({ txHash, blockNumber }) => {
Expand Down

0 comments on commit cf89e8f

Please sign in to comment.