Skip to content

feat(sdk-coin-icp): refactor account balance and fee retrieval to use IcpAgent class #6194

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

Merged
merged 1 commit into from
May 28, 2025

Conversation

mohd-kashif
Copy link
Contributor

Ticket: Win-5302

@mohd-kashif mohd-kashif self-assigned this May 27, 2025
@mohd-kashif mohd-kashif marked this pull request as ready for review May 27, 2025 11:55
@mohd-kashif mohd-kashif requested a review from a team as a code owner May 27, 2025 11:55
@mullapudipruthvik mullapudipruthvik requested a review from Copilot May 28, 2025 03:43
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the ICP account balance and fee retrieval logic to use a new IcpAgent class. Key changes include:

  • Replacing getBalanceFromPrincipal stubs with IcpAgent methods in unit tests.
  • Introducing a new IcpAgent class to encapsulate ICP ledger interactions.
  • Updating the account balance and fee retrieval flow in the ICP coin implementation.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
modules/sdk-coin-icp/test/unit/transactionBuilder/transactionRecover.ts Updated unit tests to stub IcpAgent for balance and fee methods
modules/sdk-coin-icp/src/lib/utils.ts Minor update to the JSDoc comment for feeData
modules/sdk-coin-icp/src/lib/iface.ts Added new constants for fee and metadata retrieval
modules/sdk-coin-icp/src/lib/icpAgent.ts New IcpAgent class for handling ledger interactions
modules/sdk-coin-icp/src/icp.ts Refactored balance and fee retrieval logic to leverage IcpAgent

const actualBalance = balance.plus(feeData); // gas amount returned from gasData is negative so we add it
const balance = await this.getAccountBalance(publicKey);
const feeData = await this.getFeeData();
const actualBalance = balance.minus(feeData);
Copy link
Preview

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

The old comment referred to gas data being negative and added to the balance, but the new logic subtracts the fee. Consider updating or removing the outdated comment to match the current calculation.

Copilot uses AI. Check for mistakes.

Comment on lines 69 to 70
sinon.stub(IcpAgent.prototype, 'getBalance').resolves(BigNumber(1000000000));
sinon.stub(IcpAgent.prototype, 'getFee').resolves(BigNumber(10000));
Copy link
Preview

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] Multiple tests repeat similar stubbing logic for IcpAgent. Consider centralizing these stubs in a beforeEach hook to reduce repetition and improve readability.

Suggested change
sinon.stub(IcpAgent.prototype, 'getBalance').resolves(BigNumber(1000000000));
sinon.stub(IcpAgent.prototype, 'getFee').resolves(BigNumber(10000));

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@hitansh-madan hitansh-madan left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@shashankms288 shashankms288 left a comment

Choose a reason for hiding this comment

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

LGTM

@mohd-kashif mohd-kashif merged commit 1667bb6 into master May 28, 2025
11 checks passed
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