-
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: wrong vote type issue #1624
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Possibly related PRs
Poem
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts
(1 hunks)
🔇 Additional comments (1)
packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts (1)
466-500
: 🛠️ Refactor suggestion
Improve type safety and data handling in comment formatting.
Several improvements could be made to enhance type safety and clarity:
- The
as unknown as CommentType
type casting is unsafe and could hide type mismatches. - Empty username fields might indicate missing data.
- The hardcoded sentiment value (0) lacks documentation.
Consider these improvements:
- Define proper types instead of using type casting:
interface FormattedComment extends CommentType {
commentSource: string;
comment_reactions: {
[key: string]: {
count: number;
usernames: string[] | undefined;
};
};
// ... other required fields
}
- Simplify the reactions mapping:
- comment_reactions: {
- '👍': { count: reactions.length, usernames: reactions.map((reaction) => reaction.user?.address ?? '') ?? null },
- '👎': { count: 0, usernames: undefined }
- },
+ comment_reactions: {
+ '👍': {
+ count: reactions.length,
+ usernames: reactions.reduce<string[]>((acc, r) => r.user?.address ? [...acc, r.user.address] : acc, [])
+ },
+ '👎': { count: 0, usernames: undefined }
+ },
- Add documentation for the sentiment field:
sentiment: 0, // Default neutral sentiment, possible values: -1 (negative), 0 (neutral), 1 (positive)
Let's verify the CommentType
interface usage:
packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts
Outdated
Show resolved
Hide resolved
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts
(1 hunks)
🔇 Additional comments (2)
packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts (2)
447-452
: LGTM: Improved null handling with explicit return type.
The changes improve type safety by properly handling the case when no vote is found, using an early return pattern.
454-459
: LGTM: Improved vote type determination logic.
The implementation correctly determines vote types:
- 'yes' for aye votes
- 'abstain' for split votes
- 'no' as the default case
## [0.21.3](v0.21.2...v0.21.3) (2024-11-02) ### Bug Fixes * wrong vote type issue in comments ([#1624](#1624)) ([f398d16](f398d16))
Close: #1623
Summary by CodeRabbit
Bug Fixes
votes
property is only populated when valid vote information is available.New Features
null
returns when no vote is found.