Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat(prices-selector): Add GetMany support
Browse files Browse the repository at this point in the history
  • Loading branch information
JForsaken committed Aug 1, 2022
1 parent 6f8e5ff commit 1222d78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/token/price-selector.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
CreatePriceSelectorOptions,
Filters,
GetAll,
GetMany,
GetOne,
PriceSelector,
PriceSelectorFactory,
Expand Down Expand Up @@ -73,8 +74,14 @@ export class PriceSelectorService implements PriceSelectorFactory {

return {
getAll: opts => this.getAllFromCache(opts, filters),
getOne: ({ network, address }: Parameters<GetOne>[0]) => {
return tokenDataLoader.load({ network, address });
getOne: ({ network, address }: Parameters<GetOne>[0]) => tokenDataLoader.load({ network, address }),
getMany: async (queries: Parameters<GetMany>[0]) => {
const docs = await tokenDataLoader.loadMany(queries);

return docs.map(doc => {
if (doc instanceof Error) return null;
return doc;
});
},
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/token/token-price-selector.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ export type LoggingTags = { appId?: string; network?: Network };

export type GetAll = (opts: { network: Network }) => Promise<BaseTokenPrice[]>;
export type GetOne = (opts: Parameters<GetAll>[0] & { address: string }) => Promise<BaseTokenPrice | null>;
export type GetMany = (opts: (Parameters<GetAll>[0] & { address: string })[]) => Promise<(BaseTokenPrice | null)[]>;

export interface PriceSelector {
getAll: GetAll;
getOne: GetOne;
getMany: GetMany;
}

export type CreatePriceSelectorOptions = { filters?: Filters; tags?: LoggingTags };
Expand Down

0 comments on commit 1222d78

Please sign in to comment.