Skip to content

Commit

Permalink
Adding start, limit and identifier filters to getAssetsForNetwork fun…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
pellicceama committed Nov 3, 2022
1 parent e8d4208 commit 6ed46a6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function getNetworksWithAssets(dir?: string): Promise<Network[]> {
}
}

export async function getAssetsForNetwork(network: string, dir?: string): Promise<Asset[]> {
export async function getAssetsForNetwork(network: string, dir?: string, limit?: number, start: number = 0, identifiersToFilter: string[] = []): Promise<Asset[]> {
if (!dir) {
dir = DEFAULT_REPO_DISK_LOCATION;
}
Expand All @@ -94,15 +94,28 @@ export async function getAssetsForNetwork(network: string, dir?: string): Promis
// TODO, make it work for multiple tokenlists
const assetDirs = await getDirectories(tokenlistDir);

assetDirs.forEach((directory) => {
let counter = 0;

for (const directory of assetDirs) {
if (counter >= start && counter < start + limit) {
break;
}
const split = directory.split("/");

if (split[split.length - 2] === `${network}-tokenlist` && !directory.includes(".git")) {
if(fs.existsSync(`${directory}/info.json`)) {
res.push(readAndParseJson(`${directory}/info.json`));
const asset = readAndParseJson(`${directory}/info.json`);

if(identifiersToFilter.length === 0 ||
Object.keys(asset.identifiers)
.some(identifierKey => identifiersToFilter.includes(identifierKey))) {

res.push(asset);
counter++;
}
}
}
});
}

return res;
} catch (err) {
Expand Down

0 comments on commit 6ed46a6

Please sign in to comment.