Skip to content

Commit

Permalink
Switch account action
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonmanRolls committed Dec 5, 2024
1 parent c4ec941 commit 1535ceb
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { queryOptions } from '@tanstack/react-query'
import { switchChain } from '@wagmi/core'
import { Dispatch, useCallback, useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import styled, { css } from 'styled-components'
import { match, P } from 'ts-pattern'
import { BaseError } from 'viem'
import { useClient, useConnectorClient, useSendTransaction } from 'wagmi'
import { useAccount, useClient, useConnectorClient, useSendTransaction } from 'wagmi'

import {
Button,
Expand Down Expand Up @@ -36,6 +37,7 @@ import { ConfigWithEns, TransactionDisplayItem } from '@app/types'
import { getReadableError } from '@app/utils/errors'
import { getIsCachedData } from '@app/utils/getIsCachedData'
import { useQuery } from '@app/utils/query/useQuery'
import { wagmiConfig } from '@app/utils/query/wagmi'
import { makeEtherscanLink } from '@app/utils/utils'

import { DisplayItems } from '../DisplayItems'
Expand Down Expand Up @@ -323,7 +325,7 @@ export const TransactionStageModal = ({
const { data: isSafeApp, isLoading: safeAppStatusLoading } = useIsSafeApp()
const { data: connectorClient } = useConnectorClient<ConfigWithEns>()
const client = useClient()

const { data: account } = useAccount()
const addRecentTransaction = useAddRecentTransaction()

const stage = transaction.stage || 'confirm'
Expand Down Expand Up @@ -548,7 +550,10 @@ export const TransactionStageModal = ({
!!requestError ||
isTransactionRequestCachedData
}
onClick={() => {
onClick={async () => {
if (account?.chain?.id !== request?.chainId) {
await switchChain(wagmiConfig, { chainId: request?.chainId })
}
sendTransaction(request!)

const eventName = match(actionName)
Expand Down

0 comments on commit 1535ceb

Please sign in to comment.