From f3df02ab403a6f29d51615b77d8ce684cc4a420b Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Sat, 11 Mar 2023 23:03:15 +0530 Subject: [PATCH 1/5] fix(bridge-ui): remove unnecessary tx store update --- packages/bridge-ui/src/App.svelte | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/bridge-ui/src/App.svelte b/packages/bridge-ui/src/App.svelte index b407342520f..063d10f7ef1 100644 --- a/packages/bridge-ui/src/App.svelte +++ b/packages/bridge-ui/src/App.svelte @@ -174,19 +174,13 @@ }); pendingTransactions.subscribe((store) => { - store.forEach(async (tx) => { + store.forEach(async (tx, index) => { await $signer.provider.waitForTransaction(tx.hash, 1); successToast('Transaction completed!'); - // TODO: Fix, .pop() removes the last tx but the confirmed tx is not necessarily the last one in the pendingTransactions array. const s = store; - s.pop(); + s.slice(index, 0); pendingTransactions.set(s); - - // TODO: Do we need this? - transactions.set( - await $transactioner.GetAllByAddress(await $signer.getAddress()), - ); }); }); From 9659175a8cb6b18807c407301fe4b3dfb0556854 Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Sat, 11 Mar 2023 23:48:42 +0530 Subject: [PATCH 2/5] fix(bridge-ui): ts errors for env vars --- packages/bridge-ui/src/vite-env.d.ts | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/bridge-ui/src/vite-env.d.ts b/packages/bridge-ui/src/vite-env.d.ts index 4078e7476a2..7eed77ca647 100644 --- a/packages/bridge-ui/src/vite-env.d.ts +++ b/packages/bridge-ui/src/vite-env.d.ts @@ -1,2 +1,32 @@ /// /// +/// + +interface ImportMetaEnv { + readonly VITE_L1_RPC_URL: string; + readonly VITE_L1_RPC_URL: string; + readonly VITE_L2_RPC_URL: string; + readonly VITE_L1_EXPLORER_URL: string; + readonly VITE_L2_EXPLORER_URL: string; + readonly VITE_RELAYER_URL: string; + readonly VITE_TEST_ERC20_ADDRESS_MAINNET: string; + readonly VITE_TEST_ERC20_SYMBOL_MAINNET: string; + readonly VITE_TEST_ERC20_NAME_MAINNET: string; + readonly VITE_MAINNET_CHAIN_ID: string; + readonly VITE_TAIKO_CHAIN_ID: string; + readonly VITE_MAINNET_CHAIN_NAME: string; + readonly VITE_TAIKO_CHAIN_NAME: string; + readonly VITE_MAINNET_TOKEN_VAULT_ADDRESS: string; + readonly VITE_TAIKO_TOKEN_VAULT_ADDRESS: string; + readonly VITE_MAINNET_HEADER_SYNC_ADDRESS: string; + readonly VITE_TAIKO_HEADER_SYNC_ADDRESS: string; + readonly VITE_MAINNET_BRIDGE_ADDRESS: string; + readonly VITE_TAIKO_BRIDGE_ADDRESS: string; + readonly VITE_MAINNET_SIGNAL_SERVICE_ADDRESS: string; + readonly VITE_TAIKO_SIGNAL_SERVICE_ADDRESS: string; + readonly VITE_TEST_ERC20: string; +} + +interface ImportMeta { + readonly env: ImportMetaEnv; +} From f43101bfd25fbb7c0a71a758ebec706a5b49448a Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Mon, 13 Mar 2023 20:01:05 +0530 Subject: [PATCH 3/5] fix(bridge-ui): pending transaction store logic --- packages/bridge-ui/src/App.svelte | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/bridge-ui/src/App.svelte b/packages/bridge-ui/src/App.svelte index 063d10f7ef1..ca04b9c9ad4 100644 --- a/packages/bridge-ui/src/App.svelte +++ b/packages/bridge-ui/src/App.svelte @@ -174,14 +174,20 @@ }); pendingTransactions.subscribe((store) => { - store.forEach(async (tx, index) => { - await $signer.provider.waitForTransaction(tx.hash, 1); + (async () => { + const confirmedPendingTxIndex = await Promise.race( + store.map((tx, index) => { + return new Promise(async (resolve) => { + await $signer.provider.waitForTransaction(tx.hash, 1); + resolve(index); + }); + }), + ); successToast('Transaction completed!'); - - const s = store; - s.slice(index, 0); + let s = store; + s = s.slice(confirmedPendingTxIndex, 0); pendingTransactions.set(s); - }); + })(); }); const transactionToIntervalMap = new Map(); From 35b5bb66dc15616c80fd5f66afd47261804768bf Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Mon, 13 Mar 2023 20:01:30 +0530 Subject: [PATCH 4/5] fix(bridge-ui): transaction ordering --- packages/bridge-ui/src/relayer-api/service.ts | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/bridge-ui/src/relayer-api/service.ts b/packages/bridge-ui/src/relayer-api/service.ts index 4f7cf7f8500..e0ca0856530 100644 --- a/packages/bridge-ui/src/relayer-api/service.ts +++ b/packages/bridge-ui/src/relayer-api/service.ts @@ -43,10 +43,6 @@ class RelayerAPIService implements RelayerAPI { } const txs: BridgeTransaction[] = data.map((tx) => { - const depositValue = ethers.utils.parseUnits( - tx.data.Message.DepositValue.toString(), - 'wei', - ); return { status: tx.status, message: { @@ -60,8 +56,8 @@ class RelayerAPIService implements RelayerAPI { callValue: tx.data.Message.CallValue, srcChainId: BigNumber.from(tx.data.Message.SrcChainId), destChainId: BigNumber.from(tx.data.Message.DestChainId), - depositValue: depositValue, - processingFee: BigNumber.from(tx.data.Message.ProcessingFee), + depositValue: BigNumber.from(`${tx.data.Message.DepositValue}`), + processingFee: BigNumber.from(`${tx.data.Message.ProcessingFee}`), refundAddress: tx.data.Message.RefundAddress, }, amountInWei: tx.amount, @@ -73,9 +69,7 @@ class RelayerAPIService implements RelayerAPI { }; }); - const bridgeTxs: BridgeTransaction[] = []; - - await Promise.all( + const bridgeTxs: BridgeTransaction[] = await Promise.all( (txs || []).map(async (tx) => { if (tx.message.owner.toLowerCase() !== address.toLowerCase()) return; @@ -116,7 +110,9 @@ class RelayerAPIService implements RelayerAPI { ); const event = events.find( - (e) => e.args.message.owner.toLowerCase() === address.toLowerCase(), + (e) => + e.args.message.owner.toLowerCase() === address.toLowerCase() && + e.args.message.depositValue.eq(tx.message.depositValue), ); if (!event) { @@ -172,12 +168,12 @@ class RelayerAPIService implements RelayerAPI { from: tx.from, }; - bridgeTxs.push(bridgeTx); + return bridgeTx; }), ); + bridgeTxs.reverse(); bridgeTxs.sort((tx) => (tx.status === MessageStatus.New ? -1 : 1)); - return bridgeTxs; } From 09caad788fc89fc2be11a6c4a0eef49017089996 Mon Sep 17 00:00:00 2001 From: Shadab Khan Date: Wed, 15 Mar 2023 13:10:51 +0530 Subject: [PATCH 5/5] fix(bridge-ui): compare msgHash --- packages/bridge-ui/src/relayer-api/service.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/bridge-ui/src/relayer-api/service.ts b/packages/bridge-ui/src/relayer-api/service.ts index e0ca0856530..7a93e071aa8 100644 --- a/packages/bridge-ui/src/relayer-api/service.ts +++ b/packages/bridge-ui/src/relayer-api/service.ts @@ -38,11 +38,11 @@ class RelayerAPIService implements RelayerAPI { const { data } = await axios.get(requestURL, { params }); - if (data.length === 0) { + if (data?.items?.length === 0) { return []; } - const txs: BridgeTransaction[] = data.map((tx) => { + const txs: BridgeTransaction[] = data.items.map((tx) => { return { status: tx.status, message: { @@ -81,8 +81,7 @@ class RelayerAPIService implements RelayerAPI { const receipt = await srcProvider.getTransactionReceipt(tx.hash); if (!receipt) { - bridgeTxs.push(tx); - return; + return tx; } tx.receipt = receipt; @@ -109,15 +108,16 @@ class RelayerAPIService implements RelayerAPI { receipt.blockNumber, ); + // A block could have multiple events being triggered so we need to find this particular tx const event = events.find( (e) => e.args.message.owner.toLowerCase() === address.toLowerCase() && - e.args.message.depositValue.eq(tx.message.depositValue), + e.args.message.depositValue.eq(tx.message.depositValue) && + e.args.msgHash === tx.msgHash, ); if (!event) { - bridgeTxs.push(tx); - return; + return tx; } const msgHash = event.args.msgHash;