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

Transferable vs available balance! address #1071 #1078

Merged
merged 9 commits into from
Aug 18, 2024
Merged

Conversation

Nick-1979
Copy link
Member

@Nick-1979 Nick-1979 commented Apr 2, 2024

closes #1071

I have utilized the logic mentioned here: paritytech/polkadot-sdk#1833 (comment)

like:

Screenshot 2024-04-02 at 16 24 21

and the result:
Screenshot 2024-04-02 at 16 29 23

Summary by CodeRabbit

  • New Features
    • Improved balance calculations and transferable balance display in various components across the application.
    • Added support for frozen balance retrieval and display.
    • Introduced a new hook to calculate the time and amount of cryptocurrency that can be unlocked for referenda locks.
  • Refactor
    • Enhanced type safety and clarity in balance handling logic for better system integration.
    • Streamlined component parameters for better maintainability.
  • Chores
    • Minor formatting adjustments for consistency and readability across components.

Update index.tsx
Copy link
Contributor

coderabbitai bot commented Apr 2, 2024

Walkthrough

The recent updates enhance balance management in the PolkaGate extension, focusing on accurate calculation and display of transferable balances. Key improvements include the introduction of a new BalancesInfo type for structured balance data and the implementation of a getValue utility function. These changes ensure reliable retrieval and display of balance information across components, effectively addressing issues related to balance discrepancies.

Changes

File Path Change Summary
.../fullscreen/accountDetails/index.tsx & .../hooks/useBalances.ts Enhanced balance processing with structured handling via BalancesInfo and introduced frozenBalance for improved accuracy.
.../popup/account/util.ts & .../util/workers/getAssetOnRelayChain.js Updated utility functions for balance calculations and retrieval, ensuring consistency and accuracy across components.
.../fullscreen/accountDetails/components/LockedInReferendaFS.tsx & .../popup/account/unlock/LockedInReferenda.tsx Renamed and refactored components for clarity and improved logic, removing unnecessary props and integrating new hooks.
.../hooks/useTimeToUnlock.tsx Introduced a new custom hook to calculate unlockable amounts and times for referenda locks, enhancing user experience.

Assessment against linked issues

