Reverse list and ui fixes (#82)
This commit is contained in:
parent
cb9eaed607
commit
e3e608e922
|
@ -109,12 +109,13 @@ export class WakuVoting extends WakuMessaging {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return this.lastPolls
|
return this.lastPolls.slice().reverse()
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getVotingRoom(id: number) {
|
public async getVotingRoom(id: number) {
|
||||||
try {
|
try {
|
||||||
return (await this.getVotingRooms())[id]
|
await this.getVotingRooms()
|
||||||
|
return this.lastPolls[id]
|
||||||
} catch {
|
} catch {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,13 @@ export function Proposal({ wakuVoting, account }: ProposalProps) {
|
||||||
wakuVoting={wakuVoting}
|
wakuVoting={wakuVoting}
|
||||||
/>
|
/>
|
||||||
{votes.length > 0 && (
|
{votes.length > 0 && (
|
||||||
<ProposalList theme={blueTheme} wakuVoting={wakuVoting} votes={votes} availableAmount={tokenBalance} />
|
<ProposalList
|
||||||
|
account={account}
|
||||||
|
theme={blueTheme}
|
||||||
|
wakuVoting={wakuVoting}
|
||||||
|
votes={votes}
|
||||||
|
availableAmount={tokenBalance}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</ProposalVotesWrapper>
|
</ProposalVotesWrapper>
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,29 @@ interface ProposalCardProps {
|
||||||
hideModalFunction?: (val: boolean) => void
|
hideModalFunction?: (val: boolean) => void
|
||||||
availableAmount: number
|
availableAmount: number
|
||||||
wakuVoting: WakuVoting
|
wakuVoting: WakuVoting
|
||||||
|
account: string | null | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ProposalCard({ theme, votingRoom, mobileVersion, availableAmount, wakuVoting }: ProposalCardProps) {
|
export function ProposalCard({
|
||||||
|
account,
|
||||||
|
theme,
|
||||||
|
votingRoom,
|
||||||
|
mobileVersion,
|
||||||
|
availableAmount,
|
||||||
|
wakuVoting,
|
||||||
|
}: ProposalCardProps) {
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card onClick={() => mobileVersion && history.push(`/votingRoom/${votingRoom.id.toString()}`)}>
|
<Card onClick={() => mobileVersion && history.push(`/votingRoom/${votingRoom.id.toString()}`)}>
|
||||||
<ProposalInfo votingRoom={votingRoom} providerName={wakuVoting.providerName} />
|
<ProposalInfo votingRoom={votingRoom} providerName={wakuVoting.providerName} />
|
||||||
<ProposalVote votingRoom={votingRoom} theme={theme} availableAmount={availableAmount} wakuVoting={wakuVoting} />
|
<ProposalVote
|
||||||
|
votingRoom={votingRoom}
|
||||||
|
theme={theme}
|
||||||
|
availableAmount={availableAmount}
|
||||||
|
wakuVoting={wakuVoting}
|
||||||
|
account={account}
|
||||||
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,9 @@ type ProposalListProps = {
|
||||||
wakuVoting: WakuVoting
|
wakuVoting: WakuVoting
|
||||||
votes: VotingRoom[]
|
votes: VotingRoom[]
|
||||||
availableAmount: number
|
availableAmount: number
|
||||||
|
account: string | null | undefined
|
||||||
}
|
}
|
||||||
export function ProposalList({ theme, wakuVoting, votes, availableAmount }: ProposalListProps) {
|
export function ProposalList({ theme, wakuVoting, votes, availableAmount, account }: ProposalListProps) {
|
||||||
const ref = useRef<HTMLHeadingElement>(null)
|
const ref = useRef<HTMLHeadingElement>(null)
|
||||||
const mobileVersion = useMobileVersion(ref, 600)
|
const mobileVersion = useMobileVersion(ref, 600)
|
||||||
return (
|
return (
|
||||||
|
@ -20,6 +21,7 @@ export function ProposalList({ theme, wakuVoting, votes, availableAmount }: Prop
|
||||||
{votes.map((votingRoom) => {
|
{votes.map((votingRoom) => {
|
||||||
return (
|
return (
|
||||||
<ProposalCard
|
<ProposalCard
|
||||||
|
account={account}
|
||||||
votingRoom={votingRoom}
|
votingRoom={votingRoom}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
key={votingRoom.id}
|
key={votingRoom.id}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import { useEthers } from '@usedapp/core'
|
|
||||||
import { FinalBtn, VoteBtnAgainst, VoteBtnFor } from '../Buttons'
|
import { FinalBtn, VoteBtnAgainst, VoteBtnFor } from '../Buttons'
|
||||||
import { VoteSubmitButton } from './VoteSubmitButton'
|
import { VoteSubmitButton } from './VoteSubmitButton'
|
||||||
import { VoteChart } from './VoteChart'
|
import { VoteChart } from './VoteChart'
|
||||||
|
@ -18,14 +17,30 @@ interface ProposalVoteProps {
|
||||||
availableAmount: number
|
availableAmount: number
|
||||||
hideModalFunction?: (val: boolean) => void
|
hideModalFunction?: (val: boolean) => void
|
||||||
wakuVoting: WakuVoting
|
wakuVoting: WakuVoting
|
||||||
|
account: string | null | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ProposalVote({ votingRoom, theme, availableAmount, hideModalFunction, wakuVoting }: ProposalVoteProps) {
|
export function ProposalVote({
|
||||||
const { account } = useEthers()
|
account,
|
||||||
|
votingRoom,
|
||||||
|
theme,
|
||||||
|
availableAmount,
|
||||||
|
hideModalFunction,
|
||||||
|
wakuVoting,
|
||||||
|
}: ProposalVoteProps) {
|
||||||
const [showVoteModal, setShowVoteModal] = useState(false)
|
const [showVoteModal, setShowVoteModal] = useState(false)
|
||||||
const [showConfirmModal, setShowConfirmModal] = useState(false)
|
const [showConfirmModal, setShowConfirmModal] = useState(false)
|
||||||
const [proposingAmount, setProposingAmount] = useState(0)
|
const [proposingAmount, setProposingAmount] = useState(0)
|
||||||
const [selectedVoted, setSelectedVoted] = useState(0)
|
const [selectedVoted, setSelectedVoted] = useState(0)
|
||||||
|
const [alreadyVoted, setAlreadyVoted] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (votingRoom.voters.findIndex((e) => e === account) >= 0) {
|
||||||
|
setAlreadyVoted(true)
|
||||||
|
} else {
|
||||||
|
setAlreadyVoted(false)
|
||||||
|
}
|
||||||
|
}, [account, votingRoom])
|
||||||
|
|
||||||
const setNext = (val: boolean) => {
|
const setNext = (val: boolean) => {
|
||||||
setShowConfirmModal(val)
|
setShowConfirmModal(val)
|
||||||
|
@ -59,7 +74,7 @@ export function ProposalVote({ votingRoom, theme, availableAmount, hideModalFunc
|
||||||
{showConfirmModal && (
|
{showConfirmModal && (
|
||||||
<Modal heading={votingRoom.question} setShowModal={hideConfirm} theme={theme}>
|
<Modal heading={votingRoom.question} setShowModal={hideConfirm} theme={theme}>
|
||||||
<VoteAnimatedModal
|
<VoteAnimatedModal
|
||||||
votingRoom={modifiedVotingRoom ?? votingRoom}
|
votingRoom={votingRoom}
|
||||||
selectedVote={selectedVoted}
|
selectedVote={selectedVoted}
|
||||||
setShowModal={hideConfirm}
|
setShowModal={hideConfirm}
|
||||||
proposingAmount={proposingAmount}
|
proposingAmount={proposingAmount}
|
||||||
|
@ -80,7 +95,7 @@ export function ProposalVote({ votingRoom, theme, availableAmount, hideModalFunc
|
||||||
) : (
|
) : (
|
||||||
<VotesBtns>
|
<VotesBtns>
|
||||||
<VoteBtnAgainst
|
<VoteBtnAgainst
|
||||||
disabled={!account}
|
disabled={!account || alreadyVoted}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedVoted(0)
|
setSelectedVoted(0)
|
||||||
setShowVoteModal(true)
|
setShowVoteModal(true)
|
||||||
|
@ -89,7 +104,7 @@ export function ProposalVote({ votingRoom, theme, availableAmount, hideModalFunc
|
||||||
Vote Against
|
Vote Against
|
||||||
</VoteBtnAgainst>
|
</VoteBtnAgainst>
|
||||||
<VoteBtnFor
|
<VoteBtnFor
|
||||||
disabled={!account}
|
disabled={!account || alreadyVoted}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedVoted(1)
|
setSelectedVoted(1)
|
||||||
setShowVoteModal(true)
|
setShowVoteModal(true)
|
||||||
|
|
|
@ -29,7 +29,7 @@ export function VoteModal({
|
||||||
const disabled = proposingAmount === 0
|
const disabled = proposingAmount === 0
|
||||||
const funds = availableAmount > 0
|
const funds = availableAmount > 0
|
||||||
const onClick = useCallback(async () => {
|
const onClick = useCallback(async () => {
|
||||||
wakuVoting.sendVote(votingRoom.id, selectedVote, BigNumber.from(proposingAmount))
|
await wakuVoting.sendVote(votingRoom.id, selectedVote, BigNumber.from(proposingAmount))
|
||||||
setShowConfirmModal(true)
|
setShowConfirmModal(true)
|
||||||
}, [votingRoom, selectedVote, proposingAmount, wakuVoting])
|
}, [votingRoom, selectedVote, proposingAmount, wakuVoting])
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -11,22 +11,39 @@ export function useWakuProposal(
|
||||||
const [waku, setWaku] = useState<WakuVoting | undefined>(undefined)
|
const [waku, setWaku] = useState<WakuVoting | undefined>(undefined)
|
||||||
const queuePos = useRef(0)
|
const queuePos = useRef(0)
|
||||||
const queueSize = useRef(0)
|
const queueSize = useRef(0)
|
||||||
|
const [chainId, setChainId] = useState(0)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const updateChainId = async () => {
|
||||||
|
const network = await provider?.getNetwork()
|
||||||
|
setChainId(network?.chainId ?? 0)
|
||||||
|
}
|
||||||
|
;(window as any).ethereum.on('chainChanged', updateChainId)
|
||||||
|
return () => (window as any).ethereum.removeListener('chainChanged', updateChainId)
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
;(window as any).ethereum.on('chainChanged', () => window.location.reload())
|
|
||||||
const createWaku = async (queue: number) => {
|
const createWaku = async (queue: number) => {
|
||||||
while (queue != queuePos.current) {
|
while (queue != queuePos.current) {
|
||||||
await new Promise((r) => setTimeout(r, 1000))
|
await new Promise((r) => setTimeout(r, 1000))
|
||||||
}
|
}
|
||||||
if (provider && multicallAddress) {
|
if (provider && multicallAddress) {
|
||||||
const wak = await WakuVoting.create(appName, contractAddress, provider, multicallAddress)
|
if (waku) {
|
||||||
setWaku(wak)
|
waku.cleanUp()
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const wak = await WakuVoting.create(appName, contractAddress, provider, multicallAddress)
|
||||||
|
setWaku(wak)
|
||||||
|
} catch {
|
||||||
|
setWaku(undefined)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setWaku(undefined)
|
||||||
}
|
}
|
||||||
queuePos.current++
|
queuePos.current++
|
||||||
}
|
}
|
||||||
createWaku(queueSize.current++)
|
createWaku(queueSize.current++)
|
||||||
|
}, [provider, multicallAddress, contractAddress, chainId])
|
||||||
return () => (window as any).ethereum.removeListener('chainChanged', () => window.location.reload())
|
|
||||||
}, [provider, multicallAddress, contractAddress])
|
|
||||||
|
|
||||||
return waku
|
return waku
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,13 @@ const PopUpWindow = styled.div`
|
||||||
overflow: scroll;
|
overflow: scroll;
|
||||||
z-index: 9998;
|
z-index: 9998;
|
||||||
|
|
||||||
|
-ms-overflow-style: none;
|
||||||
|
scrollbar-width: none;
|
||||||
|
|
||||||
|
$::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 600px) {
|
@media (max-width: 600px) {
|
||||||
padding: 16px 16px 32px;
|
padding: 16px 16px 32px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
Loading…
Reference in New Issue