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: save update balances #1583

Merged
merged 2 commits into from
Oct 7, 2024
Merged

fix: save update balances #1583

merged 2 commits into from
Oct 7, 2024

Conversation

Nick-1979
Copy link
Member

@Nick-1979 Nick-1979 commented Oct 6, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced balance validation by integrating a check for up-to-date asset balances.
  • Improvements

    • Made the isUpToDate function publicly accessible for broader use across the application.
    • Refined the logic for managing overall balance state to ensure only current balances are considered valid.

Copy link
Contributor

coderabbitai bot commented Oct 6, 2024

Walkthrough

The pull request introduces changes to two files within the extension-polkagate package. The isUpToDate function in useAssetsBalances.ts has been made public by adding the export keyword, enhancing its accessibility. In useBalances.ts, the isUpToDate function is imported and integrated into the useEffect hook, modifying the logic to ensure that only up-to-date balances are considered valid for updating the overall balance state.

Changes

File Path Change Summary
packages/extension-polkagate/src/hooks/useAssetsBalances.ts Changed isUpToDate function visibility from private to public by adding export.
packages/extension-polkagate/src/hooks/useBalances.ts Imported isUpToDate and integrated it into the useEffect hook for validating balance data.

Possibly related PRs

  • feat: add Polkadot as currency #1581: The changes in the useBalances.ts file utilize the isUpToDate function from useAssetsBalances.ts, which is directly related to the main PR's modification of the isUpToDate function's visibility.

Suggested reviewers

  • AMIRKHANEF

Poem

In the land of assets, where balances sway,
A function named isUpToDate found its way.
With a hop and a skip, it now shines bright,
Validating balances, making things right.
So let’s cheer for changes, both big and small,
For a rabbit’s keen eye sees the best of all! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0122d44 and e11f77e.

📒 Files selected for processing (1)
  • packages/extension-polkagate/src/hooks/useBalances.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/hooks/useBalances.ts

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

🧹 Outside diff range and nitpick comments (2)
packages/extension-polkagate/src/hooks/useBalances.ts (1)

Line range hint 37-43: Consider adding error handling for consistently out-of-date balances.

The addition of the isUpToDate check improves data reliability but might lead to fewer updates of the overall state if balances are not up-to-date. There's a potential edge case where overall might remain undefined for extended periods if balances are consistently out of date.

To improve debugging and user experience:

  1. Consider adding error logging when balances are consistently out of date.
  2. Implement a fallback mechanism or user notification for prolonged periods without updates.

Would you like assistance in implementing these suggestions?

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

106-106: Consider adding JSDoc for the exported isUpToDate function

Now that isUpToDate is exported and can be used in other parts of the application, it would be beneficial to add JSDoc comments to describe its purpose, parameters, and return value. This will help other developers understand how to use the function correctly.

Consider adding documentation like this:

/**
 * Checks if the given date is considered up-to-date based on a predefined validity period.
 * @param date - The timestamp to check, in milliseconds since the Unix epoch.
 * @returns A boolean indicating if the date is up-to-date, or undefined if no date was provided.
 */
export const isUpToDate = (date?: number): boolean | undefined => date ? Date.now() - date < BALANCE_VALIDITY_PERIOD : undefined;

Also, it's recommended to monitor the usage of this function in other parts of the codebase to ensure it's being used appropriately and doesn't lead to any inconsistencies in balance update logic across different components.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2aa580c and 0122d44.

📒 Files selected for processing (2)
  • packages/extension-polkagate/src/hooks/useAssetsBalances.ts (1 hunks)
  • packages/extension-polkagate/src/hooks/useBalances.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (4)
packages/extension-polkagate/src/hooks/useBalances.ts (3)

12-12: LGTM: New import statement for isUpToDate function.

The import of the isUpToDate function from './useAssetsBalances' is correctly implemented and aligns with the subsequent usage in the component.


37-37: Improved data reliability in useEffect hook.

The addition of isUpToDate(balances?.date) to the condition for setting the overall state enhances the reliability of the data used in the component. This change ensures that only up-to-date balances are considered when updating the state, which aligns with the PR objective of fixing the save update balances issue.

The existing checks for balances, pooledBalance, and matching genesisHash values are maintained, preserving the previous validations while adding this new layer of data freshness verification.


Line range hint 1-91: Summary: Improved balance update mechanism with potential for further enhancements.

The changes in this file successfully address the PR objective of fixing save update balances. The introduction of the isUpToDate check enhances data reliability by ensuring only current balances are used to update the overall state. This improvement aligns well with best practices for handling potentially stale data in financial applications.

While the modifications are generally positive, consider implementing the suggested error handling and logging mechanisms to further improve the robustness of the component, especially in scenarios where balances might be consistently out of date.

Overall, these changes represent a solid step forward in improving the accuracy and reliability of the balance management system.

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

106-106: Function isUpToDate is now exported

The isUpToDate function has been made public by adding the export keyword. This change allows the function to be used in other parts of the application.

To ensure this change doesn't introduce any unintended side effects, let's verify its usage across the codebase:

Copy link
Member

@AMIRKHANEF AMIRKHANEF left a comment

Choose a reason for hiding this comment

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

why onlyNew removed?
if removing the onlyNew was necessary it also should remove from the useEffect deps list.
image

@Nick-1979 Nick-1979 merged commit eccc18e into main Oct 7, 2024
8 checks passed
@Nick-1979 Nick-1979 deleted the saveNewBalances branch October 7, 2024 07:36
github-actions bot pushed a commit that referenced this pull request Oct 7, 2024
## [0.18.1](v0.18.0...v0.18.1) (2024-10-07)

### Bug Fixes

* save update balances ([#1583](#1583)) ([eccc18e](eccc18e))
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