From bea3425dd33ef6a0e6516a6692e78ec3cb9d56fb Mon Sep 17 00:00:00 2001 From: Danh Date: Fri, 27 Oct 2023 11:05:37 +0700 Subject: [PATCH] update gas fee note --- src/components/SwapForm/GasPriceNote.tsx | 41 ++++++++++++++++-------- src/components/SwapForm/index.tsx | 11 ++++--- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/components/SwapForm/GasPriceNote.tsx b/src/components/SwapForm/GasPriceNote.tsx index d2a22dbf6e..db227fa227 100644 --- a/src/components/SwapForm/GasPriceNote.tsx +++ b/src/components/SwapForm/GasPriceNote.tsx @@ -1,41 +1,54 @@ import { ChainId } from '@kyberswap/ks-sdk-core' -import { Trans, t } from '@lingui/macro' +import { Trans } from '@lingui/macro' import { FC } from 'react' import { Text } from 'rebass' +import PriceImpactNote from 'components/SwapForm/PriceImpactNote' import WarningNote from 'components/WarningNote' import { useActiveWeb3React } from 'hooks' import useTheme from 'hooks/useTheme' import { useSwitchPairToLimitOrder } from 'state/swap/hooks' +import { checkPriceImpact } from 'utils/prices' type Props = { gasUsd?: string + priceImpact?: number + isDegenMode: boolean } const GAS_USD_THRESHOLD = 20 -const GasPriceNote: FC = ({ gasUsd = 0 }) => { +const GasFeeAndPriceImpactNote: FC = ({ gasUsd = 0, priceImpact, isDegenMode }) => { const theme = useTheme() - const { chainId } = useActiveWeb3React() const switchToLimitOrder = useSwitchPairToLimitOrder() - if (+gasUsd < GAS_USD_THRESHOLD || chainId !== ChainId.MAINNET) return null + const { isHigh, isVeryHigh } = checkPriceImpact(priceImpact) + + if (+gasUsd < GAS_USD_THRESHOLD || chainId !== ChainId.MAINNET) + return + const limitOrderLink = ( + + Do you want to make a{' '} + + Limit Order + {' '} + instead? + + ) return ( - - Do you want to make a{' '} - - Limit Order - {' '} - instead? - + {isHigh || isVeryHigh ? ( + Gas fees and Price Impact are very high. You will lose your funds. + ) : ( + Gas fees is very high. You will lose your funds. + )}{' '} + {limitOrderLink} } /> ) } -export default GasPriceNote +export default GasFeeAndPriceImpactNote diff --git a/src/components/SwapForm/index.tsx b/src/components/SwapForm/index.tsx index ead77a20ae..cf2b33be39 100644 --- a/src/components/SwapForm/index.tsx +++ b/src/components/SwapForm/index.tsx @@ -13,7 +13,7 @@ import AddressInputPanel from 'components/AddressInputPanel' import { Clock } from 'components/Icons' import { AutoRow } from 'components/Row' import SlippageWarningNote from 'components/SlippageWarningNote' -import GasPriceNote from 'components/SwapForm/GasPriceNote' +import GasFeeAndPriceImpactNote from 'components/SwapForm/GasPriceNote' import InputCurrencyPanel from 'components/SwapForm/InputCurrencyPanel' import OutputCurrencyPanel from 'components/SwapForm/OutputCurrencyPanel' import SlippageSettingGroup from 'components/SwapForm/SlippageSettingGroup' @@ -37,7 +37,6 @@ import { MEDIA_WIDTHS } from 'theme' import { DetailedRouteSummary } from 'types/route' import { currencyId } from 'utils/currencyId' -import PriceImpactNote from './PriceImpactNote' import RefreshButton from './RefreshButton' import ReverseTokenSelectionButton from './ReverseTokenSelectionButton' import SwapActionButton from './SwapActionButton' @@ -260,9 +259,11 @@ const SwapForm: React.FC = props => { {!isWrapOrUnwrap && } - - - +