Skip to content

Commit

Permalink
feat: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Aug 16, 2024
1 parent d48852b commit 1d7c47f
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { parseAddressInputWithChainId } from 'lib/address/address'
import { selectAccountIdsByAssetId } from 'state/slices/selectors'
import { selectInputBuyAsset } from 'state/slices/tradeInputSlice/selectors'
import { tradeInput } from 'state/slices/tradeInputSlice/tradeInputSlice'
import { selectActiveQuote } from 'state/slices/tradeQuoteSlice/selectors'
import { useAppDispatch, useAppSelector } from 'state/store'

type ManualAddressEntryProps = {
Expand Down Expand Up @@ -46,33 +45,32 @@ export const ManualAddressEntry: FC<ManualAddressEntryProps> = memo(

const isSnapInstalled = useIsSnapInstalled()
const walletSupportsBuyAssetChain = useWalletSupportsChain(buyAssetChainId, wallet)
const activeQuote = useAppSelector(selectActiveQuote)
const buyAssetAccountIds = useAppSelector(state =>
selectAccountIdsByAssetId(state, { assetId: buyAssetAssetId }),
)
const useReceiveAddressArgs = useMemo(
() => ({
fetchUnchainedAddress: Boolean(wallet && isLedger(wallet)),
}),
[wallet],
)
const { manualReceiveAddress } = useReceiveAddress(useReceiveAddressArgs)

const shouldShowManualReceiveAddressInput = useMemo(() => {
if (shouldForceManualAddressEntry) return true
if (manualReceiveAddress) return false
// Ledger "supports" all chains, but may not have them connected
if (wallet && isLedger(wallet)) return !buyAssetAccountIds.length && !activeQuote
// We want to display the manual address entry if the wallet doesn't support the buy asset chain,
// but stop displaying it as soon as we have a quote
return !walletSupportsBuyAssetChain && !activeQuote
if (wallet && isLedger(wallet)) return !buyAssetAccountIds.length
// We want to display the manual address entry if the wallet doesn't support the buy asset chain
return !walletSupportsBuyAssetChain
}, [
activeQuote,
buyAssetAccountIds.length,
manualReceiveAddress,
wallet,
walletSupportsBuyAssetChain,
shouldForceManualAddressEntry,
])

const useReceiveAddressArgs = useMemo(
() => ({
fetchUnchainedAddress: Boolean(wallet && isLedger(wallet)),
}),
[wallet],
)
const { manualReceiveAddress } = useReceiveAddress(useReceiveAddressArgs)

const chainAdapterManager = getChainAdapterManager()
const buyAssetChainName = chainAdapterManager.get(buyAssetChainId)?.getDisplayName()

Expand Down

0 comments on commit 1d7c47f

Please sign in to comment.