Skip to content

Commit

Permalink
fix: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
impelcrypto committed Dec 19, 2024
1 parent 7c28c9a commit a60c78c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/v2/services/implementations/AssetsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class AssetsService implements IAssetsService {

constructor(
@inject(Symbols.AssetsRepository)
private AssetsRepository: IAssetsRepository,
private assetsRepository: IAssetsRepository,
@inject(Symbols.WalletFactory) walletFactory: () => IWalletService,
@inject(Symbols.CurrentWallet) private currentWallet: string,
@inject(Symbols.EventAggregator) readonly eventAggregator: IEventAggregator
Expand All @@ -42,18 +42,16 @@ export class AssetsService implements IAssetsService {
const isNativeToken = param.assetId === idAstarNativeToken;
// Memo: Check if the native token's remaining balance is enough to pay the transaction fee
if (isNativeToken) {
const useableBalance = await this.AssetsRepository.getNativeBalance(param.senderAddress);
const isBalanceEnough =
Number(ethers.utils.formatEther(useableBalance)) -
Number(ethers.utils.formatEther(param.amount)) >
REQUIRED_MINIMUM_BALANCE;
const useableBalance = await this.assetsRepository.getNativeBalance(param.senderAddress);
const requiredBalance = ethers.utils.parseEther(String(REQUIRED_MINIMUM_BALANCE)).toBigInt();
const isBalanceEnough = BigInt(useableBalance) - BigInt(param.amount) > requiredBalance;

if (!isBalanceEnough) {
throw new Error(AlertMsg.MINIMUM_BALANCE);
}
}

const transaction = await this.AssetsRepository.getNativeTransferCall(param);
const transaction = await this.assetsRepository.getNativeTransferCall(param);
const hash = await this.wallet.signAndSend({
extrinsic: transaction,
senderAddress: param.senderAddress,
Expand Down Expand Up @@ -84,7 +82,7 @@ export class AssetsService implements IAssetsService {

const isBalanceEnough = useableBalance - amount > minBal;
if (isBalanceEnough) {
const rawTx = await this.AssetsRepository.getEvmTransferData({
const rawTx = await this.assetsRepository.getEvmTransferData({
param,
web3,
});
Expand All @@ -105,15 +103,15 @@ export class AssetsService implements IAssetsService {
}

public async evmWithdraw({ amount, senderAddress }: ParamEvmWithdraw): Promise<void> {
const transaction = await this.AssetsRepository.getEvmWithdrawCall({ amount, senderAddress });
const transaction = await this.assetsRepository.getEvmWithdrawCall({ amount, senderAddress });
await this.wallet.signAndSend({
extrinsic: transaction,
senderAddress,
});
}

public async unlockVestingTokens(senderAddress: string): Promise<void> {
const transaction = await this.AssetsRepository.getVestCall();
const transaction = await this.assetsRepository.getVestCall();
await this.wallet.signAndSend({
extrinsic: transaction,
senderAddress,
Expand Down

0 comments on commit a60c78c

Please sign in to comment.