Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: investigate stx fee issues #5387

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/app/common/validation/forms/amount-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as yup from 'yup';

import { Money } from '@shared/models/money.model';
import { isNumber } from '@shared/utils';
import { analytics } from '@shared/utils/analytics';

import { countDecimals } from '@app/common/math/helpers';
import {
Expand Down Expand Up @@ -90,8 +91,16 @@ export function stxAvailableBalanceValidator(availableBalance: Money) {
microStxToStx(sum.amount).toString()
),
test(value: unknown) {
const fee = stxToMicroStx(this.parent.fee);
if (!availableBalance || !isNumber(value)) return false;
const fee = new BigNumber(stxToMicroStx(this.parent.fee));
if (!fee.isFinite()) {
void analytics.track('unable_to_read_fee_in_stx_validator');
return this.createError({ message: 'Unable to read current fee' });
}
if (!isNumber(value)) return false;
if (!availableBalance) {
void analytics.track('unable_to_read_available_balance_in_stx_validator');
return this.createError({ message: 'Available balance unknown' });
}
const availableBalanceLessFee = availableBalance.amount.minus(fee);
return availableBalanceLessFee.isGreaterThanOrEqualTo(stxToMicroStx(value));
},
Expand Down
Loading