This commit is contained in:
parent
e1a17d18c8
commit
9e661d9a82
|
@ -168,7 +168,8 @@ export const CardVote = ({ room, hideModalFunction }: CardVoteProps) => {
|
||||||
</VoteBtnFinal>
|
</VoteBtnFinal>
|
||||||
)}
|
)}
|
||||||
{Boolean(winner) && (
|
{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>
|
Finalize the vote <span>✍️</span>
|
||||||
</VoteBtnFinal>
|
</VoteBtnFinal>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -6,11 +6,18 @@ import { ProposeButton } from '../Button'
|
||||||
import { useFeaturedVotes } from '../../hooks/useFeaturedVotes'
|
import { useFeaturedVotes } from '../../hooks/useFeaturedVotes'
|
||||||
import { getFeaturedVotingState } from '../../helpers/featuredVoting'
|
import { getFeaturedVotingState } from '../../helpers/featuredVoting'
|
||||||
import { useContracts } from '../../hooks/useContracts'
|
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() {
|
export function DirectoryInfo() {
|
||||||
const { account } = useEthers()
|
const { account } = useEthers()
|
||||||
const { featuredVotingContract } = useContracts()
|
const { featuredVotingContract } = useContracts()
|
||||||
const { activeVoting, votesToSend } = useFeaturedVotes()
|
const { getTypedFeatureVote } = useTypedFeatureVote()
|
||||||
|
const { activeVoting } = useFeaturedVotes()
|
||||||
|
const { waku } = useWaku()
|
||||||
|
|
||||||
const featuredVotingState = getFeaturedVotingState(activeVoting)
|
const featuredVotingState = getFeaturedVotingState(activeVoting)
|
||||||
const castVotes = useContractFunction(featuredVotingContract, 'castVotes')
|
const castVotes = useContractFunction(featuredVotingContract, 'castVotes')
|
||||||
const finalizeVoting = useContractFunction(featuredVotingContract, 'finalizeVoting')
|
const finalizeVoting = useContractFunction(featuredVotingContract, 'finalizeVoting')
|
||||||
|
@ -24,10 +31,26 @@ export function DirectoryInfo() {
|
||||||
/>
|
/>
|
||||||
{!account && <ConnectButton />}
|
{!account && <ConnectButton />}
|
||||||
{account && featuredVotingState === 'verification' && (
|
{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' && (
|
{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>
|
</InfoWrap>
|
||||||
)
|
)
|
||||||
|
|
|
@ -75,6 +75,27 @@ export async function receiveWakuFeature(waku: WakuLight | undefined, topic: str
|
||||||
return { votes: featureVotes, votesToSend: validatedMessages }
|
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(
|
export async function filterVerifiedFeaturesVotes(
|
||||||
messages: WakuFeatureData[] | undefined,
|
messages: WakuFeatureData[] | undefined,
|
||||||
alreadyVoted: AlreadyVoted,
|
alreadyVoted: AlreadyVoted,
|
||||||
|
|
Loading…
Reference in New Issue