From 32a9edada9b9bc00f68274b13559a1102e3f42d6 Mon Sep 17 00:00:00 2001 From: Nuno Cunha <34559473+nuno-aac@users.noreply.github.com> Date: Wed, 18 May 2022 15:46:07 +0100 Subject: [PATCH] Fix uncleared form on submit (#161) --- packages/web/src/components/dashboard/sale-form.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/web/src/components/dashboard/sale-form.tsx b/packages/web/src/components/dashboard/sale-form.tsx index 64bf52db..e92aa082 100644 --- a/packages/web/src/components/dashboard/sale-form.tsx +++ b/packages/web/src/components/dashboard/sale-form.tsx @@ -15,7 +15,7 @@ import { media } from 'src/styles/breakpoints'; import { useFractalKYCUrl } from 'src/hooks/use-kyc-url'; import { useSaleBuy } from 'src/hooks/use-sale'; import BigNumber from 'bignumber.js'; -import React, { useCallback, useMemo, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import styled from 'styled-components'; /** @@ -98,7 +98,7 @@ function getFieldError(amount: string) { export function SaleForm(props: Props) { const [amount, setAmount] = useState(''); const { disabled, tokenPrice } = props; - const { isPending, run: buy } = useSaleBuy(); + const { isPending, isResolved, run: buy } = useSaleBuy(); const fieldError = getFieldError(amount); const kycUrl = useFractalKYCUrl(); const handleOnChange = useCallback(event => { @@ -112,6 +112,12 @@ export function SaleForm(props: Props) { .toString(); }, [amount, tokenPrice]); + useEffect(() => { + if (isResolved) { + setAmount(''); + } + }, [isResolved]); + return ( {disabled && (