Skip to content

Commit

Permalink
feat: removed unnecessary useeffect, modfied btc entry point return i…
Browse files Browse the repository at this point in the history
…f balance is undefined
  • Loading branch information
Polybius93 committed Dec 14, 2023
1 parent bc909cf commit c858abb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Flex cursor={cursor} onClick={onClick} outline={0}>
Expand Down
16 changes: 5 additions & 11 deletions src/app/query/bitcoin/balance/bitcoin-contracts-balance.hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useState } from 'react';
import { useMemo } from 'react';

import BigNumber from 'bignumber.js';

Expand All @@ -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<string>('0');

useEffect(() => {
if (isUndefined(bitcoinContractsBalance)) return;
setBitcoinContractsBalanceInUSD(
i18nFormatCurrency(calculateFiatValue(createMoney(bitcoinContractsBalance.amount, 'BTC')))
);
}, [bitcoinContractsBalance, calculateFiatValue]);

return useMemo(() => {
if (isUndefined(bitcoinContractsBalance))
Expand All @@ -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]);
}

0 comments on commit c858abb

Please sign in to comment.