Fix ui elements (#81)
This commit is contained in:
parent
6d28e1fae9
commit
cb9eaed607
|
@ -46,7 +46,7 @@ export function ProposalVote({ votingRoom, theme, availableAmount, hideModalFunc
|
||||||
{showVoteModal && (
|
{showVoteModal && (
|
||||||
<Modal heading={votingRoom.question} setShowModal={setShowVoteModal} theme={theme}>
|
<Modal heading={votingRoom.question} setShowModal={setShowVoteModal} theme={theme}>
|
||||||
<VoteModal
|
<VoteModal
|
||||||
votingRoom={modifiedVotingRoom}
|
votingRoom={modifiedVotingRoom ?? votingRoom}
|
||||||
availableAmount={availableAmount}
|
availableAmount={availableAmount}
|
||||||
selectedVote={selectedVoted}
|
selectedVote={selectedVoted}
|
||||||
proposingAmount={proposingAmount}
|
proposingAmount={proposingAmount}
|
||||||
|
@ -59,7 +59,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={modifiedVotingRoom ?? votingRoom}
|
||||||
selectedVote={selectedVoted}
|
selectedVote={selectedVoted}
|
||||||
setShowModal={hideConfirm}
|
setShowModal={hideConfirm}
|
||||||
proposingAmount={proposingAmount}
|
proposingAmount={proposingAmount}
|
||||||
|
@ -72,7 +72,7 @@ export function ProposalVote({ votingRoom, theme, availableAmount, hideModalFunc
|
||||||
<CardHeading />
|
<CardHeading />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<VoteChart votingRoom={modifiedVotingRoom} selectedVote={selectedVoted} />
|
<VoteChart votingRoom={modifiedVotingRoom ?? votingRoom} selectedVote={selectedVoted} />
|
||||||
|
|
||||||
<CardButtons>
|
<CardButtons>
|
||||||
{votingRoom.voteWinner ? (
|
{votingRoom.voteWinner ? (
|
||||||
|
|
|
@ -40,7 +40,7 @@ export function VoteChart({ votingRoom, proposingAmount, selectedVote, isAnimati
|
||||||
}
|
}
|
||||||
}, [graphWidth, voteSum, proposingAmount])
|
}, [graphWidth, voteSum, proposingAmount])
|
||||||
|
|
||||||
const timeLeft = useMemo(() => votingRoom.timeLeft, [votingRoom.timeLeft])
|
const timeLeft = useMemo(() => votingRoom.timeLeft * 1000, [votingRoom.timeLeft])
|
||||||
const voteWinner = useMemo(() => votingRoom.voteWinner, [votingRoom.voteWinner])
|
const voteWinner = useMemo(() => votingRoom.voteWinner, [votingRoom.voteWinner])
|
||||||
return (
|
return (
|
||||||
<Votes ref={ref}>
|
<Votes ref={ref}>
|
||||||
|
@ -90,7 +90,7 @@ function VoteBox({ won, mobileVersion, voteType, totalVotes, proposingAmount, se
|
||||||
<VoteBoxWrapper
|
<VoteBoxWrapper
|
||||||
style={{
|
style={{
|
||||||
filter: won ? 'grayscale(1)' : 'none',
|
filter: won ? 'grayscale(1)' : 'none',
|
||||||
alignItems: mobileVersion ? (voteType == 1 ? 'flex-start' : 'flex-end') : 'center',
|
alignItems: mobileVersion ? (voteType == 1 ? 'flex-end' : 'flex-start') : 'center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<VoteIcon
|
<VoteIcon
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React from 'react'
|
import React, { useCallback } from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import { VoteChart } from './ProposalVoteCard/VoteChart'
|
import { VoteChart } from './ProposalVoteCard/VoteChart'
|
||||||
import { DisabledButton, VoteBtnAgainst, VoteBtnFor } from './Buttons'
|
import { DisabledButton, VoteBtnAgainst, VoteBtnFor } from './Buttons'
|
||||||
|
@ -28,7 +28,10 @@ export function VoteModal({
|
||||||
}: VoteModalProps) {
|
}: VoteModalProps) {
|
||||||
const disabled = proposingAmount === 0
|
const disabled = proposingAmount === 0
|
||||||
const funds = availableAmount > 0
|
const funds = availableAmount > 0
|
||||||
|
const onClick = useCallback(async () => {
|
||||||
|
wakuVoting.sendVote(votingRoom.id, selectedVote, BigNumber.from(proposingAmount))
|
||||||
|
setShowConfirmModal(true)
|
||||||
|
}, [votingRoom, selectedVote, proposingAmount, wakuVoting])
|
||||||
return (
|
return (
|
||||||
<Column>
|
<Column>
|
||||||
<VoteChart votingRoom={votingRoom} proposingAmount={proposingAmount} selectedVote={selectedVote} />
|
<VoteChart votingRoom={votingRoom} proposingAmount={proposingAmount} selectedVote={selectedVote} />
|
||||||
|
@ -40,16 +43,14 @@ export function VoteModal({
|
||||||
|
|
||||||
{!funds && <DisabledButton>Not enought ABC to vote</DisabledButton>}
|
{!funds && <DisabledButton>Not enought ABC to vote</DisabledButton>}
|
||||||
|
|
||||||
{funds && (
|
{funds && selectedVote === 0 ? (
|
||||||
<ModalVoteBtnAgainst
|
<BtnAgainst disabled={disabled} onClick={onClick}>
|
||||||
disabled={disabled}
|
Vote Against
|
||||||
onClick={async () => {
|
</BtnAgainst>
|
||||||
wakuVoting.sendVote(votingRoom.id, selectedVote, BigNumber.from(proposingAmount))
|
) : (
|
||||||
setShowConfirmModal(true)
|
<BtnFor disabled={disabled} onClick={onClick}>
|
||||||
}}
|
Vote For
|
||||||
>
|
</BtnFor>
|
||||||
{selectedVote === 0 ? `Vote Against` : `Vote For`}
|
|
||||||
</ModalVoteBtnAgainst>
|
|
||||||
)}
|
)}
|
||||||
</Column>
|
</Column>
|
||||||
)
|
)
|
||||||
|
@ -63,11 +64,11 @@ const Column = styled.div`
|
||||||
margin-top: 32px;
|
margin-top: 32px;
|
||||||
`
|
`
|
||||||
|
|
||||||
const ModalVoteBtnAgainst = styled(VoteBtnAgainst)`
|
const BtnAgainst = styled(VoteBtnAgainst)`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-top: 32px;
|
margin-top: 32px;
|
||||||
`
|
`
|
||||||
const ModalVoteBtnFor = styled(VoteBtnFor)`
|
const BtnFor = styled(VoteBtnFor)`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-top: 32px;
|
margin-top: 32px;
|
||||||
`
|
`
|
||||||
|
|
|
@ -24,7 +24,7 @@ export function ProposalMobile({ wakuVoting, account }: ProposalMobileProps) {
|
||||||
<ProposalVoteMobile wakuVoting={wakuVoting} availableAmount={tokenBalance} />
|
<ProposalVoteMobile wakuVoting={wakuVoting} availableAmount={tokenBalance} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route exact path="/creation">
|
<Route exact path="/creation">
|
||||||
<ProposeMobile availableAmount={tokenBalance} />
|
<ProposeMobile availableAmount={tokenBalance} wakuVoting={wakuVoting} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route exact path="/proposal">
|
<Route exact path="/proposal">
|
||||||
<Proposal wakuVoting={wakuVoting} account={account} />
|
<Proposal wakuVoting={wakuVoting} account={account} />
|
||||||
|
|
|
@ -8,8 +8,9 @@ import { VoteChart } from '../ProposalVoteCard/VoteChart'
|
||||||
import { ProposalInfo } from '../ProposalInfo'
|
import { ProposalInfo } from '../ProposalInfo'
|
||||||
import { VotePropose } from '../VotePropose'
|
import { VotePropose } from '../VotePropose'
|
||||||
import { VotesBtns } from '../ProposalVoteCard/ProposalVote'
|
import { VotesBtns } from '../ProposalVoteCard/ProposalVote'
|
||||||
import { useVotingRoom } from '@status-waku-voting/proposal-hooks'
|
import { useRoomWakuVotes, useVotingRoom } from '@status-waku-voting/proposal-hooks'
|
||||||
import { WakuVoting } from '@status-waku-voting/core'
|
import { WakuVoting } from '@status-waku-voting/core'
|
||||||
|
import { BigNumber } from 'ethers'
|
||||||
interface ProposalVoteMobileProps {
|
interface ProposalVoteMobileProps {
|
||||||
wakuVoting: WakuVoting
|
wakuVoting: WakuVoting
|
||||||
availableAmount: number
|
availableAmount: number
|
||||||
|
@ -23,6 +24,7 @@ export function ProposalVoteMobile({ wakuVoting, availableAmount }: ProposalVote
|
||||||
const votingRoom = useVotingRoom(Number(id), wakuVoting)
|
const votingRoom = useVotingRoom(Number(id), wakuVoting)
|
||||||
|
|
||||||
const voteWinner = useMemo(() => votingRoom?.voteWinner, [votingRoom?.voteWinner])
|
const voteWinner = useMemo(() => votingRoom?.voteWinner, [votingRoom?.voteWinner])
|
||||||
|
const { votes, sum, modifiedVotingRoom } = useRoomWakuVotes(votingRoom, wakuVoting)
|
||||||
|
|
||||||
if (!votingRoom) {
|
if (!votingRoom) {
|
||||||
return <>Loading</>
|
return <>Loading</>
|
||||||
|
@ -32,7 +34,7 @@ export function ProposalVoteMobile({ wakuVoting, availableAmount }: ProposalVote
|
||||||
<Card>
|
<Card>
|
||||||
<ProposalInfo votingRoom={votingRoom} mobileMode={true} providerName={wakuVoting.providerName} />
|
<ProposalInfo votingRoom={votingRoom} mobileMode={true} providerName={wakuVoting.providerName} />
|
||||||
<VoteChartWrap>
|
<VoteChartWrap>
|
||||||
<VoteChart votingRoom={votingRoom} selectedVote={selectedVoted} />
|
<VoteChart votingRoom={modifiedVotingRoom ?? votingRoom} selectedVote={selectedVoted} />
|
||||||
</VoteChartWrap>
|
</VoteChartWrap>
|
||||||
{!voteWinner && (
|
{!voteWinner && (
|
||||||
<VotePropose
|
<VotePropose
|
||||||
|
@ -51,6 +53,7 @@ export function ProposalVoteMobile({ wakuVoting, availableAmount }: ProposalVote
|
||||||
disabled={!account}
|
disabled={!account}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedVoted(0)
|
setSelectedVoted(0)
|
||||||
|
wakuVoting.sendVote(votingRoom.id, 0, BigNumber.from(proposingAmount))
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Vote Against
|
Vote Against
|
||||||
|
@ -59,6 +62,7 @@ export function ProposalVoteMobile({ wakuVoting, availableAmount }: ProposalVote
|
||||||
disabled={!account}
|
disabled={!account}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedVoted(1)
|
setSelectedVoted(1)
|
||||||
|
wakuVoting.sendVote(votingRoom.id, 1, BigNumber.from(proposingAmount))
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Vote For
|
Vote For
|
||||||
|
@ -69,7 +73,7 @@ export function ProposalVoteMobile({ wakuVoting, availableAmount }: ProposalVote
|
||||||
|
|
||||||
<CardVoteBottom>
|
<CardVoteBottom>
|
||||||
{' '}
|
{' '}
|
||||||
<VoteSubmitButton votes={15} disabled={!account} onClick={() => null} />
|
<VoteSubmitButton votes={sum.toNumber()} disabled={!account} onClick={() => wakuVoting.commitVotes(votes)} />
|
||||||
</CardVoteBottom>
|
</CardVoteBottom>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
|
|
|
@ -13,12 +13,15 @@ import {
|
||||||
ProposingTextInput,
|
ProposingTextInput,
|
||||||
} from '../newVoteModal/ProposeModal'
|
} from '../newVoteModal/ProposeModal'
|
||||||
import { VotePropose } from '../VotePropose'
|
import { VotePropose } from '../VotePropose'
|
||||||
|
import { BigNumber } from 'ethers'
|
||||||
|
import { WakuVoting } from '@status-waku-voting/core'
|
||||||
|
|
||||||
interface ProposeVoteModalProps {
|
interface ProposeVoteModalProps {
|
||||||
availableAmount: number
|
availableAmount: number
|
||||||
|
wakuVoting: WakuVoting
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ProposeMobile({ availableAmount }: ProposeVoteModalProps) {
|
export function ProposeMobile({ availableAmount, wakuVoting }: ProposeVoteModalProps) {
|
||||||
const insufficientFunds = availableAmount < 10000
|
const insufficientFunds = availableAmount < 10000
|
||||||
const [proposingAmount, setProposingAmount] = useState(0)
|
const [proposingAmount, setProposingAmount] = useState(0)
|
||||||
const [title, setTitle] = useState('')
|
const [title, setTitle] = useState('')
|
||||||
|
@ -90,7 +93,8 @@ export function ProposeMobile({ availableAmount }: ProposeVoteModalProps) {
|
||||||
|
|
||||||
<ProposingBtn
|
<ProposingBtn
|
||||||
disabled={proposingAmount === 0}
|
disabled={proposingAmount === 0}
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
|
await wakuVoting.createVote(title, text, BigNumber.from(proposingAmount))
|
||||||
history.push(`/proposal`), setTitle(''), setText('')
|
history.push(`/proposal`), setTitle(''), setText('')
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { VoteMsg } from '@status-waku-voting/core/dist/esm/src/models/VoteMsg'
|
||||||
import { utils, BigNumber } from 'ethers'
|
import { utils, BigNumber } from 'ethers'
|
||||||
import { VotingRoom } from '@status-waku-voting/core/dist/esm/src/types/PollType'
|
import { VotingRoom } from '@status-waku-voting/core/dist/esm/src/types/PollType'
|
||||||
|
|
||||||
export function useRoomWakuVotes(votingRoom: VotingRoom, wakuVoting: WakuVoting) {
|
export function useRoomWakuVotes(votingRoom: VotingRoom | undefined, wakuVoting: WakuVoting) {
|
||||||
const [votes, setVotes] = useState<VoteMsg[]>([])
|
const [votes, setVotes] = useState<VoteMsg[]>([])
|
||||||
const [sum, setSum] = useState(BigNumber.from(0))
|
const [sum, setSum] = useState(BigNumber.from(0))
|
||||||
const [modifiedVotingRoom, setModifiedVotingRoom] = useState(votingRoom)
|
const [modifiedVotingRoom, setModifiedVotingRoom] = useState(votingRoom)
|
||||||
|
@ -12,6 +12,9 @@ export function useRoomWakuVotes(votingRoom: VotingRoom, wakuVoting: WakuVoting)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateVotes = async () => {
|
const updateVotes = async () => {
|
||||||
|
if (!votingRoom) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const newVotes = await wakuVoting.getRoomWakuVotes(votingRoom.id)
|
const newVotes = await wakuVoting.getRoomWakuVotes(votingRoom.id)
|
||||||
if (newVotes) {
|
if (newVotes) {
|
||||||
const newHash = utils.id(newVotes.wakuVotes.map((vote) => vote.id).join(''))
|
const newHash = utils.id(newVotes.wakuVotes.map((vote) => vote.id).join(''))
|
||||||
|
@ -24,9 +27,9 @@ export function useRoomWakuVotes(votingRoom: VotingRoom, wakuVoting: WakuVoting)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateVotes()
|
updateVotes()
|
||||||
const interval = setInterval(updateVotes, 10000)
|
const interval = setInterval(updateVotes, 1000)
|
||||||
return () => clearInterval(interval)
|
return () => clearInterval(interval)
|
||||||
}, [wakuVoting])
|
}, [wakuVoting, votingRoom])
|
||||||
|
|
||||||
return { votes, sum, modifiedVotingRoom }
|
return { votes, sum, modifiedVotingRoom }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue