From 1b06afffeb216fced7946e156031a8553e1add38 Mon Sep 17 00:00:00 2001 From: Fionna <13184582+fionnachan@users.noreply.github.com> Date: Thu, 19 Dec 2024 19:43:51 +0000 Subject: [PATCH] add more code --- .../getParentToChildEventsByTxHash.ts | 87 +++++++++++++------ 1 file changed, 59 insertions(+), 28 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionHistoryTxHashSearch/getParentToChildEventsByTxHash.ts b/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionHistoryTxHashSearch/getParentToChildEventsByTxHash.ts index b69b94f7dc..d8a9bdb74e 100644 --- a/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionHistoryTxHashSearch/getParentToChildEventsByTxHash.ts +++ b/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionHistoryTxHashSearch/getParentToChildEventsByTxHash.ts @@ -5,6 +5,7 @@ import { EthDepositMessage, getArbitrumNetworks } from '@arbitrum/sdk' import { getParentTxReceipt } from '../helpers' import { getProviderForChainId } from '@/token-bridge-sdk/utils' import { normalizeTimestamp } from '../../../state/app/utils' +import { ParentToChildMessagesAndDepositMessages } from './helpers' export type FetchDepositTxFromEventLogResult = { receiver: string @@ -60,48 +61,78 @@ export async function getParentToChildEventsByTxHash( return [] } - // to test for child chain, filter chains that has this parent chain id as parent - // and then loop through it............. - const childChains = getArbitrumNetworks() - .filter(childChain => childChain.parentChainId === parentChainId) - .map(network => network.chainId) + const childChainMessages = getArbitrumNetworks() + .filter(childChain => childChain.parentChainId === parentChainId) + .map(async childChain => { + const childChainId = childChain.chainId + const childProvider = getProviderForChainId(childChainId) - parentTxReceipt. + // Check if any parentToChild msg is sent to the inbox of this child chain + const logFromChildChainInbox = parentTxReceipt.logs.filter( + log => + log.address.toLowerCase() === childChain.ethBridge.inbox.toLowerCase() + ) - const parentToChildMessages = isClassic - ? await parentTxReceipt.getParentToChildMessagesClassic(childProvider) - : await parentTxReceipt.getParentToChildMessages(childProvider) + if (logFromChildChainInbox.length === 0) { + return + } - const parentToChildMessageReader = parentToChildMessages[0] + const isClassic = await parentTxReceipt.isClassic(childProvider) - if (!parentToChildMessageReader) { - return [] - } + const parentToChildMessages = isClassic + ? await parentTxReceipt.getParentToChildMessagesClassic(childProvider) + : await parentTxReceipt.getParentToChildMessages(childProvider) - const ethDeposits = await parentTxReceipt.getEthDeposits(childProvider) + const ethDeposits = await parentTxReceipt.getEthDeposits(childProvider) - const timestamp = normalizeTimestamp( - (await parentProvider.getBlock(parentTxReceipt.blockNumber)).timestamp - ) + const parentToChildMessageReader = parentToChildMessages[0] - const ethTransactions: FetchDepositTxFromEventLogResult[] = ethDeposits.map( - async depositMessage => { - const childProvider = getProviderForChainId(depositMessage.childChainId) + return { + ethDeposits + } + }) - const isClassic = await parentTxReceipt.isClassic(childProvider) + const messages = await Promise.all(childChainMessages) + const allMessages = messages.reduce( + (acc, value) => { + if (!value) { + return acc + } + return { + // retryables: acc.retryables.concat(value.allL1ToL2Messages), + // retryablesClassic: acc.retryablesClassic.concat( + // value.allL1ToL2MessagesClassic + // ), + ethDeposits: acc.deposits.concat(value.ethDeposits) + } + }, + { + retryables: [], + retryablesClassic: [], + deposits: [] + } as ParentToChildMessagesAndDepositMessages + ) + + const ethTransactions: FetchDepositTxFromEventLogResult[] = + allMessages?.ethDeposits.map(async depositMessage => { + const timestamp = normalizeTimestamp( + (await parentProvider.getBlock(parentTxReceipt.blockNumber)).timestamp + ) return { receiver: depositMessage.to, sender: depositMessage.from, - timestamp, - transactionHash: depositMessage. + timestamp: timestamp.toString(), + transactionHash: depositMessage.childTxHash, type: 'EthDeposit', - isClassic, + isClassic: false, + id: depositMessage.childTxHash, ethValue: depositMessage.value.toString(), blockCreatedAt: parentTxReceipt.blockNumber.toString() - } - } - ) + } as FetchDepositTxFromEventLogResult + }) - return transaction + return { + ethTransactions + } }