Skip to content

Commit 85f5b56

Browse files
committed
wip
1 parent 1415bbd commit 85f5b56

File tree

3 files changed

+118
-93
lines changed

3 files changed

+118
-93
lines changed

packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanel.tsx

Lines changed: 19 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,13 @@ export function TransferPanel() {
459459
return { error: error as unknown as Error }
460460
}
461461
}
462+
463+
case 'tx_history_add': {
464+
addPendingTransaction(step.payload)
465+
switchToTransactionHistoryTab()
466+
467+
return
468+
}
462469
}
463470
}
464471

@@ -479,22 +486,31 @@ export function TransferPanel() {
479486
const destinationAddress = latestDestinationAddress.current
480487

481488
try {
482-
const { sourceChainProvider, destinationChainProvider, sourceChain } =
483-
latestNetworks.current
489+
const {
490+
sourceChainProvider,
491+
destinationChainProvider,
492+
sourceChain,
493+
destinationChain
494+
} = latestNetworks.current
484495

485496
const cctpTransferStarter = new CctpTransferStarter({
486497
sourceChainProvider,
487498
destinationChainProvider
488499
})
489500

490501
const returnEarly = await drive(stepGeneratorForCctp, stepExecutor, {
502+
amount,
491503
amountBigNumber,
492504
isDepositMode,
493505
isSmartContractWallet,
494506
walletAddress,
495507
destinationAddress,
496508
transferStarter: cctpTransferStarter,
497-
wagmiConfig
509+
wagmiConfig,
510+
sourceChain,
511+
destinationChain,
512+
childChain,
513+
parentChain
498514
})
499515

500516
// this is only necessary while we are migrating to the ui driver
@@ -505,94 +521,6 @@ export function TransferPanel() {
505521
return
506522
}
507523

508-
let depositForBurnTx
509-
510-
try {
511-
if (isSmartContractWallet) {
512-
showDelayedSmartContractTxRequest()
513-
}
514-
const transfer = await cctpTransferStarter.transfer({
515-
amount: amountBigNumber,
516-
signer,
517-
destinationAddress,
518-
wagmiConfig
519-
})
520-
depositForBurnTx = transfer.sourceChainTransaction
521-
} catch (error) {
522-
if (isUserRejectedError(error)) {
523-
return
524-
}
525-
handleError({
526-
error,
527-
label: 'cctp_transfer',
528-
category: 'transaction_signing'
529-
})
530-
errorToast(
531-
`USDC ${
532-
isDepositMode ? 'Deposit' : 'Withdrawal'
533-
} transaction failed: ${(error as Error)?.message ?? error}`
534-
)
535-
}
536-
537-
const childChainName = getNetworkName(childChain.id)
538-
539-
if (isSmartContractWallet) {
540-
// For SCW, we assume that the transaction went through
541-
trackEvent(isDepositMode ? 'CCTP Deposit' : 'CCTP Withdrawal', {
542-
accountType: 'Smart Contract',
543-
network: childChainName,
544-
amount: Number(amount),
545-
complete: false,
546-
version: 2
547-
})
548-
549-
return
550-
}
551-
552-
if (!depositForBurnTx) {
553-
return
554-
}
555-
556-
trackEvent(isDepositMode ? 'CCTP Deposit' : 'CCTP Withdrawal', {
557-
accountType: 'EOA',
558-
network: childChainName,
559-
amount: Number(amount),
560-
complete: false,
561-
version: 2
562-
})
563-
564-
const newTransfer: MergedTransaction = {
565-
txId: depositForBurnTx.hash,
566-
asset: 'USDC',
567-
assetType: AssetType.ERC20,
568-
blockNum: null,
569-
createdAt: dayjs().valueOf(),
570-
direction: isDepositMode ? 'deposit' : 'withdraw',
571-
isWithdrawal: !isDepositMode,
572-
resolvedAt: null,
573-
status: 'pending',
574-
uniqueId: null,
575-
value: amount,
576-
depositStatus: DepositStatus.CCTP_DEFAULT_STATE,
577-
destination: destinationAddress ?? walletAddress,
578-
sender: walletAddress,
579-
isCctp: true,
580-
tokenAddress: getUsdcTokenAddressFromSourceChainId(sourceChain.id),
581-
cctpData: {
582-
sourceChainId: sourceChain.id,
583-
attestationHash: null,
584-
messageBytes: null,
585-
receiveMessageTransactionHash: null,
586-
receiveMessageTimestamp: null
587-
},
588-
parentChainId: parentChain.id,
589-
childChainId: childChain.id,
590-
sourceChainId: networks.sourceChain.id,
591-
destinationChainId: networks.destinationChain.id
592-
}
593-
594-
addPendingTransaction(newTransfer)
595-
switchToTransactionHistoryTab()
596524
setTransferring(false)
597525
clearAmountInput()
598526
clearRoute()

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { BigNumber, providers } from 'ethers'
22
import { BridgeTransferStarter } from '@/token-bridge-sdk/BridgeTransferStarter'
33
import { Config, SimulateContractReturnType } from '@wagmi/core'
4+
import { Chain } from 'wagmi/chains'
45

56
import { DialogType } from '../components/common/Dialog2'
7+
import { trackEvent } from '../util/AnalyticsUtils'
8+
import { MergedTransaction } from '../state/app/state'
69

710
export type Dialog = Extract<
811
DialogType,
@@ -13,13 +16,18 @@ export type Dialog = Extract<
1316
>
1417

1518
export type UiDriverContext = {
19+
amount: string
1620
amountBigNumber: BigNumber
1721
isDepositMode: boolean
1822
isSmartContractWallet: boolean
1923
walletAddress: string
2024
destinationAddress?: string
2125
transferStarter: BridgeTransferStarter
2226
wagmiConfig: Config
27+
sourceChain: Chain
28+
destinationChain: Chain
29+
childChain: Chain
30+
parentChain: Chain
2331
}
2432

2533
export type UiDriverStep =
@@ -41,6 +49,17 @@ export type UiDriverStep =
4149
txRequestLabel: string
4250
}
4351
}
52+
| {
53+
type: 'analytics'
54+
payload: {
55+
event: Parameters<typeof trackEvent>[0]
56+
properties?: Parameters<typeof trackEvent>[1]
57+
}
58+
}
59+
| {
60+
type: 'tx_history_add'
61+
payload: MergedTransaction
62+
}
4463

