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

feat: add support for pool migration #1702

Merged
merged 5 commits into from
Feb 22, 2025
Merged

feat: add support for pool migration #1702

merged 5 commits into from
Feb 22, 2025

Conversation

Nick-1979
Copy link
Member

@Nick-1979 Nick-1979 commented Feb 19, 2025

Pooled balance is part of reserved on kusama and westend, hence no need to add them to total balance anymore.

Summary by CodeRabbit

  • New Features
    • Pool Migration Support: Users can now vote on governance using staked funds from their pools.
    • Enhanced Balance Integration: The system now computes and displays asset balances more accurately, ensuring that all eligible staked funds are correctly reflected.
    • Release News Update: The latest version highlights these improvements along with additional optimizations for improved responsiveness during balance updates.
    • Pooled Balance Handling: The application now includes support for a new type of balance, enhancing the overall balance management functionality.
    • Voting Balance Calculation: The application now includes a new voting balance that sums free and reserved balances for improved accuracy.

@Nick-1979 Nick-1979 requested a review from AMIRKHANEF February 19, 2025 15:22
Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Walkthrough

The changes introduce pooled balance handling for nomination pools. The useReservedDetails hook now computes a memoized pooled balance from account assets and updates the reserved state conditionally based on the migration constant. The account utility function has been updated to conditionally include pooledBalance in the total based on a migration check, and a news entry documents the pool migration support. Additionally, the MIGRATED_NOMINATION_POOLS_CHAINS constant and copyright years have been updated.

Changes

File(s) Change Summary
packages/extension-polkagate/src/hooks/useReservedDetails.ts Extended Item type with pooledBalance; imported useAccountAssets; computed maybePooledBalance via useMemo; conditionally updated reserved state based on MIGRATED_NOMINATION_POOLS_CHAINS; refined dependency and error logging.
packages/extension-polkagate/src/popup/account/util.ts, packages/extension-polkagate/src/popup/home/news.ts Imported MIGRATED_NOMINATION_POOLS_CHAINS; added migration check in balance computation to conditionally add pooledBalance; inserted a new news entry for pool migration; updated copyright dates.
packages/extension-polkagate/src/util/constants.tsx Added new MIGRATED_NOMINATION_POOLS_CHAINS constant and updated copyright.
packages/extension-polkagate/src/fullscreen/governance/delegate/partial/AlreadyLockedTooltipText.tsx, packages/extension-polkagate/src/fullscreen/manageIdentity/Review.tsx Updated copyright year; modified type handling for getAlreadyLockedValue and setBalances functions.
packages/extension-polkagate/src/hooks/useNativeAssetBalances.ts Added import for Balance type; introduced votingBalance in balance state update.
packages/extension-polkagate/src/util/types.ts, packages/extension-polkagate/src/util/workers/utils/balancify.js Updated copyright year; modified balance calculation logic in balancify.
packages/extension-polkagate/src/util/workers/shared-helpers/getAssetOnRelayChain.js Updated copyright year; modified total balance calculation logic to conditionally exclude pooledBalance for migrated pools.

Possibly related PRs

  • chore: update packages and fix foreign assets problem #1667: The changes in the main PR enhance the useReservedDetails hook by adding logic related to pooledBalance, which is also utilized in this retrieved PR affecting balance calculations based on the genesis hash.
  • fix: staking balances get undefined in useBalances #1609: The main PR's changes to the useReservedDetails hook and the modifications in this retrieved PR concerning the useBalances hook both involve handling pooledBalance, indicating a direct connection in balance management.
  • fix: user added chains price id #1571: The main PR enhances the useReservedDetails hook with logic related to pooledBalance, which is also reflected in this retrieved PR that modifies balance calculations using MIGRATED_NOMINATION_POOLS_CHAINS.

Suggested labels

new feature, change requested

Suggested reviewers

  • AMIRKHANEF

Poem

