61-featured-communities-list-is-wrong (#87)
* u * a * u * f * Update FeatureModal.tsx
This commit is contained in:
parent
10cfa07bd7
commit
4f5651871b
|
@ -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>
|
||||
)}
|
||||
|
|
|
@ -36,6 +36,7 @@ export function FeatureModal({ community, setShowConfirmModal }: FeatureModalPro
|
|||
} else {
|
||||
await sendWaku(proposingAmount, community.publicKey)
|
||||
}
|
||||
|
||||
setShowConfirmModal(true)
|
||||
}}
|
||||
>
|
||||
|
|
|
@ -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>
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -12,6 +12,9 @@ export type VotingRoom = {
|
|||
totalVotesFor: BigNumber
|
||||
totalVotesAgainst: BigNumber
|
||||
roomNumber: number
|
||||
endBlock: BigNumber
|
||||
evaluatingPos: number
|
||||
evaluated: boolean
|
||||
}
|
||||
|
||||
export type DetailedVotingRoom = VotingRoom & { details: CommunityDetail }
|
||||
|
@ -23,4 +26,5 @@ export type FeaturedVoting = {
|
|||
endAt: BigNumber
|
||||
verificationStartAt: BigNumber
|
||||
finalized: boolean
|
||||
evaluatingPos: number
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@ describe('voting', () => {
|
|||
totalVotesFor: BigNumber.from(100),
|
||||
totalVotesAgainst: BigNumber.from(100),
|
||||
roomNumber: 1,
|
||||
endBlock: BigNumber.from(0),
|
||||
evaluatingPos: 0,
|
||||
evaluated: false,
|
||||
}
|
||||
const room = voting.fromRoom(votingRoom)
|
||||
|
||||
|
@ -36,6 +39,9 @@ describe('voting', () => {
|
|||
totalVotesFor: BigNumber.from(1000),
|
||||
totalVotesAgainst: BigNumber.from(100),
|
||||
roomNumber: 1,
|
||||
endBlock: BigNumber.from(0),
|
||||
evaluatingPos: 0,
|
||||
evaluated: false,
|
||||
}
|
||||
const room = voting.fromRoom(votingRoom)
|
||||
|
||||
|
|
Loading…
Reference in New Issue