From 9e661d9a824139c3c55bd2698bdbf7bf62845c92 Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Fri, 27 Oct 2023 13:37:55 +0200 Subject: [PATCH] f --- .../src/components/card/CardVote/CardVote.tsx | 3 +- .../components/directory/DirectoryInfo.tsx | 31 ++++++++++++++++--- .../DApp/src/helpers/receiveWakuFeature.ts | 21 +++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/packages/DApp/src/components/card/CardVote/CardVote.tsx b/packages/DApp/src/components/card/CardVote/CardVote.tsx index eb63e50..1d0349b 100644 --- a/packages/DApp/src/components/card/CardVote/CardVote.tsx +++ b/packages/DApp/src/components/card/CardVote/CardVote.tsx @@ -168,7 +168,8 @@ export const CardVote = ({ room, hideModalFunction }: CardVoteProps) => { )} {Boolean(winner) && ( - finalizeVoting.send(room.roomNumber)} disabled={!account}> + // note: @jkbktl PR + finalizeVoting.send(room.roomNumber, 1)} disabled={!account}> Finalize the vote ✍️ )} diff --git a/packages/DApp/src/components/directory/DirectoryInfo.tsx b/packages/DApp/src/components/directory/DirectoryInfo.tsx index 7c87148..ceeb986 100644 --- a/packages/DApp/src/components/directory/DirectoryInfo.tsx +++ b/packages/DApp/src/components/directory/DirectoryInfo.tsx @@ -6,11 +6,18 @@ import { ProposeButton } from '../Button' import { useFeaturedVotes } from '../../hooks/useFeaturedVotes' import { getFeaturedVotingState } from '../../helpers/featuredVoting' import { useContracts } from '../../hooks/useContracts' +import { useWaku } from '../../providers/waku/provider' +import { mapFeaturesVotes, receiveWakuFeature } from '../../helpers/receiveWakuFeature' +import { config } from '../../config' +import { useTypedFeatureVote } from '../../hooks/useTypedFeatureVote' export function DirectoryInfo() { const { account } = useEthers() const { featuredVotingContract } = useContracts() - const { activeVoting, votesToSend } = useFeaturedVotes() + const { getTypedFeatureVote } = useTypedFeatureVote() + const { activeVoting } = useFeaturedVotes() + const { waku } = useWaku() + const featuredVotingState = getFeaturedVotingState(activeVoting) const castVotes = useContractFunction(featuredVotingContract, 'castVotes') const finalizeVoting = useContractFunction(featuredVotingContract, 'finalizeVoting') @@ -19,15 +26,31 @@ export function DirectoryInfo() { {!account && } {account && featuredVotingState === 'verification' && ( - castVotes.send(votesToSend)}>Verify Weekly featured + { + const { votesToSend } = await receiveWakuFeature(waku, config.wakuConfig.wakuFeatureTopic, activeVoting!) + const votes = mapFeaturesVotes(votesToSend, getTypedFeatureVote) + + await castVotes.send(votes) + }} + > + Verify Weekly featured + )} {account && featuredVotingState === 'ended' && ( - finalizeVoting.send()}>Finalize Weekly featured + { + // note: @jkbktl PR + await finalizeVoting.send(activeVoting?.evaluatingPos) + }} + > + Finalize Weekly featured + )} ) diff --git a/packages/DApp/src/helpers/receiveWakuFeature.ts b/packages/DApp/src/helpers/receiveWakuFeature.ts index bca46c6..1d6b43b 100644 --- a/packages/DApp/src/helpers/receiveWakuFeature.ts +++ b/packages/DApp/src/helpers/receiveWakuFeature.ts @@ -75,6 +75,27 @@ export async function receiveWakuFeature(waku: WakuLight | undefined, topic: str return { votes: featureVotes, votesToSend: validatedMessages } } +// note: copy of filterVerifiedFeaturesVotes() +export function mapFeaturesVotes( + messages: WakuFeatureData[] | undefined, + getTypedData: (data: [string, string, BigNumber, BigNumber]) => TypedFeature +) { + if (!messages) { + return [] + } + const votes: [string, string, BigNumber, BigNumber, string, string][] = [] + + messages.forEach((msg) => { + const params = getContractParameters(msg.voter, msg.community, msg.sntAmount.toNumber(), msg.timestamp) + + if (utils.getAddress(recoverAddress(getTypedData(params), msg.sign)) == msg.voter) { + const splitSig = utils.splitSignature(msg.sign) + votes.push([...params, splitSig.r, splitSig._vs]) + } + }) + return votes +} + export async function filterVerifiedFeaturesVotes( messages: WakuFeatureData[] | undefined, alreadyVoted: AlreadyVoted,