Skip to content

Commit

Permalink
Merge pull request #14 from soonaverse/fix/1170
Browse files Browse the repository at this point in the history
Added ability to pull all tokens within the API
  • Loading branch information
adamunchained authored Jul 23, 2023
2 parents c6ed2a1 + a9c428c commit 6c232b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
13 changes: 12 additions & 1 deletion src/app/@api/token.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
WenRequest,
} from '@build-5/interfaces';
import { TokenDistributionRepository, TokenRepository, TokenStatsRepository } from '@build-5/lib';
import { Observable, of } from 'rxjs';
import { Observable, firstValueFrom, lastValueFrom, of } from 'rxjs';
import { BaseApi, SOON_ENV } from './base.api';

@Injectable({
Expand Down Expand Up @@ -91,6 +91,17 @@ export class TokenApi extends BaseApi<Token> {
return distributions;
};

public getAllTokens = async () => {
const tokens: Token[] = [];
let actTokens: Token[] = [];
do {
const last = tokens[tokens.length - 1]?.uid;
actTokens = await this.tokenRepo.getByField('approved', true, last);
tokens.push(...actTokens);
} while (actTokens.length === QUERY_MAX_LENGTH);
return tokens;
};

public stats(tokenId: string) {
if (!tokenId) {
return of(undefined);
Expand Down
21 changes: 9 additions & 12 deletions src/app/pages/award/pages/new/new.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,18 @@ export class NewPage implements OnInit, OnDestroy {
}
});

this.subscriptions$.push(
this.tokenApi
.top(undefined, 1)
.pipe(
map((tokens) => {
return tokens?.filter((t) => {
this.tokenApi
.getAllTokens()
.then(
(tokens) => {
this.tokens$.next(tokens?.filter((t) => {
return (
TEST_AVAILABLE_MINTABLE_NETWORKS.indexOf(<any>t.mintingData?.network) > -1 ||
t.status === TokenStatus.BASE
);
});
}),
)
.subscribe(this.tokens$),
);
) && t.approved;
}))
}
);
}

public trackByUid(index: number, item: any): number {
Expand Down

0 comments on commit 6c232b0

Please sign in to comment.