Skip to content

Commit

Permalink
fix: investigate stx fee issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed May 20, 2024
1 parent ca9cf0b commit f8c3422
Showing 1 changed file with 11 additions and 2 deletions.
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_balanxce_in_stx_validator');
return this.createError({ message: 'Available balance unknown' });
}
const availableBalanceLessFee = availableBalance.amount.minus(fee);
return availableBalanceLessFee.isGreaterThanOrEqualTo(stxToMicroStx(value));
},
Expand Down

0 comments on commit f8c3422

Please sign in to comment.