From 8aad095cc754f967b0b4174c57916b6d48d993c0 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 7 Feb 2024 15:52:02 +0200 Subject: [PATCH] Add check for minimumRemainingAmount --- .../creatorsStaking/modals/AmountInput.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/creatorsStaking/modals/AmountInput.tsx b/src/components/creatorsStaking/modals/AmountInput.tsx index ea4d6af..fb2c462 100644 --- a/src/components/creatorsStaking/modals/AmountInput.tsx +++ b/src/components/creatorsStaking/modals/AmountInput.tsx @@ -113,6 +113,20 @@ export const StakeOrIncreaseStakeAmountInput = ( setInputError('Amount exceeds available balance') } else if (amountWithDecimals.lte(new BN(0))) { setInputError('Amount must be greater than 0') + } else if ( + minimumRemainingAmount && + new BN(availableBalance.toString()) + .minus(amountWithDecimals) + .lt(minimumRemainingAmount) + ) { + const minimumRemainingAmountWithDecimals = convertToBalanceWithDecimal( + minimumRemainingAmount, + decimals || 0 + ) + + setInputError( + `You must leave at least ${minimumRemainingAmountWithDecimals} SUB in your account` + ) } else { setInputError(undefined) } @@ -165,7 +179,7 @@ export const UnstakeAmountInput = (props: CommonAmountInputProps) => { const amountWithDecimals = balanceWithDecimal(amountValue, decimals || 0) const canUnstake = - locked && + locked && new BN(locked) .minus(amountWithDecimals) .gte(new BN(minimumStakingAmount || 0))