diff --git a/src/app/hooks/use-load-tokens-apy.hook.ts b/src/app/hooks/use-load-tokens-apy.hook.ts index 17af100aa..6191adf2c 100644 --- a/src/app/hooks/use-load-tokens-apy.hook.ts +++ b/src/app/hooks/use-load-tokens-apy.hook.ts @@ -3,9 +3,8 @@ import { useEffect, useState } from 'react'; import { useDispatch } from 'react-redux'; import { forkJoin } from 'rxjs'; -import { useTezos } from '../../lib/temple/front'; -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$, @@ -13,29 +12,36 @@ 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(); 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 5762816b8..e2b715df8 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/metadata/fetch.ts b/src/lib/metadata/fetch.ts index 33a86a3bf..154386006 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); diff --git a/src/lib/temple/front/baking.ts b/src/lib/temple/front/baking.ts index f17fbe99a..dc1d37fc4 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]);