Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asynchronously fetch token data #872

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions src/fee_token_liquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,34 @@ export async function fetchTokenInfoFromExchange(
const ERC20 = artifacts.require("ERC20Detailed");
// Fetching token data from EVM
const tokenObjects: Map<number, TokenInfo> = new Map();
for (const id of tokenIds) {
const tokenAddress = await exchange.tokenIdToAddressMap(id);
let tokenInfo;
try {
const tokenInstance = await ERC20.at(tokenAddress);
const symbol = await tokenInstance.symbol();
const decimals = (await tokenInstance.decimals()).toNumber();
tokenInfo = {
id: id,
symbol: symbol,
decimals: decimals,
address: tokenAddress,
};
} catch (err) {
// This generic try-catch is essentially a TokenNotFoundError
// Could occur when the given ID slot is not occupied by a registered token on the exhchange
// or if the code registered at address occupied by a token slot is not that of and ERC20 token
tokenInfo = {
id: id,
address: tokenAddress,
};
}
tokenObjects.set(id, tokenInfo);
}
await Promise.all(
tokenIds.map(async (id) => {
const tokenAddress = await exchange.tokenIdToAddressMap(id);
let tokenInfo;
try {
const tokenInstance = await ERC20.at(tokenAddress);
const [symbol, decimals] = await Promise.all([
tokenInstance.symbol(),
tokenInstance.decimals(),
]);
tokenInfo = {
id: id,
symbol: symbol,
decimals: decimals.toNumber(),
address: tokenAddress,
};
} catch (err) {
// This generic try-catch is essentially a TokenNotFoundError
// Could occur when the given ID slot is not occupied by a registered token on the exhchange
// or if the code registered at address occupied by a token slot is not that of and ERC20 token
tokenInfo = {
id: id,
address: tokenAddress,
};
}
tokenObjects.set(id, tokenInfo);
}),
);
return tokenObjects;
}

Expand Down