From 6a6055044fa095cadd601d897a6d70334a3717ec Mon Sep 17 00:00:00 2001 From: DMY <147dmy@gmail.com> Date: Thu, 19 Dec 2024 14:00:00 +0800 Subject: [PATCH] feat: open 'showMore' after quote refresh for non-auto slippage --- src/ui/views/Swap/Component/Main.tsx | 41 ++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/ui/views/Swap/Component/Main.tsx b/src/ui/views/Swap/Component/Main.tsx index 55c5839b00e..58a3542d860 100644 --- a/src/ui/views/Swap/Component/Main.tsx +++ b/src/ui/views/Swap/Component/Main.tsx @@ -18,7 +18,7 @@ import { useQuoteVisible, useSetQuoteVisible, useSetRefreshId } from '../hooks'; import { DEX_ENUM, DEX_SPENDER_WHITELIST } from '@rabby-wallet/rabby-swap'; import { useDispatch } from 'react-redux'; import { useRbiSource } from '@/ui/utils/ga-event'; -import { useCss } from 'react-use'; +import { useCss, useDebounce } from 'react-use'; import { DEX_WITH_WRAP, KEYRING_CLASS, @@ -393,11 +393,42 @@ export const Main = () => { ] ); - const noQuote = useDebounceValue(noQuoteOrigin, 16); + const noQuote = useDebounceValue(noQuoteOrigin, 10); - if (noQuote && !showMoreOpen) { - setShowMoreOpen(true); - } + useEffect(() => { + if (noQuote) { + setShowMoreOpen(true); + } + }, [noQuote]); + + useDebounce( + () => { + if ( + Number(inputAmount) > 0 && + !inSufficient && + amountAvailable && + !quoteLoading && + !!payToken && + !!receiveToken && + !autoSlippage && + activeProvider + ) { + setShowMoreOpen(true); + } + }, + 10, + [ + inputAmount, + inSufficient, + amountAvailable, + payToken, + receiveToken, + activeProvider, + autoSlippage, + activeProvider, + quoteLoading, + ] + ); return (