Skip to content

Commit

Permalink
chore: add pagination to bridge transactions (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizAsFight authored Sep 17, 2024
1 parent 3bd3080 commit 6c950b2
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions packages/app-portal/src/systems/Chains/fuel/services/txFuelToEth.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 6c950b2

Please sign in to comment.