From c8cf45abed5bc99bb208e0a8acba683f133cc3a3 Mon Sep 17 00:00:00 2001 From: viet-nv Date: Wed, 8 Jan 2025 11:59:12 +0700 Subject: [PATCH 1/2] feat: honey pot warning for selling token --- .../SwapModal/ConfirmSwapModalContent.tsx | 55 +++++++++++++++++-- src/pages/SwapV3/index.tsx | 9 +++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx b/src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx index 1f79517e32..9a7bca5018 100644 --- a/src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx +++ b/src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx @@ -1,8 +1,9 @@ import { Currency, CurrencyAmount, Price } from '@kyberswap/ks-sdk-core' import { Trans } from '@lingui/macro' import { transparentize } from 'polished' -import { useMemo, useState } from 'react' +import { useEffect, useMemo, useState } from 'react' import { Check, Info } from 'react-feather' +import { useSearchParams } from 'react-router-dom' import { Flex, Text } from 'rebass' import { calculatePriceImpact } from 'services/route/utils' import styled from 'styled-components' @@ -20,8 +21,11 @@ import { BuildRouteResult } from 'components/SwapForm/hooks/useBuildRoute' import { MouseoverTooltip } from 'components/Tooltip' import WarningNote from 'components/WarningNote' import { Dots } from 'components/swapv2/styleds' +import { TOKEN_API_URL } from 'constants/env' +import { useActiveWeb3React } from 'hooks' import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel' import useTheme from 'hooks/useTheme' +import useCurrenciesByPage from 'pages/SwapV3/useCurrenciesByPage' import { useDegenModeManager } from 'state/user/hooks' import { CloseIcon } from 'theme/components' import { minimumAmountAfterSlippage, toCurrencyAmount } from 'utils/currencyAmount' @@ -84,6 +88,21 @@ export default function ConfirmSwapModalContent({ const shouldDisableConfirmButton = isBuildingRoute || !!errorWhileBuildRoute + const { currencyIn } = useCurrenciesByPage() + const { chainId } = useActiveWeb3React() + const [honeypot, setHoneypot] = useState<{ isHoneypot: boolean; isFOT: boolean; tax: number } | null>(null) + useEffect(() => { + if (!currencyIn?.wrapped.address) return + console.log('xxx') + fetch( + `${TOKEN_API_URL}/v1/public/tokens/honeypot-fot-info?address=${currencyIn.wrapped.address.toLowerCase()}&chainId=${chainId}`, + ) + .then(res => res.json()) + .then(res => { + setHoneypot(res.data) + }) + }, [currencyIn?.wrapped.address, chainId]) + const errorText = useMemo(() => { if (!errorWhileBuildRoute) return if (errorWhileBuildRoute.toLowerCase().includes('permit')) { @@ -95,6 +114,24 @@ export default function ConfirmSwapModalContent({ ) } + + if (honeypot?.isHoneypot) { + return ( + + This token might be a honeypot token and could be unsellable. Please consult the project team for further + assistance + + ) + } + + if (honeypot?.isFOT) { + return ( + + This token has a Fee-on-Transfer. Please increase the slippage to at least {honeypot.tax}% to proceed. + + ) + } + if ( errorWhileBuildRoute.includes('enough') || errorWhileBuildRoute.includes('min') || @@ -121,7 +158,7 @@ export default function ConfirmSwapModalContent({ There was an issue while trying to confirm your price. Please try to swap again. ) - }, [errorWhileBuildRoute]) + }, [errorWhileBuildRoute, honeypot?.isHoneypot, honeypot?.isFOT, honeypot?.tax]) const priceImpactFromBuild = buildResult?.data ? calculatePriceImpact(Number(buildResult?.data?.amountInUsd || 0), Number(buildResult?.data?.amountOutUsd || 0)) @@ -245,6 +282,8 @@ export default function ConfirmSwapModalContent({ setShowAreYouSureModal(true) } + const [searchParams, setSearchParams] = useSearchParams() + return ( <> } {errorWhileBuildRoute ? ( - + { + if (honeypot?.isFOT) { + searchParams.set('tab', 'settings') + setSearchParams(searchParams) + } + onDismiss() + }} + > - Dismiss + {honeypot?.isFOT ? 'Adjust Settings' : 'Dismiss'} ) : ( diff --git a/src/pages/SwapV3/index.tsx b/src/pages/SwapV3/index.tsx index b02b3f72db..2f544b67ae 100644 --- a/src/pages/SwapV3/index.tsx +++ b/src/pages/SwapV3/index.tsx @@ -141,6 +141,15 @@ export default function Swap() { setActiveTab(getDefaultTab()) }, [getDefaultTab]) + const tabFromUrl = searchParams.get('tab') + useEffect(() => { + if (tabFromUrl === 'settings') { + setActiveTab(TAB.SETTINGS) + searchParams.delete('tab') + setSearchParams(searchParams) + } + }, [tabFromUrl, searchParams, setSearchParams]) + const tradeRouteComposition = useMemo(() => { return getTradeComposition(chainId, routeSummary?.parsedAmountIn, undefined, routeSummary?.route, defaultTokens) }, [chainId, defaultTokens, routeSummary]) From af2d1f824fc43ae6a917825d818e39d7dbe213e2 Mon Sep 17 00:00:00 2001 From: viet-nv Date: Wed, 8 Jan 2025 14:18:21 +0700 Subject: [PATCH 2/2] fix: tax --- src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx b/src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx index 9a7bca5018..c6f4d4ca06 100644 --- a/src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx +++ b/src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx @@ -93,7 +93,6 @@ export default function ConfirmSwapModalContent({ const [honeypot, setHoneypot] = useState<{ isHoneypot: boolean; isFOT: boolean; tax: number } | null>(null) useEffect(() => { if (!currencyIn?.wrapped.address) return - console.log('xxx') fetch( `${TOKEN_API_URL}/v1/public/tokens/honeypot-fot-info?address=${currencyIn.wrapped.address.toLowerCase()}&chainId=${chainId}`, ) @@ -127,7 +126,7 @@ export default function ConfirmSwapModalContent({ if (honeypot?.isFOT) { return ( - This token has a Fee-on-Transfer. Please increase the slippage to at least {honeypot.tax}% to proceed. + This token has a Fee-on-Transfer. Please increase the slippage to at least {honeypot.tax * 100}% to proceed. ) }