Skip to content

Commit

Permalink
Remove timestamp-reference transaction from start of page (#2189)
Browse files Browse the repository at this point in the history
Removes the "extra" transaction between pages, fetched for `timestamp` reference:

- Move `slice` into main mapping function.
  • Loading branch information
iamacook authored Dec 17, 2024
1 parent b7640ed commit 2f1af10
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/routes/transactions/mappers/transactions-history.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,25 @@ export class TransactionsHistoryMapper {
if (transactionsDomain.length == 0) {
return [];
}
// Must be retrieved before mapping others as we remove it from transactionsDomain
const previousTransaction = await this.getPreviousTransaction({
offset,
transactionsDomain,
chainId,
safe,
onlyTrusted,
});

let previousTransaction: TransactionItem | undefined;

/**
* We insert a {@link DateLabel} between transactions on different days.
* On subsequent pages (offset > 0), we fetch the last transaction of previous page
* to determine if the first transaction of the current page is on the same day.
*/
if (offset > 0 && transactionsDomain.length > 1) {
previousTransaction = await this.getPreviousTransaction({
transactionsDomain,
chainId,
safe,
onlyTrusted,
});

// Remove first transaction that was requested to get previous day timestamp
transactionsDomain = transactionsDomain.slice(1);
}

const mappedTransactions = await this.getMappedTransactions({
transactionsDomain,
Expand Down Expand Up @@ -97,16 +108,11 @@ export class TransactionsHistoryMapper {
}

private async getPreviousTransaction(args: {
offset: number;
transactionsDomain: TransactionDomain[];
chainId: string;
safe: Safe;
onlyTrusted: boolean;
}): Promise<TransactionItem | undefined> {
// More than 1 element is required to get the previous transaction
if (args.offset <= 0 || args.transactionsDomain.length <= 1) {
return;
}
const prevDomainTransaction = args.transactionsDomain[0];
// We map in order to filter last list item against it
const mappedPreviousTransaction = await this.mapTransaction(
Expand All @@ -115,8 +121,6 @@ export class TransactionsHistoryMapper {
args.safe,
args.onlyTrusted,
);
// Remove first transaction that was requested to get previous day timestamp
args.transactionsDomain = args.transactionsDomain.slice(1);

return Array.isArray(mappedPreviousTransaction)
? // All transfers should have same execution date but the last is "true" previous
Expand Down

0 comments on commit 2f1af10

Please sign in to comment.