From 35c005c0232ef9b3b66d64f50fa9f4589906e99b Mon Sep 17 00:00:00 2001 From: NeOMakinG <14963751+NeOMakinG@users.noreply.github.com> Date: Wed, 4 Dec 2024 01:45:09 +0800 Subject: [PATCH] fix: update trade complete screen (#8240) --- src/assets/translations/en/main.json | 2 +- src/assets/translations/fr/main.json | 2 +- src/components/AnimatedCheck.tsx | 76 ++++++++++++++++ .../MultiHopTradeConfirm.tsx | 18 +++- .../components/TradeSuccess/TradeSuccess.tsx | 87 +++++++++++-------- 5 files changed, 142 insertions(+), 43 deletions(-) create mode 100644 src/components/AnimatedCheck.tsx diff --git a/src/assets/translations/en/main.json b/src/assets/translations/en/main.json index 14e887802a7..f460629804b 100644 --- a/src/assets/translations/en/main.json +++ b/src/assets/translations/en/main.json @@ -994,7 +994,7 @@ "allowanceApprovalTxName": "Allowance approval tx:", "tradeComplete": "You now have %{cryptoAmountFormatted} in your wallet on %{chainName}.", "doAnotherTrade": "Do another trade", - "showDetails": "Show Details", + "summary": "Trade Summary", "transactionSuccessful": "Transaction successful, waiting for confirmations", "temp": { "tradeSuccess": "Trade complete", diff --git a/src/assets/translations/fr/main.json b/src/assets/translations/fr/main.json index 57aade6aca2..e58b895dce2 100644 --- a/src/assets/translations/fr/main.json +++ b/src/assets/translations/fr/main.json @@ -993,7 +993,7 @@ "allowanceApprovalTxName": "Tx. d'autorisation d'allocation :", "tradeComplete": "Vous disposez maintenant de %{cryptoAmountFormatted} dans votre porte-monnaie sur %{chainName}.", "doAnotherTrade": "Faire un autre échange", - "showDetails": "Afficher les détails", + "summary": "Afficher le sommaire", "transactionSuccessful": "Transaction réussie, en attente de confirmations", "temp": { "tradeSuccess": "Échange terminé", diff --git a/src/components/AnimatedCheck.tsx b/src/components/AnimatedCheck.tsx new file mode 100644 index 00000000000..0678f11b342 --- /dev/null +++ b/src/components/AnimatedCheck.tsx @@ -0,0 +1,76 @@ +import type { BoxProps } from '@chakra-ui/react' +import { Box } from '@chakra-ui/react' +import { motion } from 'framer-motion' +import { useMemo } from 'react' + +export const AnimatedCheck = ({ + defaultDuration = 1000, + boxSize = 24, + color = 'green.500', +}: { + defaultDuration?: number + boxSize?: BoxProps['boxSize'] + color?: BoxProps['color'] +}) => { + const placeholderDuration = useMemo(() => defaultDuration / 1000 + 2, [defaultDuration]) + + const draw = useMemo(() => { + const drawDelay = placeholderDuration / 1.5 > 10 ? 5 : placeholderDuration / 1.5 + return { + hidden: { pathLength: 0, opacity: 0 }, + visible: () => ({ + pathLength: 1, + opacity: 1, + transition: { + pathLength: { + delay: drawDelay, + type: 'spring', + duration: 2, + bounce: 0, + }, + opacity: { delay: drawDelay, duration: 2 }, + }, + }), + } + }, [placeholderDuration]) + + const border = useMemo(() => { + return { + hidden: { pathLength: 0 }, + visible: () => ({ + pathLength: 1, + transition: { + pathLength: { + type: 'spring', + duration: placeholderDuration > 10 ? 10 : placeholderDuration, + bounce: 0, + }, + }, + }), + } + }, [placeholderDuration]) + + return ( + + + {/* Outer circle */} + + + {/* Checkmark */} + + + + ) +} diff --git a/src/components/MultiHopTrade/components/MultiHopTradeConfirm/MultiHopTradeConfirm.tsx b/src/components/MultiHopTrade/components/MultiHopTradeConfirm/MultiHopTradeConfirm.tsx index 58f7e8e21d7..b0f0dcfba8a 100644 --- a/src/components/MultiHopTrade/components/MultiHopTradeConfirm/MultiHopTradeConfirm.tsx +++ b/src/components/MultiHopTrade/components/MultiHopTradeConfirm/MultiHopTradeConfirm.tsx @@ -10,9 +10,11 @@ import { TradeSlideTransition } from 'components/MultiHopTrade/TradeSlideTransit import { TradeRoutePaths } from 'components/MultiHopTrade/types' import { Text } from 'components/Text' import { bnOrZero } from 'lib/bignumber/bignumber' +import { fromBaseUnit } from 'lib/math' import { selectActiveQuote, selectConfirmedTradeExecutionState, + selectLastHop, } from 'state/slices/tradeQuoteSlice/selectors' import { tradeQuoteSlice } from 'state/slices/tradeQuoteSlice/tradeQuoteSlice' import { TradeExecutionState } from 'state/slices/tradeQuoteSlice/types' @@ -38,6 +40,7 @@ export const MultiHopTradeConfirm = memo(() => { const [shouldShowWarningAcknowledgement, setShouldShowWarningAcknowledgement] = useState(false) const activeQuote = useAppSelector(selectActiveQuote) const { isModeratePriceImpact, priceImpactPercentage } = usePriceImpact(activeQuote) + const lastHop = useAppSelector(selectLastHop) const initialActiveTradeIdRef = useRef(activeQuote?.id ?? '') @@ -136,15 +139,22 @@ export const MultiHopTradeConfirm = memo(() => { - {isTradeComplete ? ( + {isTradeComplete && activeQuote && lastHop ? ( void children: JSX.Element titleTranslation?: string | [string, InterpolationOptions] - descriptionTranslation?: string | [string, InterpolationOptions] + sellAsset?: Asset + buyAsset?: Asset + sellAmountCryptoPrecision?: string + buyAmountCryptoPrecision?: string } -const pairProps = { showFirst: true } - export const TradeSuccess = ({ handleBack, titleTranslation, - descriptionTranslation, children, + sellAmountCryptoPrecision, + sellAsset, + buyAsset, + buyAmountCryptoPrecision, }: TradeSuccessProps) => { const translate = useTranslate() @@ -42,29 +52,32 @@ export const TradeSuccess = ({ const lastHop = useAppSelector(selectLastHop) - const subText = useMemo(() => { - if (!lastHop) return '' - - const manager = getChainAdapterManager() - const adapter = manager.get(lastHop.buyAsset.chainId) - - if (!adapter) return '' + const AmountsLine = useCallback(() => { + if (!(sellAsset && buyAsset)) return null + if (!(sellAmountCryptoPrecision && buyAmountCryptoPrecision)) return null - const chainName = adapter.getDisplayName() - - if (descriptionTranslation) - return typeof descriptionTranslation === 'string' - ? translate(descriptionTranslation, { - symbol: lastHop.buyAsset.symbol, - chainName, - }) - : translate(...descriptionTranslation) - - return translate('trade.temp.tradeComplete', { - symbol: lastHop.buyAsset.symbol, - chainName, - }) - }, [lastHop, translate, descriptionTranslation]) + return ( + + + + + + + + + + + + ) + }, [sellAsset, buyAsset, sellAmountCryptoPrecision, buyAmountCryptoPrecision]) if (!lastHop) return null @@ -72,13 +85,13 @@ export const TradeSuccess = ({ <> - - - - - {subText} - - + + + + + + + @@ -88,7 +101,7 @@ export const TradeSuccess = ({