From 5e982d3b55de5484ce5cba068ddf7fab47ea9391 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 22 Sep 2021 15:30:54 -0300 Subject: [PATCH] Guard against errors on getting erc20 metadata --- src/TokenTransferItem.tsx | 1 + src/useErigonHooks.ts | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/TokenTransferItem.tsx b/src/TokenTransferItem.tsx index a093b7f..c9f40a2 100644 --- a/src/TokenTransferItem.tsx +++ b/src/TokenTransferItem.tsx @@ -18,6 +18,7 @@ type TokenTransferItemProps = { tokenMetas: TokenMetas; }; +// TODO: handle partial const TokenTransferItem: React.FC = ({ t, txData, diff --git a/src/useErigonHooks.ts b/src/useErigonHooks.ts index 477f7b4..7322a0d 100644 --- a/src/useErigonHooks.ts +++ b/src/useErigonHooks.ts @@ -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({