-
Notifications
You must be signed in to change notification settings - Fork 93
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: modified logic for checking the native token's remaining balance #1429
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { | |
REQUIRED_MINIMUM_BALANCE_ETH, | ||
} from 'src/modules/toast/index'; | ||
import { astarNativeTokenErcAddr } from 'src/modules/xcm'; | ||
import { idAstarNativeToken } from 'src/modules/xcm/tokens'; | ||
import { container } from 'src/v2/common'; | ||
import { IEventAggregator } from 'src/v2/messaging'; | ||
import { IAssetsRepository } from 'src/v2/repositories/IAssetsRepository'; | ||
|
@@ -38,23 +39,27 @@ export class AssetsService implements IAssetsService { | |
} | ||
|
||
public async transferNativeAsset(param: ParamAssetTransfer): Promise<void> { | ||
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 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)) - | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are unnecessary conversions here. The main reason for that is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted, I've modified like this but we need to do some refactoring in the future. |
||
Number(ethers.utils.formatEther(param.amount)) > | ||
REQUIRED_MINIMUM_BALANCE; | ||
|
||
if (isBalanceEnough) { | ||
const transaction = await this.AssetsRepository.getNativeTransferCall(param); | ||
const hash = await this.wallet.signAndSend({ | ||
extrinsic: transaction, | ||
senderAddress: param.senderAddress, | ||
successMessage: param.successMessage, | ||
}); | ||
param.finalizedCallback(String(hash)); | ||
} else { | ||
throw new Error(AlertMsg.MINIMUM_BALANCE); | ||
if (!isBalanceEnough) { | ||
throw new Error(AlertMsg.MINIMUM_BALANCE); | ||
} | ||
} | ||
|
||
const transaction = await this.AssetsRepository.getNativeTransferCall(param); | ||
const hash = await this.wallet.signAndSend({ | ||
extrinsic: transaction, | ||
senderAddress: param.senderAddress, | ||
successMessage: param.successMessage, | ||
}); | ||
param.finalizedCallback(String(hash)); | ||
} | ||
|
||
public async transferEvmAsset(param: ParamEvmTransfer): Promise<void> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssetsRepository
should be renamed toassetsRepository
since it is a private variableThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in this commit