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: toast for You do not have enough tokens to pay the transaction fee #1116

Merged
merged 12 commits into from
Jan 12, 2024
2 changes: 1 addition & 1 deletion src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export default {
'The amount of token to be staking must be greater than {amount} {symbol}',
allFundsWillBeTransferred:
'All funds will be transferred because the min. staking amount is {minStakingAmount} {symbol}',
invalidBalance: 'Insufficient transferrable balance to complete the transaction',
invalidBalance: 'You do not have enough tokens to pay the transaction fee',
warningLeaveMinAmount:
'Account must hold greater than {amount}{symbol} in transferrable when you stake.',
},
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/fr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export default {
'Le montant de jeton à mettre en staking doit être supérieur à {amount} {symbol}',
allFundsWillBeTransferred:
'Tous les fonds seront transférés car le montant minimum est de {minStakingAmount} {symbol}',
invalidBalance: 'Solde transférable insuffisant pour finaliser la transaction',
invalidBalance: "Vous n'avez pas assez de jetons pour payer les frais de transaction",
warningLeaveMinAmount:
'Le compte doit contenir un montant supérieur à {amount}{symbol} transférable lorsque vous misez.',
},
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/pt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export default {
notEnoughMinAmount: 'A quantidade de token em stake deve ser maior que {amount} {symbol}',
allFundsWillBeTransferred:
'Todos os fundos serão transferidos porque o valor min. do stake é {minStakingAmount} {symbol}',
invalidBalance: 'Saldo transferível insuficiente para concluir a transação',
invalidBalance: 'Você não tem tokens suficientes para pagar a taxa de transação',
warningLeaveMinAmount:
'A conta deve conter mais de {amount}{symbol} em valor transferível quando você faz stake.',
},
Expand Down
3 changes: 3 additions & 0 deletions src/modules/toast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ export enum AlertMsg {
ERROR = 'Transaction failed',
ERROR_DUPLICATED_TX = 'Transaction failed due to duplicate transactions on PolkaSafe; please approve or reject them before creating a new transaction',
COMPLETED_HASH = 'Completed at transaction hash',
MINIMUM_BALANCE = 'You do not have enough tokens to pay the transaction fee',
}

export const REQUIRED_MINIMUM_BALANCE: number = 0.05;
gluneau marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 9 additions & 1 deletion src/v2/services/implementations/MetamaskWalletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { inject, injectable } from 'inversify';
import { getEvmProvider } from 'src/hooks/helper/wallet';
import { EthereumProvider } from 'src/hooks/types/CustomSignature';
import { getEvmExplorerUrl, getSubscanExtrinsic } from 'src/links';
import { AlertMsg } from 'src/modules/toast';
import { AlertMsg, REQUIRED_MINIMUM_BALANCE } from 'src/modules/toast';
import { Guard } from 'src/v2/common';
import { BusyMessage, ExtrinsicStatusMessage, IEventAggregator } from 'src/v2/messaging';
import { IEthCallRepository, ISystemRepository } from 'src/v2/repositories';
Expand Down Expand Up @@ -123,6 +123,14 @@ export class MetamaskWalletService extends WalletService implements IWalletServi
}: ParamSendEvmTransaction): Promise<string> {
try {
const web3 = new Web3(this.provider as any);

const balWei = await web3.eth.getBalance(from);
const useableBalance = Number(ethers.utils.formatEther(balWei));
const isBalanceNotEnough = useableBalance < REQUIRED_MINIMUM_BALANCE;
if (isBalanceNotEnough) {
throw Error(AlertMsg.MINIMUM_BALANCE);
}

const rawTx = await getRawEvmTransaction(web3, from, to, data, value);
const estimatedGas = await web3.eth.estimateGas(rawTx);
const transactionHash = await web3.eth
Expand Down
13 changes: 12 additions & 1 deletion src/v2/services/implementations/PolkadotWalletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { inject, injectable } from 'inversify';
import { LOCAL_STORAGE } from 'src/config/localStorage';
import { isMobileDevice } from 'src/hooks/helper/wallet';
import { getSubscanExtrinsic, polkasafeUrl } from 'src/links';
import { AlertMsg } from 'src/modules/toast/index';
import { AlertMsg, REQUIRED_MINIMUM_BALANCE } from 'src/modules/toast/index';
import { Guard, wait } from 'src/v2/common';
import { BusyMessage, ExtrinsicStatusMessage, IEventAggregator } from 'src/v2/messaging';
import { Account } from 'src/v2/models';
Expand Down Expand Up @@ -77,6 +77,17 @@ export class PolkadotWalletService extends WalletService implements IWalletServi
tip = tip ? ethers.utils.parseEther(tip).toString() : '1';
}

const useableBalance = await this.assetsRepository.getNativeBalance(senderAddress);
const isBalanceNotEnough =
Number(ethers.utils.formatEther(useableBalance)) < REQUIRED_MINIMUM_BALANCE;
if (isBalanceNotEnough) {
this.eventAggregator.publish(
bobo-k2 marked this conversation as resolved.
Show resolved Hide resolved
new ExtrinsicStatusMessage({ success: false, message: AlertMsg.MINIMUM_BALANCE })
);
this.eventAggregator.publish(new BusyMessage(false));
throw Error(AlertMsg.MINIMUM_BALANCE);
}

const multisig = localStorage.getItem(LOCAL_STORAGE.MULTISIG);
if (multisig) {
try {
Expand Down
Loading