This commit is contained in:
Felicio Mununga 2023-10-27 13:37:55 +02:00
parent e1a17d18c8
commit 9e661d9a82
No known key found for this signature in database
GPG Key ID: C4736C7AEBA55BE5
3 changed files with 50 additions and 5 deletions

View File

@ -168,7 +168,8 @@ export const CardVote = ({ room, hideModalFunction }: CardVoteProps) => {
</VoteBtnFinal>
)}
{Boolean(winner) && (
<VoteBtnFinal onClick={() => finalizeVoting.send(room.roomNumber)} disabled={!account}>
// note: @jkbktl PR
<VoteBtnFinal onClick={() => finalizeVoting.send(room.roomNumber, 1)} disabled={!account}>
Finalize the vote <span></span>
</VoteBtnFinal>
)}

View File

@ -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() {
<InfoWrap>
<PageInfo
heading="Current directory"
text="Vote on your favourite communities being included in
text="Vote on your favourite communities being included in
Weekly Featured Communities"
/>
{!account && <ConnectButton />}
{account && featuredVotingState === 'verification' && (
<ProposeButton onClick={() => castVotes.send(votesToSend)}>Verify Weekly featured</ProposeButton>
<ProposeButton
onClick={async () => {
const { votesToSend } = await receiveWakuFeature(waku, config.wakuConfig.wakuFeatureTopic, activeVoting!)
const votes = mapFeaturesVotes(votesToSend, getTypedFeatureVote)
await castVotes.send(votes)
}}
>
Verify Weekly featured
</ProposeButton>
)}
{account && featuredVotingState === 'ended' && (
<ProposeButton onClick={() => finalizeVoting.send()}>Finalize Weekly featured</ProposeButton>
<ProposeButton
onClick={async () => {
// note: @jkbktl PR
await finalizeVoting.send(activeVoting?.evaluatingPos)
}}
>
Finalize Weekly featured
</ProposeButton>
)}
</InfoWrap>
)

View File

@ -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,