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: referenda tracks Max #1591

Merged
merged 2 commits into from
Oct 21, 2024
Merged

fix: referenda tracks Max #1591

merged 2 commits into from
Oct 21, 2024

Conversation

Nick-1979
Copy link
Member

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

closes #1590

Summary by CodeRabbit

  • New Features

    • Enhanced governance track definitions for Kusama and Polkadot, improving clarity and accuracy.
    • Introduced a new useInfo hook to streamline data retrieval across multiple components.
  • Bug Fixes

    • Improved error handling in the useDecidingCount hook to log errors more effectively.
  • Documentation

    • Updated comments and descriptions for roles and spending limits in governance tracks.
  • Refactor

    • Consolidated multiple hooks into useInfo for better efficiency and type safety.
    • Adjusted component structure and logic in TrackStats for enhanced type safety and clarity.
    • Updated import statements and function signatures for improved clarity and maintainability.
  • Style

    • Minor formatting improvements in function signatures for consistency.

@Nick-1979 Nick-1979 self-assigned this Oct 19, 2024
@Nick-1979 Nick-1979 requested a review from AMIRKHANEF October 19, 2024 07:10
Copy link
Contributor

coderabbitai bot commented Oct 19, 2024

Walkthrough

The pull request introduces several modifications across multiple files, primarily focusing on enhancing type safety, improving function logic, and consolidating hooks. Key changes include the introduction of the useInfo hook to replace useApi and useChain, adjustments to type imports, and updates to function signatures. The governance structure for the Kusama and Polkadot tracks has been clarified, particularly regarding spending limits. Overall, these changes aim to streamline data handling and improve the clarity and maintainability of the codebase.

Changes

File Path Change Summary
packages/extension-polkagate/src/fullscreen/governance/TrackStats.tsx - Updated type imports and function signatures for findItemDecidingCount and LabelValue.
- Introduced useInfo hook for data retrieval.
- Simplified logic for chainGovInfo.
packages/extension-polkagate/src/fullscreen/governance/tracks/kusama.ts - Maintained structure of kusama object while clarifying spending limits in text properties for various roles.
packages/extension-polkagate/src/fullscreen/governance/tracks/polkadot.ts - Removed // @ts-nocheck directive to enforce TypeScript checks.
- Defined SPEND_LIMITS object for various spending roles.
packages/extension-polkagate/src/fullscreen/governance/tracks/util.ts - Adjusted import statements and added type annotations.
- Minor formatting changes to function signatures.
packages/extension-polkagate/src/hooks/useDecidingCount.ts - Changed DecidingCount from a type alias to an interface.
- Updated internal logic for type safety and error handling.
packages/extension-polkagate/src/hooks/useTracks.ts - Replaced useApi and useChain with useInfo, streamlining data retrieval.

Assessment against linked issues

