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: wrong vote type issue #1624

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -444,52 +444,60 @@ 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';
}

return 'no';
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved
};

// 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: [{ decision: voteInformation(proposer) }]
} as unknown as CommentType));
user_id: author.cid,
username: '',
votes: decision ? [{ decision }] : []
} as unknown as CommentType;
});
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved

return formattedComments;
} catch (error) {
Expand Down
Loading