From 9bef22e2247efae140f3a4bfd5aaf408b3d10596 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 19 Dec 2024 18:59:31 +0300 Subject: [PATCH] fix: limit orders display buy amount (#8420) --- src/assets/translations/en/main.json | 2 +- .../components/LimitOrderBuyAsset.tsx | 110 +++++++----------- .../LimitOrder/components/LimitOrderInput.tsx | 1 + .../slices/limitOrderInputSlice/selectors.ts | 18 ++- 4 files changed, 61 insertions(+), 70 deletions(-) diff --git a/src/assets/translations/en/main.json b/src/assets/translations/en/main.json index 91afe7db5cb..189acd37dc9 100644 --- a/src/assets/translations/en/main.json +++ b/src/assets/translations/en/main.json @@ -1059,7 +1059,7 @@ "confirmInfo": "The limit order may not fill exactly when on-chain prices reach the limit price.", "learnMore": "Learn More", "previewOrder": "Preview Order", - "youGet": "You Get", + "youGet": "You get at least", "whenPriceReaches": "When price reaches", "expiry": "Expiry", "noOpenOrders": "No open orders yet.", diff --git a/src/components/MultiHopTrade/components/LimitOrder/components/LimitOrderBuyAsset.tsx b/src/components/MultiHopTrade/components/LimitOrder/components/LimitOrderBuyAsset.tsx index 38cfdffb531..fa5511c3943 100644 --- a/src/components/MultiHopTrade/components/LimitOrder/components/LimitOrderBuyAsset.tsx +++ b/src/components/MultiHopTrade/components/LimitOrder/components/LimitOrderBuyAsset.tsx @@ -1,35 +1,32 @@ -import { Flex, FormLabel, Stack } from '@chakra-ui/react' import type { AccountId, ChainId } from '@shapeshiftoss/caip' import type { Asset } from '@shapeshiftoss/types' -import { bnOrZero } from '@shapeshiftoss/utils' import React, { memo, useCallback, useMemo } from 'react' import { useTranslate } from 'react-polyglot' import type { AccountDropdownProps } from 'components/AccountDropdown/AccountDropdown' -import { AccountDropdown } from 'components/AccountDropdown/AccountDropdown' import { TradeAssetSelect } from 'components/AssetSelection/AssetSelection' -import { Balance } from 'components/DeFi/components/Balance' -import { Text } from 'components/Text' import { useModal } from 'hooks/useModal/useModal' +import { positiveOrZero } from 'lib/bignumber/bignumber' import { - selectMarketDataByAssetIdUserCurrency, - selectPortfolioCryptoPrecisionBalanceByFilter, -} from 'state/slices/selectors' + selectBuyAmountCryptoPrecision, + selectBuyAmountUserCurrency, + selectManualReceiveAddress, +} from 'state/slices/limitOrderInputSlice/selectors' import { useAppSelector } from 'state/store' +import { TradeAssetInput } from '../../TradeAssetInput' + export type TradeAmountInputFormValues = { amountFieldInput: string amountCryptoPrecision: string amountUserCurrency: string } -const buttonProps = { - variant: 'unstyled', - display: 'flex', - height: 'auto', - lineHeight: '1', - width: '100%', +const emptyPercentOptions: number[] = [] +const formControlProps = { + borderRadius: 0, + background: 'transparent', + borderWidth: 0, } -const boxProps = { px: 0, m: 0, maxWidth: '220px' } export type LimitOrderBuyAssetProps = { asset: Asset @@ -39,13 +36,14 @@ export type LimitOrderBuyAssetProps = { chainIdFilterPredicate: (chainId: ChainId) => boolean onAccountIdChange: AccountDropdownProps['onChange'] onSetBuyAsset: (asset: Asset) => void + isLoading: boolean } export const LimitOrderBuyAsset: React.FC = memo( ({ asset, + isLoading, accountId, - isInputtingFiatSellAmount, assetFilterPredicate, chainIdFilterPredicate, onAccountIdChange, @@ -54,36 +52,10 @@ export const LimitOrderBuyAsset: React.FC = memo( const translate = useTranslate() const buyAssetSearch = useModal('buyTradeAssetSearch') - const marketData = useAppSelector(state => - selectMarketDataByAssetIdUserCurrency(state, asset.assetId), - ) - - const filter = useMemo( - () => ({ - accountId: accountId ?? '', - assetId: asset.assetId, - }), - [accountId, asset], - ) - const balance = useAppSelector(state => - selectPortfolioCryptoPrecisionBalanceByFilter(state, filter), - ) - - const fiatBalance = bnOrZero(balance).times(marketData.price).toString() + const buyAmountCryptoPrecision = useAppSelector(selectBuyAmountCryptoPrecision) + const buyAmountUserCurrency = useAppSelector(selectBuyAmountUserCurrency) - const accountDropdownLabel = useMemo( - () => ( - - ), - [asset, balance, fiatBalance, isInputtingFiatSellAmount, translate], - ) + const manualReceiveAddress = useAppSelector(selectManualReceiveAddress) const handleAssetClick = useCallback(() => { buyAssetSearch.open({ @@ -94,35 +66,37 @@ export const LimitOrderBuyAsset: React.FC = memo( }) }, [assetFilterPredicate, buyAssetSearch, chainIdFilterPredicate, onSetBuyAsset]) - return ( - - - - - - - - {balance && ( - - )} - + const tradeAssetSelect = useMemo( + () => ( - + ), + [asset.assetId, handleAssetClick, onSetBuyAsset], + ) + + return ( + ) }, ) diff --git a/src/components/MultiHopTrade/components/LimitOrder/components/LimitOrderInput.tsx b/src/components/MultiHopTrade/components/LimitOrder/components/LimitOrderInput.tsx index 815f0f9f3fe..463218eac98 100644 --- a/src/components/MultiHopTrade/components/LimitOrder/components/LimitOrderInput.tsx +++ b/src/components/MultiHopTrade/components/LimitOrder/components/LimitOrderInput.tsx @@ -410,6 +410,7 @@ export const LimitOrderInput = ({ > fromBaseUnit(buyAmountCryptoBaseUnit, buyAsset.precision), +) + +export const selectBuyAmountUserCurrency = createSelector( + selectBuyAmountCryptoPrecision, + selectInputBuyAssetUserCurrencyRate, + (buyAmountCryptoPrecision, buyAssetUserCurrencyRate) => { + return bn(buyAmountCryptoPrecision) + .times(buyAssetUserCurrencyRate ?? '0') + .toFixed(2) + }, +)