From 688f16fc7d657b2183bf165261498aed35502c96 Mon Sep 17 00:00:00 2001 From: Yaki Date: Fri, 9 Feb 2024 16:08:27 -0800 Subject: [PATCH 1/4] Refactor disableClaiming logic in Staking component --- src/routes/staking.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/staking.tsx b/src/routes/staking.tsx index c891f77..9393bcf 100644 --- a/src/routes/staking.tsx +++ b/src/routes/staking.tsx @@ -184,8 +184,8 @@ const Staking = () => { const [userStakedInfoMap, setUserStakedInfoMap] = useState>(new Map()); const disableClaiming = useMemo(() => { - return isWaiting || unclaimedEras.total === 0 && totalUnclaimed.toNumber() === 0; - }, [isWaiting, unclaimedEras, totalUnclaimed]); + return isWaiting || unclaimedEras.total === 0; + }, [isWaiting, unclaimedEras]); const [rewardsUserClaimedQuery, reexecuteQuery] = useQuery({ query: TotalRewardsClaimedQuery, @@ -443,9 +443,9 @@ const Staking = () => { reexecuteQuery({ requestPolicy: 'network-only' }); setClaimAllSuccess(false); }, [claimAllSuccess, reexecuteQuery]); - + console.log('disableClaiming', disableClaiming); const handleClaimRewards = useCallback(async () => { - if (!selectedAccount || !unclaimedEras || !currentStakingEra) return; + if (disableClaiming || !selectedAccount || !unclaimedEras || !currentStakingEra) return; await restakeClaim({ api, From 6f70eb88242d97c54e3d895dcec3546e14443808 Mon Sep 17 00:00:00 2001 From: Yaki Date: Fri, 9 Feb 2024 16:09:25 -0800 Subject: [PATCH 2/4] Remove unnecessary console.log statement --- src/routes/staking.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/staking.tsx b/src/routes/staking.tsx index 9393bcf..d332a5f 100644 --- a/src/routes/staking.tsx +++ b/src/routes/staking.tsx @@ -443,7 +443,7 @@ const Staking = () => { reexecuteQuery({ requestPolicy: 'network-only' }); setClaimAllSuccess(false); }, [claimAllSuccess, reexecuteQuery]); - console.log('disableClaiming', disableClaiming); + const handleClaimRewards = useCallback(async () => { if (disableClaiming || !selectedAccount || !unclaimedEras || !currentStakingEra) return; From 2f560d316e14621605f6a4f821704386b19e47e3 Mon Sep 17 00:00:00 2001 From: Yaki Date: Fri, 9 Feb 2024 16:29:24 -0800 Subject: [PATCH 3/4] Fix condition for setting total claimed and total unclaimed --- src/routes/staking.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/staking.tsx b/src/routes/staking.tsx index d332a5f..9a22ff7 100644 --- a/src/routes/staking.tsx +++ b/src/routes/staking.tsx @@ -511,7 +511,7 @@ const Staking = () => { useEffect(() => { if (rewardsUserClaimedQuery.fetching || !selectedAccount) return; - if (!rewardsUserClaimedQuery.data?.stakers?.length) { + if (!rewardsUserClaimedQuery.data?.stakers?.length || claimAllSuccess) { setTotalClaimed(new BigNumber(0)); setTotalUnclaimed(new BigNumber(0)); return; From e835f3f39a70494a0b6cc159c9916c4c266f119e Mon Sep 17 00:00:00 2001 From: Yaki Date: Fri, 9 Feb 2024 16:50:35 -0800 Subject: [PATCH 4/4] Refactor rewards calculation in Staking component --- src/routes/staking.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/staking.tsx b/src/routes/staking.tsx index 9a22ff7..0c9c369 100644 --- a/src/routes/staking.tsx +++ b/src/routes/staking.tsx @@ -511,7 +511,7 @@ const Staking = () => { useEffect(() => { if (rewardsUserClaimedQuery.fetching || !selectedAccount) return; - if (!rewardsUserClaimedQuery.data?.stakers?.length || claimAllSuccess) { + if (!rewardsUserClaimedQuery.data?.stakers?.length) { setTotalClaimed(new BigNumber(0)); setTotalUnclaimed(new BigNumber(0)); return; @@ -526,7 +526,7 @@ const Staking = () => { rewardsUserClaimedQuery.data.stakers[0].totalUnclaimed ); setTotalUnclaimed(totalUnclaimed); - }, [rewardsUserClaimedQuery, selectedAccount, rewardsUserClaimedQuery.fetching, rewardsUserClaimedQuery.data, claimAllSuccess]); + }, [rewardsUserClaimedQuery, selectedAccount, rewardsUserClaimedQuery.fetching, rewardsUserClaimedQuery.data]); return (