diff --git a/src/app/@api/member.api.ts b/src/app/@api/member.api.ts index a6f4340..78e3290 100644 --- a/src/app/@api/member.api.ts +++ b/src/app/@api/member.api.ts @@ -23,7 +23,7 @@ import { CustomTokenRequest, } from '@build-5/interfaces'; import dayjs from 'dayjs'; -import { Observable, combineLatest, map, of, switchMap } from 'rxjs'; +import { Observable, combineLatest, first, map, of, switchMap } from 'rxjs'; import { BaseApi } from './base.api'; export interface TokenDistributionWithAirdrops extends TokenDistribution { @@ -210,6 +210,68 @@ export class MemberApi extends BaseApi { ); } + public getAllTransactions( + memberId: string, + orderBy: string[] = ['createdOn'], + ): Observable { + return new Observable((observer) => { + let accumulatedTransactions: Transaction[] = []; + + const fetchPage = (lastValue?: string) => { + this.transactionDataset + .getTopTransactionsLive(orderBy, lastValue, memberId) + .pipe(first()) + .subscribe({ + next: (transactions) => { + if (transactions.length > 0) { + accumulatedTransactions = [...accumulatedTransactions, ...transactions]; + const lastTransaction = transactions[transactions.length - 1]; + fetchPage(lastTransaction.uid); + } else { + observer.next(accumulatedTransactions); + observer.complete(); + } + }, + error: (err) => observer.error(err), + }); + }; + + fetchPage(); + }); + } + + public getTransactionsWithLimit( + memberId: string, + totalRequired: number, + orderBy: string[] = ['createdOn'], + ): Observable { + return new Observable((observer) => { + let accumulatedTransactions: Transaction[] = []; + + const fetchPage = (lastValue?: string) => { + this.transactionDataset + .getTopTransactionsLive(orderBy, lastValue, memberId) + .pipe(first()) + .subscribe( + (transactions) => { + accumulatedTransactions = [...accumulatedTransactions, ...transactions]; + observer.next(accumulatedTransactions.slice(0, totalRequired)); + + if (transactions.length > 0 && accumulatedTransactions.length < totalRequired) { + const newLastValue = transactions[transactions.length - 1].uid; + fetchPage(newLastValue); + } else { + observer.complete(); + } + }, + (error) => observer.error(error), + ); + }; + + fetchPage(); + }); + } + public allSpacesAsMember = (memberId: NetworkAddress, lastValue?: string) => this.spaceDataset .subset(Subset.MEMBERS) diff --git a/src/app/pages/member/member.module.ts b/src/app/pages/member/member.module.ts index 8fc6c08..d0e2af3 100644 --- a/src/app/pages/member/member.module.ts +++ b/src/app/pages/member/member.module.ts @@ -61,6 +61,8 @@ import { MemberSpacesComponent } from './pages/spaces/member-spaces.component'; import { TokensPage } from './pages/tokens/tokens.page'; import { TransactionsPage } from './pages/transactions/transactions.page'; import { DataService } from './services/data.service'; +import { NzRadioModule } from 'ng-zorro-antd/radio'; +import { NzSpinModule } from 'ng-zorro-antd/spin'; @NgModule({ declarations: [ @@ -128,6 +130,8 @@ import { DataService } from './services/data.service'; NftDepositModule, NftStakeModule, TokenTradingPairsTableModule, + NzRadioModule, + NzSpinModule, ], }) export class MemberModule {} diff --git a/src/app/pages/member/pages/transactions/transactions.page.html b/src/app/pages/member/pages/transactions/transactions.page.html index af0e419..fcfc806 100644 --- a/src/app/pages/member/pages/transactions/transactions.page.html +++ b/src/app/pages/member/pages/transactions/transactions.page.html @@ -3,6 +3,52 @@ +
+
+ Select number of transactions to view/export: +
+ + + + + + + +
+