From 6c950b26f64873a9b8d8b6ef7afb4484743086c9 Mon Sep 17 00:00:00 2001 From: Luiz Gomes <8636507+LuizAsFight@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:35:25 -0300 Subject: [PATCH] chore: add pagination to bridge transactions (#543) --- .../Chains/fuel/services/txFuelToEth.ts | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/packages/app-portal/src/systems/Chains/fuel/services/txFuelToEth.ts b/packages/app-portal/src/systems/Chains/fuel/services/txFuelToEth.ts index 64d38fce..76e366b7 100644 --- a/packages/app-portal/src/systems/Chains/fuel/services/txFuelToEth.ts +++ b/packages/app-portal/src/systems/Chains/fuel/services/txFuelToEth.ts @@ -1,7 +1,12 @@ import fungibleTokenABI from '@fuel-bridge/fungible-token/bridge-fungible-token/implementation/out/release/bridge_fungible_token-abi.json'; import type { NetworkFuel } from '@fuel-ts/account'; import dayjs from 'dayjs'; -import type { Account as FuelWallet, BN, MessageProof } from 'fuels'; +import type { + Account as FuelWallet, + BN, + MessageProof, + TransactionResult, +} from 'fuels'; import { Address as FuelAddress, Contract, @@ -468,17 +473,29 @@ export class TxFuelToEthService { const { fuelAddress, fuelProvider } = input; - const txSummaries = await getTransactionsSummaries({ - provider: fuelProvider, - filters: { - owner: fuelAddress?.toB256(), - first: 100, - }, - }); + const bridgeTxs: TransactionResult[] = []; + + let hasNextPage = true; + let endCursor = undefined; + // go until last page + while (hasNextPage) { + const { transactions, pageInfo } = await getTransactionsSummaries({ + provider: fuelProvider, + filters: { + owner: fuelAddress?.toB256(), + first: 100, + after: endCursor, + }, + }); - const bridgeTxs = txSummaries.transactions.filter( - (txSummary) => !!getReceiptsMessageOut(txSummary.receipts)?.[0], - ); + const withdrawTxs = transactions.filter( + (txSummary) => !!getReceiptsMessageOut(txSummary.receipts)?.[0], + ); + bridgeTxs.push(...withdrawTxs); + + hasNextPage = pageInfo.hasNextPage; + endCursor = pageInfo.endCursor; + } return bridgeTxs; }