From c858abb729a9c1a30f1793f5d8efb92554595ddc Mon Sep 17 00:00:00 2001 From: Polybius93 Date: Wed, 13 Dec 2023 17:13:16 +0100 Subject: [PATCH] feat: removed unnecessary useeffect, modfied btc entry point return if balance is undefined --- .../bitcoin-contract-entry-point-layout.tsx | 2 +- .../balance/bitcoin-contracts-balance.hooks.ts | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/app/components/bitcoin-contract-entry-point/bitcoin-contract-entry-point-layout.tsx b/src/app/components/bitcoin-contract-entry-point/bitcoin-contract-entry-point-layout.tsx index 3a0df94fb53..87921d4d498 100644 --- a/src/app/components/bitcoin-contract-entry-point/bitcoin-contract-entry-point-layout.tsx +++ b/src/app/components/bitcoin-contract-entry-point/bitcoin-contract-entry-point-layout.tsx @@ -26,7 +26,7 @@ export function BitcoinContractEntryPointLayout(props: BitcoinContractEntryPoint : balance.amount.toString(); const formattedBalance = formatBalance(amount); - if (Number(balance.amount) === 0) return false; + if (Number(balance.amount) === 0) return null; return ( diff --git a/src/app/query/bitcoin/balance/bitcoin-contracts-balance.hooks.ts b/src/app/query/bitcoin/balance/bitcoin-contracts-balance.hooks.ts index c2f7139f76e..7aad9c4d246 100644 --- a/src/app/query/bitcoin/balance/bitcoin-contracts-balance.hooks.ts +++ b/src/app/query/bitcoin/balance/bitcoin-contracts-balance.hooks.ts @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useState } from 'react'; +import { useMemo } from 'react'; import BigNumber from 'bignumber.js'; @@ -13,14 +13,6 @@ import { useBitcoinContractsBalanceQuery } from './bitcoin-contracts-balance.que export function useGetBitcoinContractsBalance() { const calculateFiatValue = useCalculateBitcoinFiatValue(); const { data: bitcoinContractsBalance, isLoading } = useBitcoinContractsBalanceQuery(); - const [bitcoinContractsBalanceInUSD, setBitcoinContractsBalanceInUSD] = useState('0'); - - useEffect(() => { - if (isUndefined(bitcoinContractsBalance)) return; - setBitcoinContractsBalanceInUSD( - i18nFormatCurrency(calculateFiatValue(createMoney(bitcoinContractsBalance.amount, 'BTC'))) - ); - }, [bitcoinContractsBalance, calculateFiatValue]); return useMemo(() => { if (isUndefined(bitcoinContractsBalance)) @@ -31,8 +23,10 @@ export function useGetBitcoinContractsBalance() { }; return { bitcoinContractsBalance, - bitcoinContractsBalanceInUSD: bitcoinContractsBalanceInUSD, + bitcoinContractsBalanceInUSD: i18nFormatCurrency( + calculateFiatValue(createMoney(bitcoinContractsBalance.amount, 'BTC')) + ), isLoading, }; - }, [bitcoinContractsBalance, bitcoinContractsBalanceInUSD, isLoading]); + }, [bitcoinContractsBalance, isLoading, calculateFiatValue]); }