diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c365d8e0..e005413be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.7.2 + +### Fixed + +- Allow validators to change restaking preference while below minimum threshold + ## 1.7.1 ### Changed diff --git a/app/package.json b/app/package.json index 12054e42f..bc00e9b12 100644 --- a/app/package.json +++ b/app/package.json @@ -2,7 +2,7 @@ "name": "concordium-desktop-wallet", "productName": "concordium-desktop-wallet", "description": "concordium-desktop-wallet", - "version": "1.7.1", + "version": "1.7.2", "main": "./main.prod.js", "author": { "name": "Concordium Software", diff --git a/app/utils/transactionHelpers.ts b/app/utils/transactionHelpers.ts index f5d7426a6..8e39ed176 100644 --- a/app/utils/transactionHelpers.ts +++ b/app/utils/transactionHelpers.ts @@ -4,6 +4,7 @@ import { ReleaseSchedule, TransactionSummaryType, TransactionKindString, + isBakerAccount, } from '@concordium/web-sdk'; import { Validate } from 'react-hook-form'; import { @@ -682,7 +683,16 @@ export function validateBakerStake( return 'Value is not a valid CCD amount'; } const amount = ccdToMicroCcd(amountToValidate); - if (bakerStakeThreshold && bakerStakeThreshold > amount) { + const currentStake: bigint | undefined = + accountInfo && isBakerAccount(accountInfo) + ? accountInfo.accountBaker.stakedAmount + : undefined; + + if ( + bakerStakeThreshold && + bakerStakeThreshold > amount && + (!currentStake || amount !== currentStake) + ) { return `Stake is below the threshold (${displayAsCcd( bakerStakeThreshold )}) for validation`; diff --git a/test/utils/transactionHelpers.test.ts b/test/utils/transactionHelpers.test.ts index d8e8a3e0e..ded555569 100644 --- a/test/utils/transactionHelpers.test.ts +++ b/test/utils/transactionHelpers.test.ts @@ -1,5 +1,9 @@ import '../mockWindow'; -import { createRegularIntervalSchedule } from '../../app/utils/transactionHelpers'; +import { AccountInfo } from '@concordium/web-sdk'; +import { + createRegularIntervalSchedule, + validateBakerStake, +} from '../../app/utils/transactionHelpers'; test('createRegularIntervalSchedule release amounts should sum to input amount', () => { const totalAmount = 100n; @@ -44,3 +48,45 @@ test('createRegularIntervalSchedule should increase timestamps by interval', () ) ).toEqual(true); }); + +test('validateBakerStake allows amount below threshold (if equal to currentStake)', () => { + const stakedAmount = 1000000n; // microCCD (1 CCD) + const accountAmount = 1000000000n; // microCCD (1000 CCD) + const accountInfo = { + accountAmount, + accountBaker: { stakedAmount }, + } as AccountInfo; + const threshold = 100000000n; // microCCD (100 CCD) + const amount = '1'; // CCD + expect( + validateBakerStake(threshold, amount, accountInfo, 1n) + ).toBeUndefined(); +}); + +test('validateBakerStake does not allow amount below threshold (if not equal to currentStake)', () => { + const stakedAmount = 1000000n; // microCCD (1 CCD) + const accountAmount = 1000000000n; // microCCD (1000 CCD) + const accountInfo = { + accountAmount, + accountBaker: { stakedAmount }, + } as AccountInfo; + const threshold = 100000000n; // microCCD (100 CCD) + const amount = '5'; // CCD + expect(validateBakerStake(threshold, amount, accountInfo, 1n)).toContain( + 'below the threshold' + ); +}); + +test('validateBakerStake allows amount equal threshold', () => { + const stakedAmount = 1000000n; // microCCD (1 CCD) + const accountAmount = 1000000000n; // microCCD (1000 CCD) + const accountInfo = { + accountAmount, + accountBaker: { stakedAmount }, + } as AccountInfo; + const threshold = 100000000n; // microCCD (100 CCD) + const amount = '100'; // CCD + expect( + validateBakerStake(threshold, amount, accountInfo, 1n) + ).toBeUndefined(); +});