11import dayjs from 'dayjs'
2+ import { getChainIdFromProvider } from '@/token-bridge-sdk/utils'
23
34import { step , UiDriverStepGenerator , UiDriverContext } from './UiDriver'
45import {
@@ -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