Guard against errors on getting erc20 metadata

This commit is contained in:
Willian Mitsuda 2021-09-22 15:30:54 -03:00
parent b5c76a4e01
commit 5e982d3b55
2 changed files with 15 additions and 10 deletions

View File

@ -18,6 +18,7 @@ type TokenTransferItemProps = {
tokenMetas: TokenMetas;
};
// TODO: handle partial
const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
t,
txData,

View File

@ -225,16 +225,20 @@ export const useTxData = (
continue;
}
const erc20Contract = new Contract(t.token, erc20, provider);
const [name, symbol, decimals] = await Promise.all([
erc20Contract.name(),
erc20Contract.symbol(),
erc20Contract.decimals(),
]);
tokenMetas[t.token] = {
name,
symbol,
decimals,
};
try {
const [name, symbol, decimals] = await Promise.all([
erc20Contract.name(),
erc20Contract.symbol(),
erc20Contract.decimals(),
]);
tokenMetas[t.token] = {
name,
symbol,
decimals,
};
} catch (err) {
console.warn(`Couldn't get token ${t.token} metadata; ignoring`, err);
}
}
setTxData({