4564
export type UiDriverStepType = UiDriverStep['type']
4665

@@ -66,6 +85,10 @@ export type UiDriverStepResultFor<TStepType extends UiDriverStepType> =
6685
? void
6786
: TStepType extends 'tx_ethers' | 'tx_wagmi'
6887
? Result<providers.TransactionReceipt>
88+
: TStepType extends 'analytics'
89+
? void
90+
: TStepType extends 'tx_history_add'
91+
? void
6992
: never
7093

7194
export type UiDriverStepGenerator<TStep extends UiDriverStep = UiDriverStep> = (

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

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { step, UiDriverStepGenerator } from './UiDriver'
1+
import dayjs from 'dayjs'
2+
3+
import { step, UiDriverStepGenerator, UiDriverContext } from './UiDriver'
24
import {
35
stepGeneratorForDialog,
46
stepGeneratorForSmartContractWalletDestinationDialog,
57
stepGeneratorForTransactionEthers,
68
stepGeneratorForTransactionWagmi
79
} from './UiDriverCommon'
810

11+
import { getNetworkName } from '../util/networks'
12+
import { DepositStatus, MergedTransaction } from '../state/app/state'
13+
import { AssetType } from '../hooks/arbTokenBridge.types'
14+
import { getUsdcTokenAddressFromSourceChainId } from '../state/cctpState'
15+
916
export const stepGeneratorForCctp: UiDriverStepGenerator = async function* (
1017
context
1118
) {
@@ -41,9 +48,76 @@ export const stepGeneratorForCctp: UiDriverStepGenerator = async function* (
4148
wagmiConfig: context.wagmiConfig
4249
})
4350

44-
yield* stepGeneratorForTransactionWagmi(context, {
51+
const receipt = yield* stepGeneratorForTransactionWagmi(context, {
4552
// @ts-expect-error - TODO: fix this
4653
txRequest: request,
4754
txRequestLabel: 'stepGeneratorForCctp.transfer'
4855
})
56+
57+
if (typeof receipt === 'undefined') {
58+
return
59+
}
60+
61+
yield {
62+
type: 'analytics',
63+
payload: {
64+
event: context.isDepositMode ? 'CCTP Deposit' : 'CCTP Withdrawal',
65+
properties: {
66+
accountType: context.isSmartContractWallet ? 'Smart Contract' : 'EOA',
67+
network: getNetworkName(context.childChain.id),
68+
amount: Number(context.amount),
69+
complete: false,
70+
version: 2
71+
}
72+
}
73+
}
74+
75+
yield {
76+
type: 'tx_history_add',
77+
payload: createMergedTransaction(context, receipt.transactionHash)
78+
}
79+
}
80+
81+
function createMergedTransaction(
82+
{
83+
isDepositMode,
84+
walletAddress,
85+
destinationAddress,
86+
sourceChain,
87+
destinationChain,
88+
amount,
89+
parentChain,
90+
childChain
91+
}: UiDriverContext,
92+
depositForBurnTxHash: string
93+
): MergedTransaction {
94+
return {
95+
txId: depositForBurnTxHash,
96+
asset: 'USDC',
97+
assetType: AssetType.ERC20,
98+
blockNum: null,
99+
createdAt: dayjs().valueOf(),
100+
direction: isDepositMode ? 'deposit' : 'withdraw',
101+
isWithdrawal: !isDepositMode,
102+
resolvedAt: null,
103+
status: 'pending',
104+
uniqueId: null,
105+
value: amount,
106+
depositStatus: DepositStatus.CCTP_DEFAULT_STATE,
107+
destination: destinationAddress ?? walletAddress,
108+
sender: walletAddress,
109+
isCctp: true,
110+
tokenAddress: getUsdcTokenAddressFromSourceChainId(sourceChain.id),
111+
cctpData: {
112+
sourceChainId: sourceChain.id,
113+
attestationHash: null,
114+
messageBytes: null,
115+
receiveMessageTransactionHash: null,
116+
receiveMessageTimestamp: null
117+
},
118+
parentChainId: parentChain.id,
119+
childChainId: childChain.id,
120+
sourceChainId: sourceChain.id,
121+
destinationChainId: destinationChain.id
122+
}
49123
}

0 commit comments

Comments
 (0)