File tree Expand file tree Collapse file tree 3 files changed +64
-1
lines changed
packages/arb-token-bridge-ui/src Expand file tree Collapse file tree 3 files changed +64
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import Tippy from '@tippyjs/react'
44import { constants , utils } from 'ethers'
55import { useLatest } from 'react-use'
66import { useAccount , useConfig } from 'wagmi'
7+ import { writeContract } from '@wagmi/core'
78import { TransactionResponse } from '@ethersproject/providers'
89import { twMerge } from 'tailwind-merge'
910import { scaleFrom18DecimalsToNativeTokenDecimals } from '@arbitrum/sdk'
@@ -430,6 +431,34 @@ export function TransferPanel() {
430431 return { error : error as unknown as Error }
431432 }
432433 }
434+
435+ case 'tx_wagmi' : {
436+ try {
437+ const txHash = await writeContract (
438+ wagmiConfig ,
439+ step . payload . txRequest
440+ )
441+ const txReceipt =
442+ await context . transferStarter . sourceChainProvider . waitForTransaction (
443+ txHash
444+ )
445+
446+ return { data : txReceipt }
447+ } catch ( error ) {
448+ // capture error and show toast for anything that's not user rejecting error
449+ if ( ! isUserRejectedError ( error ) ) {
450+ handleError ( {
451+ error,
452+ label : step . payload . txRequestLabel ,
453+ category : 'transaction_signing'
454+ } )
455+
456+ errorToast ( `${ ( error as Error ) ?. message ?? error } ` )
457+ }
458+
459+ return { error : error as unknown as Error }
460+ }
461+ }
433462 }
434463 }
435464
Original file line number Diff line number Diff line change 11import { BigNumber , providers } from 'ethers'
22import { BridgeTransferStarter } from '@/token-bridge-sdk/BridgeTransferStarter'
3+ import { SimulateContractReturnType } from '@wagmi/core'
34
45import { DialogType } from '../components/common/Dialog2'
56
@@ -32,6 +33,13 @@ export type UiDriverStep =
3233 txRequestLabel : string
3334 }
3435 }
36+ | {
37+ type : 'tx_wagmi'
38+ payload : {
39+ txRequest : SimulateContractReturnType [ 'request' ]
40+ txRequestLabel : string
41+ }
42+ }
3543
3644export type UiDriverStepType = UiDriverStep [ 'type' ]
3745
@@ -55,7 +63,7 @@ export type UiDriverStepResultFor<TStepType extends UiDriverStepType> =
5563 ? boolean
5664 : TStepType extends 'scw_tooltip'
5765 ? void
58- : TStepType extends 'tx_ethers'
66+ : TStepType extends 'tx_ethers' | 'tx_wagmi'
5967 ? Result < providers . TransactionReceipt >
6068 : never
6169
Original file line number Diff line number Diff line change @@ -61,3 +61,29 @@ export const stepGeneratorForTransactionEthers: UiDriverStepGeneratorForTransact
6161 return data
6262 }
6363 }
64+
65+ export type UiDriverStepGeneratorForTransactionWagmi <
66+ TStep extends UiDriverStep = UiDriverStep
67+ > = (
68+ context : UiDriverContext ,
69+ payload : UiDriverStepPayloadFor < 'tx_wagmi' >
70+ ) => AsyncGenerator <
71+ TStep ,
72+ providers . TransactionReceipt | void ,
73+ UiDriverStepResultFor < TStep [ 'type' ] >
74+ >
75+
76+ export const stepGeneratorForTransactionWagmi : UiDriverStepGeneratorForTransactionWagmi =
77+ async function * ( context , payload ) {
78+ if ( context . isSmartContractWallet ) {
79+ yield * step ( { type : 'scw_tooltip' } )
80+ }
81+
82+ const { error, data } = yield * step ( { type : 'tx_wagmi' , payload } )
83+
84+ if ( typeof error !== 'undefined' ) {
85+ yield * step ( { type : 'return' } )
86+ } else {
87+ return data
88+ }
89+ }
You can’t perform that action at this time.
0 commit comments