Skip to content

Commit

Permalink
Fix: Missing validation (#3096)
Browse files Browse the repository at this point in the history
* fix: missing fee validation

* chore: log
  • Loading branch information
tuul-wq authored Feb 3, 2025
1 parent 718ca6b commit 4541076
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ const validateFx = createEffect(({ store, balances }: ValidateParams) => {

if (!result) return;

throw new Error(result.errorText);
const error = new Error(result.errorText);
console.error(error);

throw error;
});

const $initiatorWallets = combine(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BN } from '@polkadot/util';
import { BN, BN_ZERO } from '@polkadot/util';

import { ZERO_BALANCE, formatAmount } from '@/shared/lib/utils';
import { type Config, type TransferFeeStore, type TransferXcmFeeStore } from '../../types/types';
Expand Down Expand Up @@ -31,21 +31,17 @@ function insufficientBalanceForFee(
isNative,
isProxy,
isMultisig,
isXcm,
}: TransferFeeStore,
config: Config = { withFormatAmount: true },
) {
if (isXcm && !isNative) {
if (isLteThanBalance(fee, balance)) {
return true;
}
if (!isNative) {
return isLteThanBalance(fee, balance);
}

const amountBN = new BN(config.withFormatAmount ? formatAmount(amount, asset.precision) : amount);
const feeBN = new BN(isProxy || isMultisig ? ZERO_BALANCE : fee);
const value = amountBN.add(feeBN);
const feeBN = isProxy || isMultisig ? BN_ZERO : new BN(fee);

return isLteThanBalance(value, balance);
return isLteThanBalance(amountBN.add(feeBN), balance);
}

function insufficientBalanceForXcmFee(
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/shared/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@
},
"notEnoughBalanceError": "Not enough funds to complete operation",
"notEnoughBalanceForDepositError": "Insufficient balance to pay deposit and network fee",
"notEnoughBalanceForFeeError": "Insufficient balance to pay network fee",
"notEnoughBalanceForFeeError": "Not enough tokens to pay for the network fee",
"notEnoughStakedError": "Not enough staked to unstake specific amount",
"notEnoughUnlockingError": "Not enough unlocking to return specific amount",
"overview": {
Expand Down Expand Up @@ -1650,7 +1650,7 @@
"noAmount": "Please provide amount",
"notEnoughBalanceError": "Not enough funds to transfer specific amount",
"notEnoughBalanceForDepositError": "Insufficient balance to pay deposit and network fee",
"notEnoughBalanceForFeeError": "Insufficient balance to pay network fee",
"notEnoughBalanceForFeeError": "Not enough tokens to pay for the network fee",
"notZeroAmountError": "Value cannot be zero",
"onChainPlaceholder": "On-chain",
"pasteButton": "Paste",
Expand Down
12 changes: 12 additions & 0 deletions src/renderer/widgets/Transfer/model/form-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ const $transferForm = createForm<FormParams>({
balance: $accountBalance,
}),
),
TransferRules.amount.insufficientBalanceForFee(
combine({
fee: $totalFee,
xcmFee: xcmTransferModel.$xcmFee,
network: $networkStore,
balance: $accountBalance,
isNative: $isNative,
isMultisig: $isMultisig,
isXcm: $isXcm,
isProxy: $isProxy,
}),
),
TransferRules.amount.insufficientBalanceForXcmFee(
combine({
fee: $totalFee,
Expand Down

0 comments on commit 4541076

Please sign in to comment.