From e75f0f03be2790920428e6506257da62cdfc4b64 Mon Sep 17 00:00:00 2001 From: lendihop Date: Fri, 20 Oct 2023 17:11:16 +0200 Subject: [PATCH 1/3] fix --- src/app/hooks/use-load-tokens-apy.hook.ts | 34 +++++++++++++---------- src/app/hooks/use-metadata-refresh.ts | 13 +++++---- src/lib/temple/front/baking.ts | 20 ++----------- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/app/hooks/use-load-tokens-apy.hook.ts b/src/app/hooks/use-load-tokens-apy.hook.ts index 17af100aae..e92f64b4a4 100644 --- a/src/app/hooks/use-load-tokens-apy.hook.ts +++ b/src/app/hooks/use-load-tokens-apy.hook.ts @@ -3,7 +3,8 @@ import { useEffect, useState } from 'react'; import { useDispatch } from 'react-redux'; import { forkJoin } from 'rxjs'; -import { useTezos } from '../../lib/temple/front'; +import { useChainId, useTezos } from '../../lib/temple/front'; +import { TempleChainId } from '../../lib/temple/types'; import { useUsdToTokenRatesSelector } from '../store/currency/selectors'; import { loadTokensApyActions } from '../store/d-apps/actions'; import { @@ -18,24 +19,29 @@ import { export const useTokensApyLoading = () => { const dispatch = useDispatch(); const tezos = useTezos(); + const chainId = useChainId(true)!; const usdToTokenRates = useUsdToTokenRatesSelector(); const [tokensApy, setTokensApy] = useState({}); useEffect(() => { - const subscription = forkJoin([ - fetchTzBtcApy$(), - fetchKUSDApy$(), - fetchUSDTApy$(), - fetchUUSDCApr$(tezos), - fetchUBTCApr$(tezos), - fetchYOUApr$(tezos, usdToTokenRates) - ]).subscribe(responses => { - setTokensApy(Object.assign({}, ...responses)); - }); - - return () => subscription.unsubscribe(); - }, [usdToTokenRates]); + if (chainId === TempleChainId.Mainnet) { + const subscription = forkJoin([ + fetchTzBtcApy$(), + fetchKUSDApy$(), + fetchUSDTApy$(), + fetchUUSDCApr$(tezos), + fetchUBTCApr$(tezos), + fetchYOUApr$(tezos, usdToTokenRates) + ]).subscribe(responses => { + setTokensApy(Object.assign({}, ...responses)); + }); + + return () => subscription.unsubscribe(); + } + + return; + }, [chainId, usdToTokenRates, tezos]); useEffect(() => { dispatch(loadTokensApyActions.success(tokensApy)); diff --git a/src/app/hooks/use-metadata-refresh.ts b/src/app/hooks/use-metadata-refresh.ts index 5762816b81..e2b715df8a 100644 --- a/src/app/hooks/use-metadata-refresh.ts +++ b/src/app/hooks/use-metadata-refresh.ts @@ -4,10 +4,11 @@ import { useDispatch } from 'react-redux'; import { refreshTokensMetadataAction } from 'app/store/tokens-metadata/actions'; import { useTokensMetadataSelector } from 'app/store/tokens-metadata/selectors'; +import { fetchTokensMetadata } from 'lib/apis/temple'; import { TokenMetadata } from 'lib/metadata'; -import { fetchTokensMetadata } from 'lib/metadata/fetch'; import { buildTokenMetadataFromFetched } from 'lib/metadata/utils'; -import { useChainId, useTezos } from 'lib/temple/front'; +import { useChainId } from 'lib/temple/front'; +import { TempleChainId } from 'lib/temple/types'; import { useLocalStorage } from 'lib/ui/local-storage'; const STORAGE_KEY = 'METADATA_REFRESH'; @@ -17,7 +18,6 @@ type RefreshRecords = Record; const REFRESH_VERSION = 1; export const useMetadataRefresh = () => { - const tezos = useTezos(); const chainId = useChainId()!; const dispatch = useDispatch(); @@ -38,8 +38,10 @@ export const useMetadataRefresh = () => { return; } - if (needToSetVersion) - fetchTokensMetadata(tezos.rpc.getRpcUrl(), slugsOnAppLoad) + if (!needToSetVersion) return; + + if (chainId === TempleChainId.Mainnet) { + fetchTokensMetadata(chainId, slugsOnAppLoad) .then(data => data.reduce((acc, token, index) => { const slug = slugsOnAppLoad[index]!; @@ -57,5 +59,6 @@ export const useMetadataRefresh = () => { }, error => console.error(error) ); + } }, [chainId]); }; diff --git a/src/lib/temple/front/baking.ts b/src/lib/temple/front/baking.ts index f17fbe99a3..dc1d37fc4e 100644 --- a/src/lib/temple/front/baking.ts +++ b/src/lib/temple/front/baking.ts @@ -1,6 +1,5 @@ import { useCallback, useMemo } from 'react'; -import { HttpResponseError, HttpRequestFailed } from '@taquito/http-utils'; import BigNumber from 'bignumber.js'; import { @@ -20,23 +19,8 @@ export function useDelegate(address: string, suspense = true) { const getDelegate = useCallback(async () => { try { return await tezos.rpc.getDelegate(address); - } catch (error: unknown) { - if (error instanceof HttpResponseError) { - if (error.status === 404) return null; - } - if (error instanceof HttpRequestFailed) { - /* - `@taquito/http-utils` package uses `@vespaiach/axios-fetch-adapter`, - which throws a SyntaxError in case of 404 response. - See: https://github.com/vespaiach/axios-fetch-adapter/issues/25 - */ - if (/SyntaxError(.*)JSON/.test(error.message)) { - console.error('Presumably, `@vespaiach/axios-fetch-adapter` SyntaxError (taken as 404):', { error }); - return null; - } - } - - throw error; + } catch { + return null; } }, [address, tezos]); From 771d5e5fcdfa8720582d33849bb5435e19389a53 Mon Sep 17 00:00:00 2001 From: lendihop Date: Fri, 20 Oct 2023 17:14:01 +0200 Subject: [PATCH 2/3] imports fix --- src/app/hooks/use-load-tokens-apy.hook.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/hooks/use-load-tokens-apy.hook.ts b/src/app/hooks/use-load-tokens-apy.hook.ts index e92f64b4a4..6191adf2cc 100644 --- a/src/app/hooks/use-load-tokens-apy.hook.ts +++ b/src/app/hooks/use-load-tokens-apy.hook.ts @@ -3,10 +3,8 @@ import { useEffect, useState } from 'react'; import { useDispatch } from 'react-redux'; import { forkJoin } from 'rxjs'; -import { useChainId, useTezos } from '../../lib/temple/front'; -import { TempleChainId } from '../../lib/temple/types'; -import { useUsdToTokenRatesSelector } from '../store/currency/selectors'; -import { loadTokensApyActions } from '../store/d-apps/actions'; +import { useUsdToTokenRatesSelector } from 'app/store/currency/selectors'; +import { loadTokensApyActions } from 'app/store/d-apps/actions'; import { fetchKUSDApy$, fetchTzBtcApy$, @@ -14,7 +12,9 @@ import { fetchUSDTApy$, fetchUUSDCApr$, fetchYOUApr$ -} from '../store/d-apps/utils'; +} from 'app/store/d-apps/utils'; +import { useChainId, useTezos } from 'lib/temple/front'; +import { TempleChainId } from 'lib/temple/types'; export const useTokensApyLoading = () => { const dispatch = useDispatch(); From a0562c32f6015be350d4aaa08d6d0cf99c100eea Mon Sep 17 00:00:00 2001 From: lendihop Date: Fri, 20 Oct 2023 17:16:12 +0200 Subject: [PATCH 3/3] rm export --- src/lib/metadata/fetch.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/lib/metadata/fetch.ts b/src/lib/metadata/fetch.ts index 33a86a3bf5..1543860068 100644 --- a/src/lib/metadata/fetch.ts +++ b/src/lib/metadata/fetch.ts @@ -36,10 +36,7 @@ export const fetchOneTokenMetadata = async ( return chainTokenMetadataToBase(metadataOnChain) || undefined; }; -export const fetchTokensMetadata = async ( - rpcUrl: string, - slugs: string[] -): Promise<(TokenMetadataResponse | null)[]> => { +const fetchTokensMetadata = async (rpcUrl: string, slugs: string[]): Promise<(TokenMetadataResponse | null)[]> => { if (slugs.length === 0) return []; const tezos = new TezosToolkit(rpcUrl);