Skip to content

Commit

Permalink
Merge pull request #5140 from leather-wallet/fix/send-stx-validation-msg
Browse files Browse the repository at this point in the history
fix: wrong send stx validation msg
  • Loading branch information
fbwoolf authored Mar 27, 2024
2 parents caae144 + 926a90b commit 33aae7a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/common/validation/forms/amount-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ export function btcMinimumSpendValidator() {
});
}

export function stxAmountValidator() {
export function stxAmountValidator(availableStxBalance: Money) {
return yup
.number()
.typeError(FormErrorMessages.MustBeNumber)
.concat(currencyAmountValidator())
.concat(stxAmountPrecisionValidator(formatPrecisionError()));
.concat(stxAmountPrecisionValidator(formatPrecisionError(availableStxBalance)));
}

export function stxAvailableBalanceValidator(availableBalance: Money) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export function useStxSendForm() {
stxFees,

validationSchema: yup.object({
amount: stxAmountValidator().concat(stxAvailableBalanceValidator(availableStxBalance)),
amount: stxAmountValidator(availableStxBalance).concat(
stxAvailableBalanceValidator(availableStxBalance)
),
fee: stxFeeValidator(availableStxBalance),
recipient,
memo,
Expand Down
8 changes: 6 additions & 2 deletions tests/specs/send/send-stx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { SendPage } from '@tests/page-object-models/send.page';
import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors';
import { getDisplayerAddress } from '@tests/utils';

import { STX_DECIMALS } from '@shared/constants';

import { FormErrorMessages } from '@app/common/error-messages';

import { test } from '../../fixtures/fixtures';
Expand Down Expand Up @@ -106,7 +108,8 @@ test.describe('send stx', () => {
await sPage.amountInput.fill('0.0000001');
await sPage.amountInput.blur();
const errorMsg = await sPage.amountInputErrorLabel.innerText();
test.expect(errorMsg).toEqual(FormErrorMessages.MustBePositive);
const error = FormErrorMessages.TooMuchPrecision;
test.expect(errorMsg).toEqual(error.replace('{decimals}', String(STX_DECIMALS)));
});

test('that the amount is greater than the available balance', async () => {
Expand Down Expand Up @@ -160,7 +163,8 @@ test.describe('send stx', () => {

await sPage.previewSendTxButton.click();
const errorMsg = await sPage.amountInputErrorLabel.innerText();
test.expect(errorMsg).toEqual(FormErrorMessages.MustBePositive);
const error = FormErrorMessages.TooMuchPrecision;
test.expect(errorMsg).toEqual(error.replace('{decimals}', String(STX_DECIMALS)));
await sPage.amountInput.fill('0.000001');
await sPage.previewSendTxButton.click();
const details = await sPage.confirmationDetails.allInnerTexts();
Expand Down

0 comments on commit 33aae7a

Please sign in to comment.