From b43d8ca1d46091a5bcf105d11ffa1da1ea2abd45 Mon Sep 17 00:00:00 2001 From: Thomas Jeatt Date: Tue, 25 Apr 2023 11:47:22 +0100 Subject: [PATCH 1/2] fix: prevent api call being made when form is in an error state --- src/pages/Staking/index.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pages/Staking/index.tsx b/src/pages/Staking/index.tsx index 6a5a41770b..a90b70e678 100644 --- a/src/pages/Staking/index.tsx +++ b/src/pages/Staking/index.tsx @@ -124,7 +124,7 @@ const Staking = (): JSX.Element => { handleSubmit, watch, reset, - formState: { errors }, + formState: { errors, isDirty, isValid }, trigger, setValue } = useForm({ @@ -200,7 +200,8 @@ const Staking = (): JSX.Element => { isIdle: estimatedRewardAmountAndAPYIdle, isLoading: estimatedRewardAmountAndAPYLoading, data: estimatedRewardAmountAndAPY, - error: estimatedRewardAmountAndAPYError + error: estimatedRewardAmountAndAPYError, + refetch: estimatedRewardAmountAndAPYRefetch } = useQuery( [ GENERIC_FETCHER, @@ -212,11 +213,16 @@ const Staking = (): JSX.Element => { ], genericFetcher(), { - enabled: !!bridgeLoaded + enabled: false, + retry: false } ); useErrorHandler(estimatedRewardAmountAndAPYError); + if (isValid || !isDirty) { + estimatedRewardAmountAndAPYRefetch(); + } + const { isIdle: stakedAmountAndEndBlockIdle, isLoading: stakedAmountAndEndBlockLoading, @@ -851,7 +857,7 @@ const Staking = (): JSX.Element => { fullWidth size='large' type='submit' - disabled={initializing || unlockFirst} + disabled={initializing || unlockFirst || !isValid} loading={initialStakeMutation.isLoading || moreStakeMutation.isLoading} > {submitButtonLabel}{' '} From 3cb97e14b4896782a5e10eb1d45eb6ddfb6d0ac9 Mon Sep 17 00:00:00 2001 From: Thomas Jeatt Date: Tue, 25 Apr 2023 11:51:23 +0100 Subject: [PATCH 2/2] chore: add TODO --- src/pages/Staking/index.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/Staking/index.tsx b/src/pages/Staking/index.tsx index a90b70e678..820f011322 100644 --- a/src/pages/Staking/index.tsx +++ b/src/pages/Staking/index.tsx @@ -219,6 +219,9 @@ const Staking = (): JSX.Element => { ); useErrorHandler(estimatedRewardAmountAndAPYError); + // MEMO: This is being set outside of a useEffect because of + // an race condition. This is a underlying issue with the + // component and can't be easily fixed. if (isValid || !isDirty) { estimatedRewardAmountAndAPYRefetch(); }