-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
WalkthroughThe 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 Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 ofinterface
Instead oftype
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' componentIn the
LabelValue
component, thevalue
prop is typed asunknown
and then cast tostring
ornumber
. Consider adding type guards or validations to ensurevalue
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' determinationThe logic for
chainGovInfo
usestoken === 'KSM' ? kusama : polkadot
, which defaults to Polkadot tracks when the token is not'KSM'
. Consider adding explicit handling or error checking for unexpectedtoken
values to ensure the application behaves correctly even iftoken
is neither'KSM'
nor'DOT'
.
100-100
: Avoid unnecessary type casting in 'Remaining Slots' calculationIn the calculation of "Remaining Slots", there are multiple casts using
as unknown as number
. Iftrack[1].maxDeciding
is already of typenumber
, these casts are unnecessary. Consider ensuring thatmaxDeciding
is correctly typed to eliminate redundant casting and improve code clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 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 importThe 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 appliedThe 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 appliedThe 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 addressedThe 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:
- Line 13: Correctly destructures
api
andchain
from the newuseInfo
hook.- 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:
- Consolidation of hooks improves maintainability.
- The core functionality of
useTracks
is preserved.- 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:
- How do these changes in
useTracks
contribute to fixing the maximum spending limit issue?- 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 NecessaryThe import of
u32
from'@polkadot/types'
is acceptable ifu32
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 withuseInfo
The replacement of
useApi
anduseChain
withuseInfo
simplifies the retrieval ofapi
andchain
. This enhances code readability and reduces the number of dependencies.
19-19
: Destructureapi
andchain
UsinguseInfo
Destructuring
api
andchain
directly fromuseInfo(address)
improves code clarity by consolidating related data retrieval.
83-83
: Good Practice: Handle Promise Rejections with.catch
Adding
.catch(console.error)
tofetchDecidingCounts()
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 tracksBy 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 usageThe function
findItemDecidingCount
now acceptsdecidingCounts
asDecidingCount | undefined
instead of an array. Please verify that all instances wheredecidingCounts
is passed to this function have been updated accordingly and that the new structure withreferenda
andfellowship
properties is consistent throughout the codebase to prevent runtime errors.
70-70
: Efficient consolidation of hooks into 'useInfo'Replacing multiple hooks (
useApi
,useDecimal
,useToken
) withuseInfo(address)
simplifies the code and improves readability by consolidating related data retrieval into a single hook.
92-92
: Verify correct retrieval of track descriptionsEnsure 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.
## [0.19.1](v0.19.0...v0.19.1) (2024-10-21) ### Bug Fixes * referenda tracks Max ([#1591](#1591)) ([268a5eb](268a5eb))
closes #1590
Summary by CodeRabbit
New Features
useInfo
hook to streamline data retrieval across multiple components.Bug Fixes
useDecidingCount
hook to log errors more effectively.Documentation
Refactor
useInfo
for better efficiency and type safety.TrackStats
for enhanced type safety and clarity.Style