Objective Addressed Explanation
Origin able to spend up to 100,000 DOT from the treasury at once (#1590)

Possibly related PRs

Suggested labels

change requested

Suggested reviewers

  • AMIRKHANEF

Poem

In the code where rabbits play,
Changes hop in bright array.
Hooks now dance, types align,
Governance tracks, all will shine!
With each tweak, our code's a treat,
Hopping forward, can't be beat! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between aba4985 and ff3ba0b.

📒 Files selected for processing (2)
  • packages/extension-polkagate/src/fullscreen/governance/TrackStats.tsx (4 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/tracks/polkadot.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/extension-polkagate/src/fullscreen/governance/TrackStats.tsx
  • packages/extension-polkagate/src/fullscreen/governance/tracks/polkadot.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.

@Nick-1979 Nick-1979 added the bug Something isn't working label Oct 19, 2024
@Nick-1979 Nick-1979 added this to the Milestone 4 milestone Oct 19, 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: 5

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

13-16: Use of interface Instead of type

Changing DecidingCount from a type alias to an interface allows for future extension and consistency with other interface definitions.

No action required; this is acceptable as per TypeScript best practices.

packages/extension-polkagate/src/fullscreen/governance/TrackStats.tsx (3)

Line range hint 43-60: Ensure safe type casting in 'LabelValue' component

In the LabelValue component, the value prop is typed as unknown and then cast to string or number. Consider adding type guards or validations to ensure value is of the expected type before casting. This will enhance type safety and prevent potential runtime errors.


72-72: Handle unexpected 'token' values in 'chainGovInfo' determination

The logic for chainGovInfo uses token === 'KSM' ? kusama : polkadot, which defaults to Polkadot tracks when the token is not 'KSM'. Consider adding explicit handling or error checking for unexpected token values to ensure the application behaves correctly even if token is neither 'KSM' nor 'DOT'.


100-100: Avoid unnecessary type casting in 'Remaining Slots' calculation

In the calculation of "Remaining Slots", there are multiple casts using as unknown as number. If track[1].maxDeciding is already of type number, these casts are unnecessary. Consider ensuring that maxDeciding is correctly typed to eliminate redundant casting and improve code clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 55b5e19 and aba4985.

📒 Files selected for processing (6)
  • packages/extension-polkagate/src/fullscreen/governance/TrackStats.tsx (4 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/tracks/kusama.ts (0 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/tracks/polkadot.ts (0 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/tracks/util.ts (2 hunks)
  • packages/extension-polkagate/src/hooks/useDecidingCount.ts (2 hunks)
  • packages/extension-polkagate/src/hooks/useTracks.ts (2 hunks)
💤 Files with no reviewable changes (2)
  • packages/extension-polkagate/src/fullscreen/governance/tracks/kusama.ts
  • packages/extension-polkagate/src/fullscreen/governance/tracks/polkadot.ts
🧰 Additional context used
🔇 Additional comments (14)
packages/extension-polkagate/src/fullscreen/governance/tracks/util.ts (4)

4-6: LGTM: Improved type safety for BN import

The explicit typing of the BN import enhances type safety and code clarity. This change is a good practice and aligns with TypeScript best practices.


15-15: LGTM: Consistent formatting applied

The addition of a space before the opening parenthesis in the function declaration is a minor formatting change that improves consistency with the coding style used elsewhere in the file.


23-23: LGTM: Consistent formatting applied

The addition of a space before the opening parenthesis in the function declaration is a minor formatting change that improves consistency with the coding style used elsewhere in the file.


Line range hint 1-26: Summary: Minor improvements, but PR objectives not fully addressed

The changes in this file improve type safety and maintain consistent formatting, which are positive improvements to code quality. However, these changes don't directly address the stated PR objective of fixing the incorrect maximum spending for referenda tracks in Polkadot (issue #1590).

To ensure we're not missing any relevant changes, let's check for any modifications to spending-related logic in the codebase:

If these searches don't yield relevant results, it might be worth discussing with the PR author how the changes in this file relate to the stated objective of fixing the referenda tracks max spending issue.

✅ Verification successful

Changes do not address the maximum spending issue

The modifications in util.ts improve type safety and maintain consistent formatting but do not address the incorrect maximum spending for referenda tracks as intended by the PR objective (issue #1590).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for changes related to spending limits or treasury functionality

# Test 1: Look for changes to spending-related functions or variables
echo "Searching for spending-related changes:"
rg --type typescript -e 'spend|treasury|referenda.*max' -g '!**/util.ts'

# Test 2: Check for any new or modified constants related to spending limits
echo "Searching for spending limit constants:"
rg --type typescript -e 'const.*spend|const.*treasury|const.*referenda' -g '!**/util.ts'

Length of output: 413


Script:

#!/bin/bash
# Description: Search for changes related to spending limits or treasury functionality with adjusted file patterns

# Test 1: Look for changes to spending-related functions or variables
echo "Searching for spending-related changes:"
rg -g "*.ts" -e 'spend|treasury|referenda.*max'

# Test 2: Check for any new or modified constants related to spending limits
echo "Searching for spending limit constants:"
rg -g "*.ts" -e 'const.*spend|const.*treasury|const.*referenda'

Length of output: 4311

packages/extension-polkagate/src/hooks/useTracks.ts (2)

13-13: Approve the function body changes.

The modifications to the function body are appropriate and maintain the existing functionality:

  1. Line 13: Correctly destructures api and chain from the new useInfo hook.
  2. Line 29: Simplifies the return statement without changing its behavior.

These changes align well with the new hook usage and improve code readability.

Also applies to: 29-29


Line range hint 1-29: Overall impact is positive, but clarification needed on issue resolution.

The changes in this file represent a positive refactoring step:

  1. Consolidation of hooks improves maintainability.
  2. The core functionality of useTracks is preserved.
  3. The code is slightly more concise and readable.

However, it's not immediately clear how these changes address the issue of incorrect maximum spending for referenda tracks in Polkadot (issue #1590).

Could you please clarify:

  1. How do these changes in useTracks contribute to fixing the maximum spending limit issue?
  2. Are there other files in this PR that more directly address the spending limit problem?

To help verify this, you could run the following script to search for relevant changes in other files:

#!/bin/bash
# Description: Search for changes related to spending limits in other files

echo "Searching for files with changes related to spending limits:"
rg --type typescript -i 'spend(ing)?.*limit|treasury.*spend'

echo "Searching for files with changes related to referenda tracks:"
rg --type typescript -i 'referenda.*tracks?|tracks?.*referenda'

This will help identify if the spending limit issue is addressed in other parts of the codebase.

packages/extension-polkagate/src/hooks/useDecidingCount.ts (4)

6-6: Ensure Type Annotations and Imports are Necessary

The import of u32 from '@polkadot/types' is acceptable if u32 is used in type annotations within this file. Ensure that all imported types are utilized to maintain clean and efficient code.


8-9: Consolidate Hooks with useInfo

The replacement of useApi and useChain with useInfo simplifies the retrieval of api and chain. This enhances code readability and reduces the number of dependencies.


19-19: Destructure api and chain Using useInfo

Destructuring api and chain directly from useInfo(address) improves code clarity by consolidating related data retrieval.


83-83: Good Practice: Handle Promise Rejections with .catch

Adding .catch(console.error) to fetchDecidingCounts() ensures that unhandled promise rejections are caught and logged, preventing potential crashes.

packages/extension-polkagate/src/fullscreen/governance/TrackStats.tsx (4)

21-21: Appropriate import of Polkadot governance tracks

By importing { polkadot } from './tracks/polkadot', the code now correctly includes the governance tracks for Polkadot. This aligns with the PR objective to fix the referenda tracks' maximum spending limit on the Polkadot network.


31-40: Confirm 'decidingCounts' type change and usage

The function findItemDecidingCount now accepts decidingCounts as DecidingCount | undefined instead of an array. Please verify that all instances where decidingCounts is passed to this function have been updated accordingly and that the new structure with referenda and fellowship properties is consistent throughout the codebase to prevent runtime errors.


70-70: Efficient consolidation of hooks into 'useInfo'

Replacing multiple hooks (useApi, useDecimal, useToken) with useInfo(address) simplifies the code and improves readability by consolidating related data retrieval into a single hook.


92-92: Verify correct retrieval of track descriptions

Ensure that the expression chainGovInfo[topMenu.toLocaleLowerCase()].find(({ name }) => name === snakeCaseTrackName)?.text accurately retrieves the track description. This will confirm that users see the correct information for each track, which is especially important after updating the governance structures.

@Nick-1979 Nick-1979 merged commit 268a5eb into main Oct 21, 2024
8 checks passed
@Nick-1979 Nick-1979 deleted the fixTracksMax branch October 21, 2024 07:30
github-actions bot pushed a commit that referenced this pull request Oct 21, 2024
## [0.19.1](v0.19.0...v0.19.1) (2024-10-21)

### Bug Fixes

* referenda tracks Max ([#1591](#1591)) ([268a5eb](268a5eb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

referenda tracks Max spending is not correct for polkadot
2 participants