Skip to content

Commit

Permalink
feat: filter out added chains in select chain UI (#6884)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodenfurniture authored May 13, 2024
1 parent 0d80b35 commit 3a7a892
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/ManageAccountsDrawer/components/SelectChain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { RawText } from 'components/Text'
import { availableLedgerChainIds } from 'context/WalletProvider/Ledger/constants'
import { useWallet } from 'hooks/useWallet/useWallet'
import { assertGetChainAdapter, chainIdToFeeAssetId } from 'lib/utils'
import { selectAssetById, selectWalletSupportedChainIds } from 'state/slices/selectors'
import {
selectAssetById,
selectWalletChainIds,
selectWalletSupportedChainIds,
} from 'state/slices/selectors'
import { useAppSelector } from 'state/store'

import { filterChainIdsBySearchTerm } from '../helpers'
Expand Down Expand Up @@ -55,11 +59,16 @@ export const SelectChain = ({ onSelectChainId, onClose }: SelectChainProps) => {
const [searchQuery, setSearchQuery] = useState('')
const wallet = useWallet().state.wallet

const walletConnectedChainIds = useAppSelector(selectWalletChainIds)
const walletSupportedChainIds = useAppSelector(selectWalletSupportedChainIds)

const availableChainIds = useMemo(() => {
// If a Ledger is connected, we have the option to add additional chains that are not currently "supported" by the HDWallet
return wallet && isLedger(wallet) ? availableLedgerChainIds : walletSupportedChainIds
}, [wallet, walletSupportedChainIds])
const allAvailableChainIds =
wallet && isLedger(wallet) ? availableLedgerChainIds : walletSupportedChainIds

return allAvailableChainIds.filter(chainId => !walletConnectedChainIds.includes(chainId))
}, [wallet, walletConnectedChainIds, walletSupportedChainIds])

const isSearching = useMemo(() => searchQuery.length > 0, [searchQuery])

Expand Down

0 comments on commit 3a7a892

Please sign in to comment.