Skip to content

Commit

Permalink
Modified to iterate over networks and assets sequentially
Browse files Browse the repository at this point in the history
  • Loading branch information
Arshad Mahmood committed Aug 22, 2022
1 parent 19aef49 commit 5960fdf
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/db/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ type AssetInfoCallback = (assetInfo: Asset) => Promise<void>;
export async function assetsForEach(callback: AssetInfoCallback, complete?: () => Promise<void>) {
try {
const networks = await getNetworks();
await Promise.all(networks.map(async network => {
for (const network of networks) {
const assets = await getAssetsForNetwork(network.networkCode);
return Promise.all(assets.map(async asset => {
return callback(asset);
}));
}));
for (const asset of assets) {
await callback(asset);
}
}

if (complete) {
await complete();
}

} catch (err) {
throw err;
}
Expand All @@ -29,12 +28,12 @@ export async function assetForId(id: string, callback: AssetInfoCallback) {
const assets = await fetchAssetsCsv();
const assetCsvRow = assets.get(`id:${id}`);

if(!assetCsvRow) {
if (!assetCsvRow) {
return callback(null);
}
}
const asset = (await getAssetsForNetwork(assetCsvRow.primaryNetwork)).find((asset) => asset.id === id);

return callback(asset);
return callback(asset);
} catch (err) {
throw err;
}
Expand All @@ -45,7 +44,6 @@ export async function findAssetByNetworkIdAndAddress(
address: string,
callback: AssetInfoCallback
) {

try {
const asset = (await getAssetsForNetwork(networkCode)).find((asset) => asset.address === address);
return callback(asset);
Expand Down

0 comments on commit 5960fdf

Please sign in to comment.