From d5b8126c015f79490bfcc8952de7bd74f09f7d9e Mon Sep 17 00:00:00 2001 From: 0xonramp <0xonramp@gmail.com> Date: Fri, 17 Jan 2025 13:08:22 -0500 Subject: [PATCH] Favor useMemo --- src/components/smart-trade-button/index.tsx | 23 +++++++-------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/components/smart-trade-button/index.tsx b/src/components/smart-trade-button/index.tsx index a69262883..9643c063a 100644 --- a/src/components/smart-trade-button/index.tsx +++ b/src/components/smart-trade-button/index.tsx @@ -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' @@ -100,41 +100,34 @@ export function SmartTradeButton(props: SmartTradeButtonProps) { buttonLabelOverrides, ) - const [warnings, setWarnings] = useState([]) - - 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,