Skip to content

Commit

Permalink
Favor useMemo
Browse files Browse the repository at this point in the history
  • Loading branch information
0xonramp committed Jan 17, 2025
1 parent 7eb1290 commit d5b8126
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/components/smart-trade-button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useWeb3Modal } from '@web3modal/wagmi/react'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useCallback, useMemo } from 'react'

import { Warnings, WarningType } from '@/components/swap/components/warning'
import { useTradeButton } from '@/components/swap/hooks/use-trade-button'
Expand Down Expand Up @@ -100,41 +100,34 @@ export function SmartTradeButton(props: SmartTradeButtonProps) {
buttonLabelOverrides,
)

const [warnings, setWarnings] = useState<WarningType[]>([])

useEffect(() => {
const warnings: WarningType[] = useMemo(() => {
if (
!isTradablePair &&
isRestrictedCountry &&
!hiddenWarnings?.includes(WarningType.restricted)
) {
setWarnings([WarningType.restricted])
return
return [WarningType.restricted]
}
if (
!isTradablePair &&
isUsingVpn &&
!hiddenWarnings?.includes(WarningType.vpn)
) {
setWarnings([WarningType.vpn])
return
return [WarningType.vpn]
}
if (
buttonState === TradeButtonState.signTerms &&
!hiddenWarnings?.includes(WarningType.signTerms)
) {
setWarnings([WarningType.signTerms])
return
return [WarningType.signTerms]
}
if (slippage > 9 && !hiddenWarnings?.includes(WarningType.priceImpact)) {
setWarnings([WarningType.priceImpact])
return
return [WarningType.priceImpact]
}
if (!hiddenWarnings?.includes(WarningType.flashbots)) {
setWarnings([WarningType.flashbots])
return
return [WarningType.flashbots]
}
setWarnings([])
return []
}, [
buttonState,
hiddenWarnings,
Expand Down

0 comments on commit d5b8126

Please sign in to comment.