Skip to content

Commit c54bbee

Browse files
committed
reduce context
1 parent b55ee41 commit c54bbee

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

packages/arb-token-bridge-ui/src/ui-driver/UiDriver.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ export type UiDriverContext = {
2424
destinationAddress?: string
2525
transferStarter: BridgeTransferStarter
2626
wagmiConfig: Config
27-
sourceChain: Chain
28-
destinationChain: Chain
29-
childChain: Chain
30-
parentChain: Chain
3127
}
3228

3329
export type UiDriverStep =

packages/arb-token-bridge-ui/src/ui-driver/UiDriverCctp.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dayjs from 'dayjs'
2+
import { getChainIdFromProvider } from '@/token-bridge-sdk/utils'
23

34
import { step, UiDriverStepGenerator, UiDriverContext } from './UiDriver'
45
import {
@@ -74,23 +75,28 @@ export const stepGeneratorForCctp: UiDriverStepGenerator = async function* (
7475

7576
yield* step({
7677
type: 'tx_history_add',
77-
payload: createMergedTransaction(context, receipt.transactionHash)
78+
payload: await createMergedTransaction(context, receipt.transactionHash)
7879
})
7980
}
8081

81-
function createMergedTransaction(
82+
async function createMergedTransaction(
8283
{
8384
isDepositMode,
8485
walletAddress,
8586
destinationAddress,
86-
sourceChain,
87-
destinationChain,
8887
amount,
89-
parentChain,
90-
childChain
88+
transferStarter
9189
}: UiDriverContext,
9290
depositForBurnTxHash: string
93-
): MergedTransaction {
91+
): Promise<MergedTransaction> {
92+
const [sourceChainId, destinationChainId] = await Promise.all([
93+
getChainIdFromProvider(transferStarter.sourceChainProvider),
94+
getChainIdFromProvider(transferStarter.destinationChainProvider)
95+
])
96+
97+
const childChainId = isDepositMode ? destinationChainId : sourceChainId
98+
const parentChainId = isDepositMode ? sourceChainId : destinationChainId
99+
94100
return {
95101
txId: depositForBurnTxHash,
96102
asset: 'USDC',
@@ -107,17 +113,17 @@ function createMergedTransaction(
107113
destination: destinationAddress ?? walletAddress,
108114
sender: walletAddress,
109115
isCctp: true,
110-
tokenAddress: getUsdcTokenAddressFromSourceChainId(sourceChain.id),
116+
tokenAddress: getUsdcTokenAddressFromSourceChainId(sourceChainId),
111117
cctpData: {
112-
sourceChainId: sourceChain.id,
118+
sourceChainId,
113119
attestationHash: null,
114120
messageBytes: null,
115121
receiveMessageTransactionHash: null,
116122
receiveMessageTimestamp: null
117123
},
118-
parentChainId: parentChain.id,
119-
childChainId: childChain.id,
120-
sourceChainId: sourceChain.id,
121-
destinationChainId: destinationChain.id
124+
parentChainId,
125+
childChainId,
126+
sourceChainId,
127+
destinationChainId
122128
}
123129
}

0 commit comments

Comments
 (0)