Skip to content

Commit

Permalink
feat: disable preview and warn users of unsupported ChainFlip BTC sel…
Browse files Browse the repository at this point in the history
…ls for KK (#8506)
  • Loading branch information
gomesalexandre authored Jan 13, 2025
1 parent 8a3bbbb commit 2d80a02
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/assets/translations/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@
"receiveAddressDescription": "No %{chainName} address found from connected wallet. Manually enter an address",
"disableThorNativeSmartContractReceive": "We've detected that you're sending to a smart contract address on %{chainName}. Due to THORChain limitations, receiving %{nativeAssetSymbol} to a smart contract address is not supported. Please enter another address",
"disableThorTaprootReceive": "We've detected that you're sending to a taproot Bitcoin address. Due to THORChain limitations, receiving BTC to a taproot address is not currently supported. Please enter another address.",
"disableChainflipKeepKeyTaprootReceive": "Due to KeepKey limitations, selling BTC on ChainFlip is not available yet. Please choose another pair, or connect a different wallet.",
"toContinue": "to continue.",
"addressPlaceholder": "%{chainName} address",
"priceImpactWarning": "Due to the size of this trade relative to available liquidity, the expected price impact of this trade is %{priceImpactPercentage}%. Are you sure you want to trade?",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Alert, AlertIcon, Divider, HStack, useMediaQuery } from '@chakra-ui/react'
import { btcAssetId } from '@shapeshiftoss/caip'
import { isEvmChainId } from '@shapeshiftoss/chain-adapters'
import { SwapperName, TradeQuoteError } from '@shapeshiftoss/swapper'
import { bnOrZero, isSome, isUtxoChainId } from '@shapeshiftoss/utils'
Expand All @@ -17,7 +18,7 @@ import { Text } from 'components/Text'
import { useAccountsFetchQuery } from 'context/AppProvider/hooks/useAccountsFetchQuery'
import { useIsSmartContractAddress } from 'hooks/useIsSmartContractAddress/useIsSmartContractAddress'
import { useWallet } from 'hooks/useWallet/useWallet'
import { isToken } from 'lib/utils'
import { isKeepKeyHDWallet, isToken } from 'lib/utils'
import { selectIsTradeQuoteApiQueryPending } from 'state/apis/swapper/selectors'
import { selectFeeAssetById, selectMarketDataUserCurrency } from 'state/slices/selectors'
import {
Expand Down Expand Up @@ -76,7 +77,7 @@ export const ConfirmSummary = ({
const translate = useTranslate()
const [isSmallerThanXl] = useMediaQuery(`(max-width: ${breakpoints.xl})`, { ssr: false })
const {
state: { isConnected, isDemoWallet },
state: { wallet, isConnected, isDemoWallet },
} = useWallet()

const buyAmountAfterFeesCryptoPrecision = useAppSelector(selectBuyAmountAfterFeesCryptoPrecision)
Expand Down Expand Up @@ -187,8 +188,20 @@ export const ConfirmSummary = ({
isWalletReceiveAddressLoading,
})

// Taproot sends are unsupported for KeepKey, and Chainflip uses Taproot address for BTC sells.
const isUnsupportedKeepKeyP2TrTx = useMemo(() => {
return (
wallet &&
sellAsset?.assetId === btcAssetId &&
isKeepKeyHDWallet(wallet) &&
activeSwapperName === SwapperName.Chainflip
)
}, [activeSwapperName, sellAsset?.assetId, wallet])

const shouldDisablePreviewButton = useMemo(() => {
return (
// No dice for KK BTC sends
isUnsupportedKeepKeyP2TrTx ||
// don't execute trades while address is validating
isManualReceiveAddressRequired ||
isManualReceiveAddressValidating ||
Expand All @@ -207,6 +220,7 @@ export const ConfirmSummary = ({
isTradeQuoteApiQueryPending[activeSwapperName]
)
}, [
isUnsupportedKeepKeyP2TrTx,
isManualReceiveAddressRequired,
isManualReceiveAddressValidating,
isManualReceiveAddressEditing,
Expand Down Expand Up @@ -285,6 +299,25 @@ export const ConfirmSummary = ({
]
}, [buyAsset, buyAssetFeeAsset, sellAsset])

const maybeWarning = useMemo(() => {
if (nativeAssetBridgeWarning)
return (
<Alert status='info' borderRadius='lg'>
<AlertIcon />
<Text translation={nativeAssetBridgeWarning} />
</Alert>
)
if (isUnsupportedKeepKeyP2TrTx)
return (
<Alert status='info' borderRadius='lg'>
<AlertIcon />
<Text translation='trade.disableChainflipKeepKeyTaprootReceive' />
</Alert>
)

return null
}, [isUnsupportedKeepKeyP2TrTx, nativeAssetBridgeWarning])

const manualAddressEntryDescription = useMemo(() => {
if (shouldDisableThorNativeSmartContractReceive)
return translate('trade.shouldDisableThorNativeSmartContractReceive', {
Expand Down Expand Up @@ -395,14 +428,7 @@ export const ConfirmSummary = ({
networkFeeFiatUserCurrency={totalNetworkFeeFiatPrecision}
>
<>
{nativeAssetBridgeWarning ? (
<Alert status='info' borderRadius='lg'>
<AlertIcon />
<Text translation={nativeAssetBridgeWarning} />
</Alert>
) : (
<></>
)}
{maybeWarning}
<RecipientAddress
shouldForceManualAddressEntry={shouldDisableThorNativeSmartContractReceive}
recipientAddressDescription={
Expand Down

0 comments on commit 2d80a02

Please sign in to comment.