diff --git a/source/components/AssetItem/index.jsx b/source/components/AssetItem/index.jsx index 6e4da77e..20f9e257 100644 --- a/source/components/AssetItem/index.jsx +++ b/source/components/AssetItem/index.jsx @@ -17,17 +17,14 @@ const AssetItem = ({ updateToken, logo, name, amount, value, symbol, loading, failed, assetNameTestId, }) => { const classes = useStyles(); - const [fetchLoading, setFetchLoading] = useState(false); const { t } = useTranslation(); const { currentNetwork, usingMainnet } = useSelector((state) => state.network); const handleFetchAssets = async () => { // Avoid calling multiple times - if (fetchLoading) return; + if (loading) return; - setFetchLoading(true); await updateToken(); - setFetchLoading(false); }; const ledgerNotSpecified = !usingMainnet && !currentNetwork?.ledgerCanisterId; return ( @@ -79,7 +76,6 @@ const AssetItem = ({ : ()} )} - ); diff --git a/source/components/Tokens/index.jsx b/source/components/Tokens/index.jsx index ba051adb..d1f9b109 100644 --- a/source/components/Tokens/index.jsx +++ b/source/components/Tokens/index.jsx @@ -23,19 +23,31 @@ const Tokens = () => { const { navigator } = useRouter(); const { onScroll, fullScroll } = useScroll(); - const fetchAssets = () => { + const fetchAssets = (cb = () => {}) => { sendMessage({ type: HANDLER_TYPES.GET_ASSETS, params: {}, }, (keyringAssets) => { + cb(keyringAssets); dispatch(setAssets({ keyringAssets, icpPrice })); dispatch(setAssetsLoading(false)); setLoading(false); }); }; + const handleFetchAssets = () => { + dispatch(setAssetsLoading(true)); + setLoading(true); + + return new Promise((resolve) => { + fetchAssets(resolve); + }); + }; + useEffect(() => { - const id = setInterval(fetchAssets, 15000); + const id = setInterval(() => { + !assetsLoading && fetchAssets(); + }, 15000); fetchAssets(); return () => clearInterval(id); }, [icpPrice]); @@ -66,7 +78,7 @@ const Tokens = () => { { export const parseAssetsAmount = (assets = []) => ( assets.map((currentAsset) => { const { amount, token, error } = currentAsset; + const hasError = error || amount === 'Error'; const { decimals } = token; - const parsedAmount = error + const parsedAmount = hasError ? 0 : parseToFloatAmount(amount, parseInt(decimals?.toString(), 10)); return { ...currentAsset, amount: parsedAmount, + error: hasError, }; }) );