Skip to content

Commit

Permalink
feat: honey pot warning for selling token
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Jan 8, 2025
1 parent fb92fc1 commit c8cf45a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
55 changes: 51 additions & 4 deletions src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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')) {
Expand All @@ -95,6 +114,24 @@ export default function ConfirmSwapModalContent({
</Text>
)
}

if (honeypot?.isHoneypot) {
return (
<Text>
This token might be a honeypot token and could be unsellable. Please consult the project team for further
assistance
</Text>
)
}

if (honeypot?.isFOT) {
return (
<Text>
This token has a Fee-on-Transfer. Please increase the slippage to at least {honeypot.tax}% to proceed.
</Text>
)
}

if (
errorWhileBuildRoute.includes('enough') ||
errorWhileBuildRoute.includes('min') ||
Expand All @@ -121,7 +158,7 @@ export default function ConfirmSwapModalContent({
<Trans>There was an issue while trying to confirm your price. Please try to swap again.</Trans>
</Text>
)
}, [errorWhileBuildRoute])
}, [errorWhileBuildRoute, honeypot?.isHoneypot, honeypot?.isFOT, honeypot?.tax])

const priceImpactFromBuild = buildResult?.data
? calculatePriceImpact(Number(buildResult?.data?.amountInUsd || 0), Number(buildResult?.data?.amountOutUsd || 0))
Expand Down Expand Up @@ -245,6 +282,8 @@ export default function ConfirmSwapModalContent({
setShowAreYouSureModal(true)
}

const [searchParams, setSearchParams] = useSearchParams()

return (
<>
<SwapModalAreYouSure
Expand Down Expand Up @@ -320,9 +359,17 @@ export default function ConfirmSwapModalContent({
{errorWhileBuildRoute && <WarningNote shortText={errorText} />}

{errorWhileBuildRoute ? (
<ButtonPrimary onClick={onDismiss}>
<ButtonPrimary
onClick={() => {
if (honeypot?.isFOT) {
searchParams.set('tab', 'settings')
setSearchParams(searchParams)
}
onDismiss()
}}
>
<Text fontSize={14} fontWeight={500} as="span" lineHeight={1}>
<Trans>Dismiss</Trans>
{honeypot?.isFOT ? 'Adjust Settings' : 'Dismiss'}
</Text>
</ButtonPrimary>
) : (
Expand Down
9 changes: 9 additions & 0 deletions src/pages/SwapV3/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit c8cf45a

Please sign in to comment.