diff --git a/package.json b/package.json index db175d0d7d..a1dec5bef8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "interbtc-ui", - "version": "2.29.3", + "version": "2.29.5", "private": true, "dependencies": { "@craco/craco": "^6.1.1", diff --git a/src/pages/Staking/index.tsx b/src/pages/Staking/index.tsx index 15914d27ff..fd3582752c 100644 --- a/src/pages/Staking/index.tsx +++ b/src/pages/Staking/index.tsx @@ -106,6 +106,7 @@ interface LockingAmountAndTime { const Staking = (): JSX.Element => { const [blockLockTimeExtension, setBlockLockTimeExtension] = React.useState(0); + const [calculateRewards, setCalculateRewards] = React.useState(false); const dispatch = useDispatch(); const { t } = useTranslation(); @@ -190,7 +191,7 @@ const Staking = (): JSX.Element => { [GENERIC_FETCHER, 'escrow', 'getRewardEstimate', selectedAccountAddress], genericFetcher(), { - enabled: !!bridgeLoaded + enabled: !!bridgeLoaded && calculateRewards } ); useErrorHandler(rewardAmountAndAPYError); @@ -213,7 +214,7 @@ const Staking = (): JSX.Element => { ], genericFetcher(), { - enabled: !!bridgeLoaded + enabled: !!bridgeLoaded && calculateRewards } ); useErrorHandler(estimatedRewardAmountAndAPYError); @@ -320,10 +321,14 @@ const Staking = (): JSX.Element => { React.useEffect(() => { if (!lockTime) return; if (!currentBlockNumber) return; + if (!stakedAmountAndEndBlock) return; const lockTimeValue = Number(lockTime); - setBlockLockTimeExtension(currentBlockNumber + convertWeeksToBlockNumbers(lockTimeValue)); - }, [currentBlockNumber, lockTime]); + const extensionTime = + stakedAmountAndEndBlock.endBlock + currentBlockNumber + convertWeeksToBlockNumbers(lockTimeValue); + + setBlockLockTimeExtension(extensionTime); + }, [currentBlockNumber, lockTime, stakedAmountAndEndBlock]); React.useEffect(() => { reset({ @@ -421,6 +426,8 @@ const Staking = (): JSX.Element => { }; const validateLockingAmount = (value: string): string | undefined => { + setCalculateRewards(false); + const valueWithFallback = value || '0'; const monetaryLockingAmount = newMonetaryAmount(valueWithFallback, GOVERNANCE_TOKEN, true); @@ -435,6 +442,8 @@ const Staking = (): JSX.Element => { return 'Locking amount must not be greater than available balance!'; } + setCalculateRewards(true); + const planckLockingAmount = monetaryLockingAmount.toBig(0); const lockBlocks = convertWeeksToBlockNumbers(parseInt(lockTime)); // This is related to the on-chain implementation where currency values are integers.