Skip to content

Commit

Permalink
refactor: use isDefined function in filter
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarkhanzadian committed Jan 9, 2024
1 parent 336e12c commit ca7b44c
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/app/pages/fund/choose-asset-to-fund/choose-asset-to-fund.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand All @@ -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]
);

Expand Down

0 comments on commit ca7b44c

Please sign in to comment.