Objective Addressed Explanation
Correct calculation of transferable balance (#1071)
Update to current balance pallet compatibility (#1071)

Poem

In the realm of code, where balances sway,
A rabbit hopped, to brighten the day.
With a flick and a hop, the numbers align,
Frozen and free, in harmony they combine.

🌟 Across the blockchain, through every gate,
🐇 CodeRabbit ensures, the balances are straight.
In PolkaGate's land, the balances gleam,
A testament to teamwork, and a coder's dream.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 32a32be and 00c1978.
Files selected for processing (4)
  • packages/extension-polkagate/src/fullscreen/accountDetailsFullScreen/index.tsx (1 hunks)
  • packages/extension-polkagate/src/hooks/useBalances.ts (3 hunks)
  • packages/extension-polkagate/src/popup/account/util.ts (3 hunks)
  • packages/extension-polkagate/src/util/types.ts (1 hunks)
Additional comments not posted (4)
packages/extension-polkagate/src/popup/account/util.ts (1)

36-39: The updated logic for calculating the 'transferable' balance in the getValue function correctly considers the frozenBalance and reservedBalance. This change aligns with the PR objectives to accurately calculate and display the transferable balance.

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

104-117: The addition of frozenBalance handling in the getBalances function is a significant improvement. It ensures that the frozenBalance is accurately retrieved from the system account data and included in the newBalances state, aligning with the PR objectives to accurately calculate and display the transferable balance.

packages/extension-polkagate/src/fullscreen/accountDetailsFullScreen/index.tsx (1)

230-230: The modification to use the getValue function for retrieving the 'Transferable' balance in the AccountDetails component is a positive change. It ensures that the balance displayed is calculated based on the updated logic that considers the frozenBalance, aligning with the PR objectives.

packages/extension-polkagate/src/util/types.ts (1)

619-619: The addition of the frozenBalance field to the BalancesInfo interface is crucial for supporting the updated logic for calculating and displaying the transferable balance. This change ensures that the type definitions are aligned with the PR objectives.

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 Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 00c1978 and 9341eb3.
Files selected for processing (6)
  • packages/extension-polkagate/src/hooks/useAssetsBalances.ts (3 hunks)
  • packages/extension-polkagate/src/popup/account/util.ts (3 hunks)
  • packages/extension-polkagate/src/util/workers/getAssetOnAssetHub.js (1 hunks)
  • packages/extension-polkagate/src/util/workers/getAssetOnRelayChain.js (2 hunks)
  • packages/extension-polkagate/src/util/workers/utils/balancify.js (2 hunks)
  • packages/extension-polkagate/src/util/workers/utils/toGetNativeToken.js (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/popup/account/util.ts
Additional comments not posted (6)
packages/extension-polkagate/src/util/workers/utils/balancify.js (2)

8-8: The addition of frozenBalance to the balancify function aligns with the PR objectives and follows the existing pattern for handling balance fields. Good job ensuring consistency.


22-22: The change in balancifyAsset from using balances.availableBalance to balances.free for availableBalance seems to reflect a significant logic adjustment. Please ensure this change accurately represents the intended balance calculations and does not introduce discrepancies.

packages/extension-polkagate/src/util/workers/utils/toGetNativeToken.js (1)

11-15: Fetching systemBalance for each address and updating frozenBalance accordingly aligns with the PR objectives. However, consider adding error handling and type checking when assigning frozenBalance to ensure robustness against potential changes in the systemBalance response structure.

packages/extension-polkagate/src/util/workers/getAssetOnAssetHub.js (1)

46-47: The introduction of freeBalance and frozenBalance fields in getAssetOnAssetHub function is consistent with the PR objectives and is implemented clearly. Consider refining the comment "JUST to comply with the rule ..." to provide more context or clarity on the rule being referred to.

packages/extension-polkagate/src/util/workers/getAssetOnRelayChain.js (1)

57-60: Retrieving systemBalance for each address and updating frozenBalance accordingly aligns with the PR objectives. Consider adding error handling and type checking when assigning frozenBalance to ensure robustness against potential changes in the systemBalance response structure.

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

64-64: Adding frozenBalance to BN_MEMBERS aligns with the PR objectives and ensures consistency across balance-related functionalities.

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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9341eb3 and e414c65.
Files selected for processing (6)
  • packages/extension-polkagate/src/fullscreen/governance/post/decisionDeposit/index.tsx (6 hunks)
  • packages/extension-polkagate/src/fullscreen/sendFund/InputPage.tsx (8 hunks)
  • packages/extension-polkagate/src/popup/crowdloans/contribute/Contribute.tsx (4 hunks)
  • packages/extension-polkagate/src/popup/send/index.tsx (3 hunks)
  • packages/extension-polkagate/src/popup/staking/pool/stake/StakeInitialChoice.tsx (1 hunks)
  • packages/extension-polkagate/src/popup/staking/pool/stake/bondExtra/index.tsx (7 hunks)
Additional comments not posted (22)
packages/extension-polkagate/src/popup/staking/pool/stake/StakeInitialChoice.tsx (1)

63-63: The TODO comment about considering the frozen amount for staking is noted. It's good practice to track such enhancements or potential fixes. Consider creating an issue or task in your project management tool to ensure this doesn't get overlooked.

packages/extension-polkagate/src/popup/staking/pool/stake/bondExtra/index.tsx (4)

49-51: Introduced transferableBalance to consider the total possible staking amount. This is a good practice for clarity and maintainability, ensuring that the balance calculations are based on the correct balance type.


62-71: The logic to set the maximum staking amount considering transferableBalance and estimated fees is correctly implemented. This ensures that the user does not stake more than they can afford after accounting for fees.


99-119: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [92-105]

The fee estimation logic for both the staking amount and the maximum possible staking amount is well-handled. It's important to keep the user informed about potential transaction costs.


108-116: The check to disable the "Next" button based on the staking amount being in range and other conditions is correctly implemented. This prevents users from proceeding with invalid or problematic inputs.

packages/extension-polkagate/src/popup/send/index.tsx (5)

32-32: Importing getValue to retrieve transferableBalance is a good approach for more accurate balance handling in the context of transfers.


57-57: Using transferableBalance for balance calculations instead of directly accessing balances?.availableBalance ensures that the logic considers only the amount that can actually be transferred, improving accuracy.


64-73: The logic to set the whole amount based on transferableBalance correctly accounts for fees and existential deposit, ensuring users don't transfer more than they can afford or drop below the existential deposit.


80-83: Adjusting the logic to check if the amount is less than the transferable balance before enabling the transfer button is a prudent safety measure.


125-127: Updating the call to the transfer function to use transferableBalance instead of balances is a logical step following the introduction of transferableBalance. This ensures consistency in the balance used throughout the transfer logic.

packages/extension-polkagate/src/popup/crowdloans/contribute/Contribute.tsx (5)

27-27: Importing and using getValue to calculate transferableBalance is a good practice, ensuring that the logic operates on the correct balance type for contributions.


57-57: Using transferableBalance for balance-related calculations in the context of crowdloan contributions ensures that the logic is based on the amount that is actually available for transfer, enhancing accuracy.


69-74: The fee estimation logic considering transferableBalance is correctly implemented, ensuring that users are informed about potential transaction costs accurately.


81-84: The logic to disable the "Next" button based on the contribution amount being in range and other conditions is correctly implemented, preventing users from proceeding with invalid or problematic inputs.


91-100: Setting the maximum contribution amount considering transferableBalance and estimated fees is correctly implemented, ensuring that users do not contribute more than they can afford after accounting for fees.

packages/extension-polkagate/src/fullscreen/governance/post/decisionDeposit/index.tsx (2)

20-20: Replacing the import of broadcast with getValue and removing unused imports and components cleans up the code and focuses on the necessary functionality for decision deposit handling.


129-129: Adjusting the calculation of notEnoughBalance by using getValue to retrieve transferableBalance ensures that the logic checks against the correct balance type, improving the accuracy of the check.

packages/extension-polkagate/src/fullscreen/sendFund/InputPage.tsx (5)

19-19: Importing getValue to calculate transferableBalance is a good approach for more accurate balance handling in the context of fund transfers.


85-85: Introducing transferableBalance for balance calculations instead of directly accessing balances?.availableBalance ensures that the logic considers only the amount that can actually be transferred, improving accuracy.


82-105: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [94-112]

The logic to display warning messages based on transferableBalance and other conditions is correctly implemented, ensuring users are informed about potential issues before proceeding with the transfer.


272-277: Calculating the maximum fee based on transferableBalance is a prudent approach to ensure that users are aware of the maximum potential cost of their transfer, aiding in decision-making.


311-324: The logic to set the whole amount based on transferableBalance, considering fees and existential deposit, is correctly implemented. This ensures users don't transfer more than they can afford or drop below the existential deposit.

@AMIRKHANEF
Copy link
Member

Needs more check on Acala!

@Nick-1979 Nick-1979 changed the title address #1071 Transferable vs available balance! address #1071 Apr 7, 2024
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

Commits

Files that changed from the base of the PR and between e414c65 and 25ed4ee.

Files selected for processing (2)
  • packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx (3 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/post/decisionDeposit/index.tsx (4 hunks)
Additional context used
Learnings (1)
packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx (1)
Learnt from: AMIRKHANEF
PR: PolkaGate/extension#1394
File: packages/extension-polkagate/src/fullscreen/accountDetails/components/ReservedDisplayBalance.tsx:0-0
Timestamp: 2024-07-01T09:27:24.482Z
Learning: When checking for NaN values, always use `Number.isNaN` instead of `isNaN` to avoid unexpected type coercions.
Biome
packages/extension-polkagate/src/fullscreen/governance/post/decisionDeposit/index.tsx

[error] 22-22: Do not shadow the global "Proxy" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

Additional comments not posted (4)
packages/extension-polkagate/src/fullscreen/governance/post/decisionDeposit/index.tsx (2)

49-49: Improved readability with consistent formatting.

The added space after the function name aligns with common formatting practices, enhancing readability.


128-128: Enhanced balance check logic using getValue.

Using getValue('transferable', balances) to retrieve the transferable balance improves the clarity and flexibility of the balance sufficiency check.

packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx (2)

8-8: Improved type safety with BalancesInfo.

Importing BalancesInfo enhances the type safety and clarity of balance data handling, aligning with best practices for structured data management.


227-227: Refined balance retrieval logic using getValue.

Using getValue('Transferable', balancesToShow as BalancesInfo) for the amount prop ensures accurate and maintainable balance retrieval.

Comment on lines +21 to +22
import { getValue } from '../../../../popup/account/util';
import { Proxy, ProxyItem, TxInfo } from '../../../../util/types';
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid shadowing restricted global names.

The Proxy type imported here shadows the global Proxy object in JavaScript, which can lead to confusion. Consider renaming this type to avoid potential issues.

- import { Proxy, ProxyItem, TxInfo } from '../../../../util/types';
+ import { Proxy as CustomProxy, ProxyItem, TxInfo } from '../../../../util/types';
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { getValue } from '../../../../popup/account/util';
import { Proxy, ProxyItem, TxInfo } from '../../../../util/types';
import { getValue } from '../../../../popup/account/util';
import { Proxy as CustomProxy, ProxyItem, TxInfo } from '../../../../util/types';
Tools
Biome

[error] 22-22: Do not shadow the global "Proxy" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

@Nick-1979
Copy link
Member Author

Needs more check on Acala!

@AMIRKHANEF can u do the checks plz

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

Outside diff range, codebase verification and nitpick comments (1)
packages/extension-polkagate/src/hooks/useBalances.ts (1)

101-120: Consider using optional chaining.

The useBalances hook correctly includes frozenBalance, enhancing balance data completeness. Consider using optional chaining for accessing formatted.

-    formatted && api.derive.balances?.all(formatted).then((allBalances) => {
+    api.derive.balances?.all(formatted)?.then((allBalances) => {
Tools
Biome

[error] 117-117: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 25ed4ee and 9df8f16.

Files selected for processing (4)
  • packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx (4 hunks)
  • packages/extension-polkagate/src/hooks/useBalances.ts (4 hunks)
  • packages/extension-polkagate/src/popup/account/util.ts (3 hunks)
  • packages/extension-polkagate/src/util/workers/getAssetOnRelayChain.js (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx
Additional context used
Biome
packages/extension-polkagate/src/hooks/useBalances.ts

[error] 117-117: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (5)
packages/extension-polkagate/src/popup/account/util.ts (2)

13-15: LGTM!

The isEmptyObject function correctly checks if an object is empty.


Line range hint 16-41: LGTM!

The modifications to the getValue function enhance its robustness by handling empty objects and implementing logic for 'transferable' balances.

packages/extension-polkagate/src/util/workers/getAssetOnRelayChain.js (3)

Line range hint 16-34: LGTM!

The getPooledBalance function is correctly implemented, and the use of optional chaining enhances robustness.


Line range hint 54-74: LGTM!

The getBalances function correctly includes frozenBalance, enriching the balance data.


Line range hint 85-126: LGTM!

The getAssetOnRelayChain function is correctly implemented, and the cosmetic changes are appropriate.

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

Outside diff range, codebase verification and nitpick comments (3)
packages/extension-polkagate/src/popup/account/unlock/LockedInReferenda.tsx (2)

31-31: Function Declaration Style: Maintain consistency.

The function declaration style was altered slightly by adding a space. Ensure consistency in coding style across the codebase.

- export default function LockedInReferenda({ address, refresh, setRefresh }: Props): React.ReactElement<Props> {
+ export default function LockedInReferenda ({ address, refresh, setRefresh }: Props): React.ReactElement<Props> {

Line range hint 43-49: Redundant Conditional Check: Simplify logic.

The check for referendaLocks === null and subsequent return can be simplified by handling undefined or null values together.

- if (referendaLocks === null) {
-   setLockedInReferenda(BN_ZERO);
-   setTimeToUnlock(null);
-   return;
- }
+ if (!referendaLocks) {
+   setLockedInReferenda(referendaLocks === null ? BN_ZERO : undefined);
+   setTimeToUnlock(referendaLocks === null ? null : undefined);
+   return;
}
packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx (1)

4-4: Type Import Issue: PalletBalancesBalanceLock Not Found in @polkadot/types/lookup.

The type PalletBalancesBalanceLock is not present in the @polkadot/types/lookup package, which suggests that the import statement is incorrect or outdated.

  • Check the package documentation or source to verify the correct type name or location.
  • Update the import statement accordingly to reflect the correct type.
Analysis chain

Type Import Issue: Verify the existence of PalletBalancesBalanceLock.

The import from @polkadot/types/lookup is flagged as problematic. Verify the existence and correctness of this type.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of `PalletBalancesBalanceLock` in `@polkadot/types/lookup`.

# Test: Check if `PalletBalancesBalanceLock` is exported from `@polkadot/types/lookup`.
rg --type ts 'PalletBalancesBalanceLock' | rg '@polkadot/types/lookup'

Length of output: 367


Script:

#!/bin/bash
# Description: Check if `PalletBalancesBalanceLock` exists in the `@polkadot/types/lookup` package.

# Search for the definition or export of `PalletBalancesBalanceLock` in the package.
rg 'PalletBalancesBalanceLock' $(fd 'lookup' | grep '@polkadot/types')

Length of output: 495

Tools
GitHub Check: build

[failure] 4-4:
Module '"@polkadot/types/lookup"' has no exported member 'PalletBalancesBalanceLock'.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9df8f16 and 3357cd8.

Files selected for processing (9)
  • packages/extension-polkagate/src/fullscreen/accountDetails/components/LockedInReferendaFS.tsx (4 hunks)
  • packages/extension-polkagate/src/fullscreen/accountDetails/components/index.ts (1 hunks)
  • packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx (7 hunks)
  • packages/extension-polkagate/src/hooks/index.ts (1 hunks)
  • packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx (1 hunks)
  • packages/extension-polkagate/src/popup/account/Others.tsx (3 hunks)
  • packages/extension-polkagate/src/popup/account/index.tsx (1 hunks)
  • packages/extension-polkagate/src/popup/account/unlock/LockedInReferenda.tsx (4 hunks)
  • packages/extension-polkagate/src/popup/staking/solo/index.tsx (3 hunks)
Files skipped from review due to trivial changes (2)
  • packages/extension-polkagate/src/popup/account/Others.tsx
  • packages/extension-polkagate/src/popup/staking/solo/index.tsx
Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx
Additional context used
GitHub Check: build
packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx

[failure] 4-4:
Module '"@polkadot/types/lookup"' has no exported member 'PalletBalancesBalanceLock'.

Additional comments not posted (10)
packages/extension-polkagate/src/fullscreen/accountDetails/components/index.ts (1)

10-10: Export Update: Consider the impact of replacing LockedBalanceDisplay.

The export replacement of LockedBalanceDisplay with LockedInReferendaFS suggests a functional shift. Ensure that all dependent components or modules are updated to use LockedInReferendaFS where necessary.

packages/extension-polkagate/src/popup/account/unlock/LockedInReferenda.tsx (2)

Line range hint 64-82: Sorting Logic: Ensure stability and correctness.

The sorting logic for referendaLocks is crucial for determining the biggest vote. Ensure the sort function is stable and correctly prioritizes locks.

Verification successful

Sorting Logic Verified: Stability and Correctness Ensured

The sorting logic for referendaLocks is implemented in the useTimeToUnlock function, where locks are sorted by total and endBlock in descending order. This ensures that the biggest vote is correctly prioritized. The logic appears stable and correct as per the criteria mentioned.

  • File: packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx
  • Relevant Code:
    referendaLocks.sort((a, b) => {
      if (a.total.gt(b.total)) {
        return -1;
      }
      if (a.total.lt(b.total)) {
        return 1;
      }
      return a.endBlock.gt(b.endBlock) ? -1 : 1;
    });
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the sorting logic for `referendaLocks`.

# Test: Check if the sorting logic is stable and correctly implemented.
ast-grep --lang typescript --pattern $'referendaLocks.sort((a, b) => { $$$ })'

Length of output: 79


Script:

#!/bin/bash
# Search for any usage of `referendaLocks` in the codebase to identify sorting logic or relevant operations.
rg 'referendaLocks' -A 5

Length of output: 9532


35-39: Improved State Management: Verify hook functionality.

The introduction of useInfo, useTokenPrice, and useTimeToUnlock hooks simplifies state management. Ensure these hooks are functioning correctly and efficiently.

Verification successful

Hook Implementations and Usage Verified

The hooks useInfo, useTokenPrice, and useTimeToUnlock are defined and used across multiple files in the codebase. They are imported from a central hooks directory, indicating they are custom hooks likely defined within this project. The implementations are as follows:

  • useInfo: Defined in useInfo.ts and used extensively across various components to retrieve account and chain information.
  • useTokenPrice: Defined in useTokenPrice.ts and used to fetch token price information.
  • useTimeToUnlock: Defined in useTimeToUnlock.tsx and used to calculate time-related unlocking data.

These hooks are correctly implemented and imported, ensuring they function as intended in managing state efficiently across the application.

  • Files of interest include:
    • packages/extension-polkagate/src/hooks/useInfo.ts
    • packages/extension-polkagate/src/hooks/useTokenPrice.ts
    • packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the `useInfo`, `useTokenPrice`, and `useTimeToUnlock` hooks.

# Test: Search for the implementations of these hooks to ensure they are correctly defined.
ast-grep --lang typescript --pattern 'function useInfo($_) { $$$ }'
ast-grep --lang typescript --pattern 'function useTokenPrice($_) { $$$ }'
ast-grep --lang typescript --pattern 'function useTimeToUnlock($_) { $$$ }'

Length of output: 223


Script:

#!/bin/bash
# Description: Search for the implementations of the `useInfo`, `useTokenPrice`, and `useTimeToUnlock` hooks with adjusted patterns.

# Search for the useInfo hook
ast-grep --lang typescript --pattern 'const useInfo = ($_: any) => { $$$ }'

# Search for the useTokenPrice hook
ast-grep --lang typescript --pattern 'const useTokenPrice = ($_: any) => { $$$ }'

# Search for the useTimeToUnlock hook
ast-grep --lang typescript --pattern 'const useTimeToUnlock = ($_: any) => { $$$ }'

Length of output: 247


Script:

#!/bin/bash
# Description: Search for import statements and alternative patterns for the hooks.

# Search for import statements of the hooks
rg 'import { useInfo }' -A 2
rg 'import { useTokenPrice }' -A 2
rg 'import { useTimeToUnlock }' -A 2

# Search for hooks defined with different patterns
ast-grep --lang typescript --pattern 'export function useInfo($_) { $$$ }'
ast-grep --lang typescript --pattern 'export function useTokenPrice($_) { $$$ }'
ast-grep --lang typescript --pattern 'export function useTimeToUnlock($_) { $$$ }'

Length of output: 695


Script:

#!/bin/bash
# Description: Correct the regex syntax and search for mentions of the hooks in the codebase.

# Corrected search for import statements of the hooks
rg 'import.*useInfo' -A 2
rg 'import.*useTokenPrice' -A 2
rg 'import.*useTimeToUnlock' -A 2

# Search for any mention of the hooks in the codebase
rg 'useInfo'
rg 'useTokenPrice'
rg 'useTimeToUnlock'

Length of output: 95560

packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx (2)

27-31: Use of biggestOngoingLock: Ensure correctness.

The biggestOngoingLock function is used to determine the largest ongoing lock. Ensure this logic accurately reflects the intended functionality.

Verification successful

Use of biggestOngoingLock is Correct

The biggestOngoingLock function is implemented and used correctly in the codebase. It accurately determines the largest ongoing lock by checking for locks with an endBlock equal to BN_MAX_INTEGER and is used appropriately in the logic to compare against biggestVote. No issues were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `biggestOngoingLock`.

# Test: Check if `biggestOngoingLock` is correctly implemented and used.
ast-grep --lang typescript --pattern $'const biggestOngoingLock = useCallback(($$$) => { $$$ })'

Length of output: 97


Script:

#!/bin/bash
# Search for the definition of `biggestOngoingLock` in the codebase
rg 'const biggestOngoingLock = useCallback' -A 5

# Search for all usages of `biggestOngoingLock` in the codebase
rg 'biggestOngoingLock'

Length of output: 1060


112-127: API Query Logic: Confirm balance lock retrieval.

Ensure that the API query for balance locks is correctly implemented and retrieves the expected data.

Verification successful

API Query Logic Verified: Balance lock retrieval is correctly implemented.

The API query for balance locks is present and correctly implemented in the useTimeToUnlock.tsx file. The logic checks for locks and retrieves the expected data based on the specified conditions.

  • Verified in packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the API query for balance locks.

# Test: Ensure the API query for `balances.locks` is correctly implemented.
ast-grep --lang typescript --pattern $'api.query[\'balances\'][\'locks\']($_).then(($$) => { $$$ })'

Length of output: 109


Script:

#!/bin/bash
# Use ripgrep to search for the specific API query pattern in the codebase.
rg "api\.query\['balances'\]\['locks'\]" -A 5

Length of output: 662

packages/extension-polkagate/src/fullscreen/accountDetails/components/LockedInReferendaFS.tsx (3)

30-30: Component renaming is appropriate.

Renaming the component to LockedInReferendaFS aligns with its purpose of displaying locked referenda information. Ensure that all references to the old component name have been updated.


15-18: Ensure correct usage of hooks.

The useInfo hook now provides decimal and token directly, which simplifies the component. Ensure that useInfo is correctly returning these values for all possible address inputs.

Verification successful

The useInfo hook correctly returns decimal and token. The useInfo function includes both decimal and token in its return statement, ensuring these values are provided for all address inputs. This satisfies the review comment's requirement.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the `useInfo` hook returns `decimal` and `token` correctly for all addresses.

# Test: Search for the `useInfo` hook implementation. Expect: `decimal` and `token` are returned correctly.
ast-grep --lang typescript --pattern $'function useInfo($_) {
  $$$
  return { api, decimal, token, $$$ }
}'

Length of output: 109


Script:

#!/bin/bash
# Search for the implementation of the `useInfo` hook in the codebase.
ast-grep --lang typescript --pattern 'function useInfo($$$) {
  $$$
}' --json

# If the above does not yield results, search for any function named `useInfo`.
rg 'function useInfo' -A 10

Length of output: 1053


Script:

#!/bin/bash
# Extract the full return statement of the `useInfo` function to verify the inclusion of `decimal` and `token`.
rg 'return useMemo' -A 10 packages/extension-polkagate/src/hooks/useInfo.ts

Length of output: 339


38-38: Consider edge cases for unlocking logic.

The useTimeToUnlock hook is used to manage unlocking logic. Consider edge cases where referendaLocks might be empty or undefined, and ensure these are handled gracefully.

Verification successful

Edge cases for unlocking logic are handled.

The useTimeToUnlock function addresses edge cases where referendaLocks might be null, undefined, or empty, ensuring graceful handling of these scenarios by setting appropriate states.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `useTimeToUnlock` handles edge cases where `referendaLocks` is empty or undefined.

# Test: Search for the `useTimeToUnlock` hook implementation. Expect: Proper handling of empty or undefined `referendaLocks`.
ast-grep --lang typescript --pattern $'function useTimeToUnlock($_, referendaLocks, $$$) {
  if (referendaLocks === undefined || referendaLocks.length === 0) {
    $$$
  }
  $$$
}'

Length of output: 181


Script:

#!/bin/bash
# Description: Locate the implementation of the `useTimeToUnlock` hook to verify its handling of edge cases.

# Search for the implementation of `useTimeToUnlock` in the codebase.
rg 'function useTimeToUnlock' -A 20

Length of output: 2259


Script:

#!/bin/bash
# Description: Extract the full implementation of the `useTimeToUnlock` function to analyze its logic.

# Search for the full implementation of `useTimeToUnlock` in the codebase.
rg 'export default function useTimeToUnlock' -A 50 packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx

Length of output: 1765

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

99-99: New hook export: useTimeToUnlock.

The addition of useTimeToUnlock to the exports is appropriate, expanding the module's functionality. Ensure that this hook is implemented correctly and used consistently across the codebase.

packages/extension-polkagate/src/popup/account/index.tsx (1)

242-249: Simplify conditional rendering logic.

The use of logical AND (&&) for conditional rendering improves readability. Ensure that the conditions for displaying staking labels are correctly evaluated.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3357cd8 and a2d7983.

Files selected for processing (1)
  • packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a2d7983 and 13ac15d.

Files selected for processing (1)
  • packages/extension-polkagate/src/hooks/index.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/extension-polkagate/src/hooks/index.ts

@Nick-1979 Nick-1979 merged commit d73d625 into main Aug 18, 2024
3 checks passed
@Nick-1979 Nick-1979 deleted the closes#1071 branch September 15, 2024 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong transferable balance
2 participants