From ca7b44cc4b53a5f12a56d8efab55d8345355a749 Mon Sep 17 00:00:00 2001 From: Edgar Khanzadian Date: Tue, 9 Jan 2024 18:24:49 +0400 Subject: [PATCH] refactor: use isDefined function in filter --- .../choose-asset-to-fund.tsx | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/app/pages/fund/choose-asset-to-fund/choose-asset-to-fund.tsx b/src/app/pages/fund/choose-asset-to-fund/choose-asset-to-fund.tsx index 5276ba8e9ba..6ed18bca538 100644 --- a/src/app/pages/fund/choose-asset-to-fund/choose-asset-to-fund.tsx +++ b/src/app/pages/fund/choose-asset-to-fund/choose-asset-to-fund.tsx @@ -1,12 +1,9 @@ import { useCallback, useMemo } from 'react'; import { Outlet, useNavigate } from 'react-router-dom'; -import { - AllTransferableCryptoAssetBalances, - BitcoinCryptoCurrencyAssetBalance, - StacksCryptoCurrencyAssetBalance, -} from '@shared/models/crypto-asset-balance.model'; +import { AllTransferableCryptoAssetBalances } from '@shared/models/crypto-asset-balance.model'; import { RouteUrls } from '@shared/route-urls'; +import { isDefined } from '@shared/utils'; import { useBtcCryptoCurrencyAssetBalance } from '@app/common/hooks/balance/btc/use-btc-crypto-currency-asset-balance'; import { useStxCryptoCurrencyAssetBalance } from '@app/common/hooks/balance/stx/use-stx-crypto-currency-asset-balance'; @@ -18,8 +15,6 @@ import { CryptoAssetList } from '@app/components/crypto-assets/choose-crypto-ass import { ModalHeader } from '@app/components/modal-header'; import { useCheckLedgerBlockchainAvailable } from '@app/store/accounts/blockchain/utils'; -type CryptoAssetBalance = BitcoinCryptoCurrencyAssetBalance | StacksCryptoCurrencyAssetBalance; - export function ChooseCryptoAssetToFund() { const btcCryptoCurrencyAssetBalance = useBtcCryptoCurrencyAssetBalance(); const stxCryptoCurrencyAssetBalance = useStxCryptoCurrencyAssetBalance(); @@ -36,14 +31,12 @@ export function ChooseCryptoAssetToFund() { const filteredCryptoAssetBalances = useMemo( () => - cryptoCurrencyAssetBalances - .filter((assetBalance): assetBalance is CryptoAssetBalance => assetBalance != null) - .filter(assetBalance => - whenWallet({ - ledger: checkBlockchainAvailable(assetBalance?.blockchain), - software: true, - }) - ), + cryptoCurrencyAssetBalances.filter(isDefined).filter(assetBalance => + whenWallet({ + ledger: checkBlockchainAvailable(assetBalance?.blockchain), + software: true, + }) + ), [cryptoCurrencyAssetBalances, checkBlockchainAvailable, whenWallet] );