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: modified logic for checking the native token's remaining balance #1429

Merged
merged 3 commits into from
Dec 30, 2024

Conversation

impelcrypto
Copy link
Member

@impelcrypto impelcrypto commented Dec 19, 2024

Pull Request Summary

  • fix: modified logic for checking the native token's remaining balance

Check list

  • contains breaking changes
  • adds new feature
  • modifies existing feature (bug fix or improvements)
  • relies on other tasks
  • documentation changes
  • tested on mobile devices

Copy link

github-actions bot commented Dec 19, 2024

Visit the preview URL for this PR (updated for commit a60c78c):

https://astar-apps--pr1429-fix-vastr-send-j38cl0iw.web.app

(expires Mon, 06 Jan 2025 08:47:58 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: dd76fe72958fe2910fef9d53f0b4539b82b849db

@impelcrypto impelcrypto changed the title fix: modified native token's remaining balance checking logic fix: modified logic for checking the native token's remaining balance Dec 19, 2024
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AssetsRepository should be renamed to assetsRepository since it is a private variable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in this commit

if (isNativeToken) {
const useableBalance = await this.AssetsRepository.getNativeBalance(param.senderAddress);
const isBalanceEnough =
Number(ethers.utils.formatEther(useableBalance)) -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are unnecessary conversions here. The main reason for that is useableBalance and param.amount are strings. IMO using string for balances is not natural (more natural is bigint) and leads to increased code complexity.
You don't need to fix this now, but we should have this in mind for the future

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

@impelcrypto impelcrypto merged commit f8dcfe1 into main Dec 30, 2024
8 of 9 checks passed
@impelcrypto impelcrypto deleted the fix/vastr-send branch December 30, 2024 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants