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; tokenMetas: TokenMetas;
}; };
// TODO: handle partial
const TokenTransferItem: React.FC<TokenTransferItemProps> = ({ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
t, t,
txData, txData,

View File

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