I'm a little rabbit with code so bright,
Hopping through changes with pure delight.
Pooled balances bloom under the migration light,
Skipping past bugs with each swift byte.
Carrots and commits keep our code just right!
🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52b5973 and 1b3a036.

📒 Files selected for processing (1)
  • packages/extension-polkagate/src/popup/home/news.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/popup/home/news.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: Analyze (javascript)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3caf1c and f3e38f1.

📒 Files selected for processing (4)
  • packages/extension-polkagate/src/hooks/useReservedDetails.ts (3 hunks)
  • packages/extension-polkagate/src/popup/account/util.ts (3 hunks)
  • packages/extension-polkagate/src/popup/home/news.ts (2 hunks)
  • packages/extension-polkagate/src/util/constants.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/extension-polkagate/src/util/constants.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
packages/extension-polkagate/src/popup/account/util.ts

[error] 28-28: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
packages/extension-polkagate/src/popup/account/util.ts (1)

30-32: LGTM! Balance calculation logic aligns with pool migration.

The total balance calculation correctly excludes pooled balance for migrated chains (Kusama and Westend) where it's now part of reserved balance.

packages/extension-polkagate/src/popup/home/news.ts (1)

12-17: LGTM! Clear and informative news entry.

The news entry accurately describes the pool migration support and its impact on governance voting capabilities.

packages/extension-polkagate/src/hooks/useReservedDetails.ts (3)

20-20: LGTM! Type definition updated for pool migration.

The Item type correctly includes pooledBalance as a possible reserved detail.


30-32: LGTM! Efficient memoization of pooled balance.

The pooled balance is correctly memoized with appropriate dependencies.


284-293: LGTM! Proper handling of pooled balance as reserved.

The implementation correctly:

  1. Checks if the chain is in MIGRATED_NOMINATION_POOLS_CHAINS
  2. Verifies non-zero pooled balance
  3. Updates reserved state with the pooled balance

@Nick-1979 Nick-1979 changed the title Feat: add support for Pool migration feat: add support for Pool migration Feb 19, 2025
@Nick-1979 Nick-1979 changed the title feat: add support for Pool migration feat: add support for pool migration Feb 20, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/extension-polkagate/src/util/workers/utils/balancify.js (1)

19-20: LGTM! Consider adding documentation.

The new votingBalance calculation correctly handles pooled balances being part of reserved balance after pool migration. The fallback to BN_ZERO ensures safe handling of undefined reserved balances.

Consider adding a JSDoc comment to document this behavior change:

+  /**
+   * Calculate voting balance as free + reserved.
+   * After pool migration, pooled balances are part of reserved balance on certain chains,
+   * so we no longer use the API's votingBalance directly.
+   */
   votingBalance: String(balances.free.add(balances?.reserved || BN_ZERO))
packages/extension-polkagate/src/hooks/useNativeAssetBalances.ts (1)

59-60: Consider updating the dependency array.

The votingBalance calculation depends on allBalances, but it's not included in the dependency array of the useCallback hook.

Add allBalances to the dependency array:

  }, [api, genesisHash, chainName, decimal, stakingAccount, token, isFetchingNativeTokenOfAssetHub, balances, formatted, isFetching.fetching[String(formatted)]?.['length'], setRefresh
+    , allBalances
  ]);
packages/extension-polkagate/src/fullscreen/governance/delegate/partial/AlreadyLockedTooltipText.tsx (1)

34-44: Consider using for...of loop for better readability.

Instead of disabling the ESLint rule, consider refactoring the loop to use the more readable for...of syntax.

-        // eslint-disable-next-line @typescript-eslint/prefer-for-of
-        for (let i = 0; i < LOCKS_ORDERED.length; i++) {
-          const lockName = LOCKS_ORDERED[i];
+        for (const lockName of LOCKS_ORDERED) {
           if (a.id.eq(lockName)) {
             return -1;
           } else if (b.id.eq(lockName)) {
             return 1;
           }
-        }
+        }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f3e38f1 and a765e1e.

