From fa70422829a3dd6051aad9ee2205056f33e35431 Mon Sep 17 00:00:00 2001 From: Amir Ekbatanifard Date: Sat, 2 Nov 2024 10:42:18 +0330 Subject: [PATCH 1/3] fix: wrong vote type issue --- .../src/fullscreen/governance/utils/helpers.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts b/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts index b15638857..8a8ab5595 100644 --- a/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts +++ b/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts @@ -444,14 +444,18 @@ export async function getReferendumCommentsSS (chainName: string, refId: string const votes = await votesResponse.json() as VoteSS[]; // Helper function to determine the vote decision - const voteInformation = (address: string): string => { + const voteInformation = (address: string): string | null => { const vote = votes.find(({ account }) => account === address); - if (vote?.aye) { + if (!vote) { + return null; + } + + if (vote.aye) { return 'yes'; } - if (!vote?.aye && (vote?.isSplit || vote?.isSplitAbstain)) { + if (!vote.aye && (vote.isSplit || vote.isSplitAbstain)) { return 'Abstain'; } @@ -488,7 +492,7 @@ export async function getReferendumCommentsSS (chainName: string, refId: string updated_at: updatedAt, user_id: author.cid, username: '', - votes: [{ decision: voteInformation(proposer) }] + votes: voteInformation(proposer) ? [{ decision: voteInformation(proposer) }] : [] } as unknown as CommentType)); return formattedComments; From 499adfd8a4db491a3cc4c9035339eb42484b9e68 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 2 Nov 2024 11:49:54 +0330 Subject: [PATCH 2/3] refactor: remove a duplicate call --- .../fullscreen/governance/utils/helpers.ts | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts b/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts index 8a8ab5595..e1738c01c 100644 --- a/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts +++ b/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts @@ -463,37 +463,41 @@ export async function getReferendumCommentsSS (chainName: string, refId: string }; // Format the comments - const formattedComments = comments.items.map(({ _id, author, content, createdAt, proposer, reactions, replies, updatedAt }) => ({ - commentSource: 'SS', - comment_reactions: { - '👍': { count: reactions.length, usernames: reactions.map((reaction) => reaction.user?.address ?? '') ?? null }, - '👎': { count: 0, usernames: undefined } // SubSquare does not display dislikes - }, - content, - created_at: createdAt, - id: _id, - proposer, - // Format replies - replies: replies.map(({ _id, cid, content, createdAt, proposer, reactions, updatedAt }) => ({ + const formattedComments = comments.items.map(({ _id, author, content, createdAt, proposer, reactions, replies, updatedAt }) => { + const decision = voteInformation(proposer); + + return { commentSource: 'SS', + comment_reactions: { + '👍': { count: reactions.length, usernames: reactions.map((reaction) => reaction.user?.address ?? '') ?? null }, + '👎': { count: 0, usernames: undefined } // SubSquare does not display dislikes + }, content, created_at: createdAt, id: _id, proposer, - reply_reactions: { - '👍': { count: reactions.length, usernames: reactions.map((reaction) => reaction.user?.address ?? '') ?? null }, - '👎': { count: 0, usernames: undefined } // SubSquare does not display dislikes - }, + // Format replies + replies: replies.map(({ _id, cid, content, createdAt, proposer, reactions, updatedAt }) => ({ + commentSource: 'SS', + content, + created_at: createdAt, + id: _id, + proposer, + reply_reactions: { + '👍': { count: reactions.length, usernames: reactions.map((reaction) => reaction.user?.address ?? '') ?? null }, + '👎': { count: 0, usernames: undefined } // SubSquare does not display dislikes + }, + updated_at: updatedAt, + user_id: cid, + username: '' + } as unknown as Reply)), + sentiment: 0, updated_at: updatedAt, - user_id: cid, - username: '' - } as unknown as Reply)), - sentiment: 0, - updated_at: updatedAt, - user_id: author.cid, - username: '', - votes: voteInformation(proposer) ? [{ decision: voteInformation(proposer) }] : [] - } as unknown as CommentType)); + user_id: author.cid, + username: '', + votes: decision ? [{ decision }] : [] + } as unknown as CommentType; + }); return formattedComments; } catch (error) { From f8d7718f87786c45fde695662651918cc3f8d6cb Mon Sep 17 00:00:00 2001 From: Amir Ekbatanifard Date: Sat, 2 Nov 2024 12:54:50 +0330 Subject: [PATCH 3/3] fix: abstain vote type issue --- .../src/fullscreen/governance/utils/helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts b/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts index e1738c01c..ed43695d6 100644 --- a/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts +++ b/packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts @@ -455,8 +455,8 @@ export async function getReferendumCommentsSS (chainName: string, refId: string return 'yes'; } - if (!vote.aye && (vote.isSplit || vote.isSplitAbstain)) { - return 'Abstain'; + if (vote.isSplit || vote.isSplitAbstain) { + return 'abstain'; } return 'no';