Skip to content

Commit

Permalink
add fromTimestamp to limit query results
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Polyakov committed Mar 4, 2024
1 parent 2faf813 commit c898450
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/components/pages/Swap/TransactionsWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ export default class SwapTransactionsWidget extends Mixins(ScrollableTableMixin)
private readonly operations = [Operation.Swap];
private interval: Nullable<ReturnType<typeof setInterval>> = null;
private updateTransactions = debouncedInputHandler(this.updateData, 250, { leading: false });
private intervalTimestamp = 0;
private fromTimestamp = dayjs().subtract(1, 'month').startOf('day').unix(); // month ago, start of the day
private timestamp = 0;
private totalCount = 0;
private transactions: HistoryItem[] = [];
Expand Down Expand Up @@ -241,7 +242,7 @@ export default class SwapTransactionsWidget extends Mixins(ScrollableTableMixin)
await this.fetchData();
if (this.currentPage === 1) {
this.updateTimestamp();
this.updateIntervalTimestamp();
this.subscribeOnData();
}
}
Expand All @@ -250,7 +251,7 @@ export default class SwapTransactionsWidget extends Mixins(ScrollableTableMixin)
const { pageAmount, currentPage } = this;
const variables = {
filter: this.createFilter(),
filter: this.createFilter(this.fromTimestamp),
first: pageAmount,
offset: pageAmount * (currentPage - 1),
};
Expand All @@ -266,11 +267,11 @@ export default class SwapTransactionsWidget extends Mixins(ScrollableTableMixin)
}
private async fetchDataUpdates(): Promise<void> {
const variables = { filter: this.createFilter(this.timestamp) };
const variables = { filter: this.createFilter(this.intervalTimestamp) };
const { transactions, totalCount } = await this.requestData(variables);
this.transactions = [...transactions, ...this.transactions].slice(0, this.pageAmount);
this.totalCount = this.totalCount + totalCount;
this.updateTimestamp();
this.updateIntervalTimestamp();
}
private async requestData(variables): Promise<{ transactions: HistoryItem[]; totalCount: number }> {
Expand Down Expand Up @@ -298,8 +299,8 @@ export default class SwapTransactionsWidget extends Mixins(ScrollableTableMixin)
return { transactions, totalCount };
}
private updateTimestamp(): void {
this.timestamp = Math.floor((this.transactions[0]?.startTime ?? 0) / 1000);
private updateIntervalTimestamp(): void {
this.intervalTimestamp = Math.floor((this.transactions[0]?.startTime ?? 0) / 1000);
}
private subscribeOnData(): void {
Expand Down

0 comments on commit c898450

Please sign in to comment.