import React from 'react'; import { Link } from 'react-router-dom'; import { Table } from 'semantic-ui-react'; import { I18nProps } from '@polkadot/react-components/types'; import { ApiProps } from '@polkadot/react-api/types'; import { withCalls } from '@polkadot/react-api/with'; import { Hash } from '@polkadot/types/interfaces'; import { formatBalance } from '@polkadot/util'; import translate from './translate'; import { calcTotalStake } from '@polkadot/joy-utils/index'; import { SealedVote } from '@joystream/types/'; import AddressMini from '@polkadot/react-components/AddressMiniJoy'; import CandidatePreview from './CandidatePreview'; import { findVoteByHash } from './myVotesStore'; type Props = ApiProps & I18nProps & { hash: Hash; sealedVote?: SealedVote; }; class Comp extends React.PureComponent { renderCandidateOrAction () { const { hash, sealedVote } = this.props; if (!sealedVote) { return Unknown hashed vote: {hash.toHex()}; } if (sealedVote.vote.isSome) { const candidateId = sealedVote.vote.unwrap(); return ; } else { const revealUrl = `/council/reveals?hashedVote=${hash.toHex()}`; return Reveal this vote; } } render () { const { hash, sealedVote } = this.props; const myVote = findVoteByHash(hash.toHex()); return !sealedVote ? null : ( Hash {hash.toHex()} {myVote && Salt {myVote.salt} } Stake {formatBalance(calcTotalStake(sealedVote.stake))} {myVote && Voted on {new Date(myVote.votedOnTime).toLocaleString()} } Voter Candidate {this.renderCandidateOrAction()}
); } } // inject the actual API calls automatically into props export default translate( withCalls( ['query.councilElection.votes', { paramName: 'hash', propName: 'sealedVote' }] )(Comp) );