From 563fe953207a4c4fe225fe1c0a033c349caac451 Mon Sep 17 00:00:00 2001 From: hotequil Date: Wed, 18 Dec 2024 11:24:40 -0300 Subject: [PATCH] CU-86a5xwkrj-NEON3 - Swap Request - Implement a Clear Form button --- .../src/components/GreyAccountSelect.tsx | 2 +- .../src/components/GreyAmountInput.tsx | 2 +- src/renderer/src/locales/en/pages.json | 3 +- .../src/routes/pages/Swap/SwapPageContent.tsx | 44 +++++++++++++++---- src/shared/@types/i18next-resources.d.ts | 1 + 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/renderer/src/components/GreyAccountSelect.tsx b/src/renderer/src/components/GreyAccountSelect.tsx index c385b980..fa389142 100644 --- a/src/renderer/src/components/GreyAccountSelect.tsx +++ b/src/renderer/src/components/GreyAccountSelect.tsx @@ -57,7 +57,7 @@ export const GreyAccountSelect = ({ } return ( - + {children ? ( {children} diff --git a/src/renderer/src/components/GreyAmountInput.tsx b/src/renderer/src/components/GreyAmountInput.tsx index 13e199f3..0ee53c0a 100644 --- a/src/renderer/src/components/GreyAmountInput.tsx +++ b/src/renderer/src/components/GreyAmountInput.tsx @@ -19,7 +19,7 @@ export const GreyAmountInput = ({ onChange, value, disabled, loading, className, return (
[]> +} + +type TActionsData = { selectedTokenToUse: SwapServiceLoadableValue> selectedAccountToUse: SwapServiceValidateValue selectedAmountToUse: SwapServiceLoadableValue @@ -88,9 +91,12 @@ export const SwapPageContent = ({ account }: TProps) => { }) ) + const { actionData: staticActionData, setData: setStaticData } = useActions({ + availableTokensToUse: { loading: true, value: [] }, + }) + const { actionData, actionState, setData, setError, clearErrors, reset, handleAct } = useActions( { - availableTokensToUse: { loading: true, value: null }, selectedTokenToUse: { loading: false, value: null }, selectedAccountToUse: { loading: false, value: null, valid: null }, selectedAmountToUse: { loading: false, value: null }, @@ -177,6 +183,16 @@ export const SwapPageContent = ({ account }: TProps) => { swapServiceRef.current.setAmountToUse(amount) } + const handleResetForm = () => { + swapServiceRef.current.setTokenToUse(null) + swapServiceRef.current.setAccountToUse(null) + swapServiceRef.current.setAmountToUse(null) + swapServiceRef.current.setTokenToReceive(null) + swapServiceRef.current.setAddressToReceive(null) + + reset() + } + const handleSubmit = async () => { if ( !swapServiceRef.current || @@ -234,7 +250,7 @@ export const SwapPageContent = ({ account }: TProps) => { const swapService = swapServiceRef.current swapService.eventEmitter.on('availableTokensToUse', availableTokensToUse => { - setData({ availableTokensToUse }) + setStaticData({ availableTokensToUse }) }) swapService.eventEmitter.on('tokenToUse', tokenToUse => { @@ -278,7 +294,7 @@ export const SwapPageContent = ({ account }: TProps) => { return () => { swapService.eventEmitter.removeAllListeners() } - }, [accountsRef, setData]) + }, [accountsRef, setData, setStaticData]) useEffect(() => { if (balanceQuery.isLoading) return @@ -437,7 +453,17 @@ export const SwapPageContent = ({ account }: TProps) => {
-

{t('form.title')}

+
+

{t('form.title')}

+ +
@@ -452,8 +478,8 @@ export const SwapPageContent = ({ account }: TProps) => { leftIcon={} > { ? [actionData.selectedTokenToUse.value.blockchain] : (Object.keys(swapChainsByServiceName) as TBlockchainServiceKey[]) } - loading={actionData.availableTokensToUse.loading} + loading={staticActionData.availableTokensToUse.loading} /> diff --git a/src/shared/@types/i18next-resources.d.ts b/src/shared/@types/i18next-resources.d.ts index 429770aa..2b4fed29 100644 --- a/src/shared/@types/i18next-resources.d.ts +++ b/src/shared/@types/i18next-resources.d.ts @@ -1217,6 +1217,7 @@ interface Resources { } form: { title: 'What tokens do you want to swap?' + restart: 'Restart' swapFromTitle: 'Swap this...' swapToTitle: 'For this...' balanceLabel: 'Balance'