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

chore: return spendable and actual balance in rpc api getErc20Balance #308

Merged
merged 22 commits into from
Aug 12, 2024

Conversation

khanti42
Copy link
Collaborator

@khanti42 khanti42 commented Jul 31, 2024

Description

This pull request enhances the getErc20Balance function to return both the spendable balance and the actual balance of an ERC-20 token. The primary goal is to provide users with a more accurate representation of their available funds by distinguishing between confirmed (actual) balances and spendable balances, taking into account any pending transactions.

Changes

Function Update

The getErc20Balance function now calculates and returns two balances:

  • Spendable Balance: The minimum of the confirmed balance and the latest state balance (considering pending transactions).
  • Actual Balance: The confirmed balance without considering pending transactions.

Balance Calculation

  • Confirmed Balance: The balance after all confirmed transactions.
  • Latest State Balance: The balance considering pending transactions (both incoming and outgoing).
  • Spendable Balance: Calculated as the minimum of the confirmed balance and the latest state balance.

Motivation

  • User Experience: By showing the spendable balance, users are provided with a clearer picture of the amount they can actually use, preventing confusion and potential transaction failures due to pending transactions.
  • Accuracy: Ensures that the displayed balance reflects the true spendable amount, avoiding scenarios where users see tokens that are not yet confirmed and therefore not spendable.

Testing

  • Updated unit tests to cover scenarios with pending transactions.
  • Verified that the function correctly returns both the spendable and actual balances.

Impact

  • Backward Compatibility: The function signature changes to return two balances instead of one, which may require updates in the consuming code.
  • User Interface: UIs displaying the token balance will need to be updated to show both the spendable and actual balances.

Requirement:

Requires this PR to be merged first:

@khanti42 khanti42 marked this pull request as ready for review July 31, 2024 21:04
@khanti42 khanti42 requested a review from a team as a code owner July 31, 2024 21:04
@khanti42 khanti42 requested review from Julink-eth and stanleyyconsensys and removed request for a team July 31, 2024 21:04
@stanleyyconsensys stanleyyconsensys changed the title feat: getErc20Balance Should Return Spendable and Actual Balance chore: Return Spendable and Actual Balance in getErc20Balance Aug 1, 2024
@stanleyyconsensys stanleyyconsensys changed the title chore: Return Spendable and Actual Balance in getErc20Balance chore: Return Spendable and Actual Balance in RPC Api getErc20Balance Aug 1, 2024
@stanleyyconsensys stanleyyconsensys changed the title chore: Return Spendable and Actual Balance in RPC Api getErc20Balance chore: return spendable and actual balance in rpc api getErc20Balance Aug 1, 2024
Copy link

sonarqubecloud bot commented Aug 2, 2024

Quality Gate Passed Quality Gate passed for 'consensys_starknet-snap-starknet-snap'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

sonarqubecloud bot commented Aug 2, 2024

Quality Gate Passed Quality Gate passed for 'consensys_starknet-snap-wallet-ui'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@khanti42 khanti42 merged commit 1ad58a0 into main Aug 12, 2024
13 checks passed
@khanti42 khanti42 deleted the feat/sf-670 branch August 12, 2024 10:12
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.

2 participants