📒 Files selected for processing (5)
  • packages/extension-polkagate/src/fullscreen/governance/delegate/partial/AlreadyLockedTooltipText.tsx (4 hunks)
  • packages/extension-polkagate/src/fullscreen/manageIdentity/Review.tsx (2 hunks)
  • packages/extension-polkagate/src/hooks/useNativeAssetBalances.ts (3 hunks)
  • packages/extension-polkagate/src/util/types.ts (2 hunks)
  • packages/extension-polkagate/src/util/workers/utils/balancify.js (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/extension-polkagate/src/util/types.ts
  • packages/extension-polkagate/src/fullscreen/manageIdentity/Review.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
packages/extension-polkagate/src/util/workers/utils/balancify.js (1)

1-5: LGTM!

The copyright year update and BN_ZERO import are appropriate for the new votingBalance calculation.

packages/extension-polkagate/src/hooks/useNativeAssetBalances.ts (1)

5-5: LGTM!

The Balance type import and votingBalance calculation using api.createType ensure type safety and consistent behavior.

Also applies to: 46-46

packages/extension-polkagate/src/fullscreen/governance/delegate/partial/AlreadyLockedTooltipText.tsx (3)

7-9: LGTM!

The import changes appropriately support the pool migration changes by updating to the new BalancesInfo type and adding necessary type imports.


24-24: LGTM!

The function signature has been appropriately updated to use the new BalancesInfo type while maintaining the same functionality.


85-85: LGTM!

Good addition of the optional chaining operator to safely handle potentially undefined refId values.

@Nick-1979 Nick-1979 requested review from AMIRKHANEF and removed request for AMIRKHANEF February 20, 2025 13:06
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/extension-polkagate/src/util/workers/shared-helpers/getAssetOnRelayChain.js (1)

29-30: LGTM! Correctly implements pooled balance handling.

The implementation aligns with PR objectives by excluding pooled balance from total balance calculation for migrated chains (Kusama and Westend) where it's part of reserved balance.

Consider extracting the total balance calculation to a separate function for better readability:

+  const calculateTotalBalance = (freeBalance, reservedBalance, pooledBalance, isMigrated) => {
+    return freeBalance.add(reservedBalance).add(isMigrated ? BN_ZERO : pooledBalance);
+  };
+
   balanceInfo.forEach(({ address, balances, pooledBalance, soloTotal }) => {
     const genesisHash = api.genesisHash.toString();
     const isMigrated = MIGRATED_NOMINATION_POOLS_CHAINS.includes(genesisHash);
-    const totalBalance = balances.freeBalance.add(balances.reservedBalance).add(isMigrated ? BN_ZERO : pooledBalance);
+    const totalBalance = calculateTotalBalance(balances.freeBalance, balances.reservedBalance, pooledBalance, isMigrated);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a765e1e and 52b5973.

📒 Files selected for processing (1)
  • packages/extension-polkagate/src/util/workers/shared-helpers/getAssetOnRelayChain.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/extension-polkagate/src/util/workers/shared-helpers/getAssetOnRelayChain.js (1)

4-6: LGTM! Imports align with PR objectives.

The new imports support the pooled balance migration feature:

  • BN_ZERO for zero value when excluding pooled balance
  • MIGRATED_NOMINATION_POOLS_CHAINS for checking chain migration status

@Nick-1979 Nick-1979 merged commit 55c57b8 into main Feb 22, 2025
5 checks passed
@Nick-1979 Nick-1979 deleted the poolMigration branch February 22, 2025 07:59
github-actions bot pushed a commit that referenced this pull request Feb 22, 2025
# [0.35.0](v0.34.0...v0.35.0) (2025-02-22)

### Features

* add support for pool migration ([#1702](#1702)) ([55c57b8](55c57b8))
@coderabbitai coderabbitai bot mentioned this pull request Feb 22, 2025
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