Skip to content

Commit

Permalink
REQUIRED_MINIMUM_BALANCE
Browse files Browse the repository at this point in the history
  • Loading branch information
gluneau committed Jan 9, 2024
1 parent f8c0ee5 commit 3a0320c
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/modules/toast/index.ts
Original file line number Diff line number Diff line change
@@ -6,3 +6,5 @@ export enum AlertMsg {
COMPLETED_HASH = 'Completed at transaction hash',
MINIMUM_BALANCE = 'Minimum balance on the network is 0.05',
}

export const REQUIRED_MINIMUM_BALANCE: number = 0.05;
5 changes: 3 additions & 2 deletions src/v2/services/implementations/MetamaskWalletService.ts
Original file line number Diff line number Diff line change
@@ -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';
@@ -126,7 +126,8 @@ export class MetamaskWalletService extends WalletService implements IWalletServi

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

6 changes: 4 additions & 2 deletions src/v2/services/implementations/PolkadotWalletService.ts
Original file line number Diff line number Diff line change
@@ -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';
@@ -78,7 +78,9 @@ export class PolkadotWalletService extends WalletService implements IWalletServi
}

const useableBalance = await this.assetsRepository.getNativeBalance(senderAddress);
if (Number(useableBalance) < Number(500000000000000000)) {
const isBalanceNotEnough =
Number(ethers.utils.formatEther(useableBalance)) < REQUIRED_MINIMUM_BALANCE;
if (isBalanceNotEnough) {
this.eventAggregator.publish(
new ExtrinsicStatusMessage({ success: false, message: AlertMsg.MINIMUM_BALANCE })
);

0 comments on commit 3a0320c

Please sign in to comment.