Add etherscan links (#79)

This commit is contained in:
Szymon Szlachtowicz 2021-09-21 01:07:28 +02:00 committed by GitHub
parent e1a1203a58
commit 1374663cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 6 deletions

View File

@ -14,7 +14,7 @@ const ABI = [
export class WakuVoting extends WakuMessaging { export class WakuVoting extends WakuMessaging {
private votingContract: Contract private votingContract: Contract
public providerName: string
constructor( constructor(
appName: string, appName: string,
votingContract: Contract, votingContract: Contract,
@ -22,6 +22,7 @@ export class WakuVoting extends WakuMessaging {
provider: Web3Provider, provider: Web3Provider,
chainId: number, chainId: number,
multicallAddress: string, multicallAddress: string,
providerName: string,
waku?: Waku waku?: Waku
) { ) {
super( super(
@ -39,6 +40,7 @@ export class WakuVoting extends WakuMessaging {
], ],
waku waku
) )
this.providerName = providerName
this.votingContract = votingContract this.votingContract = votingContract
} }
@ -52,7 +54,17 @@ export class WakuVoting extends WakuMessaging {
const network = await provider.getNetwork() const network = await provider.getNetwork()
const votingContract = new Contract(contractAddress, VotingContract.abi, provider) const votingContract = new Contract(contractAddress, VotingContract.abi, provider)
const tokenAddress = await votingContract.token() const tokenAddress = await votingContract.token()
return new WakuVoting(appName, votingContract, tokenAddress, provider, network.chainId, multicall, waku) const providerName = (await provider.getNetwork()).name
return new WakuVoting(
appName,
votingContract,
tokenAddress,
provider,
network.chainId,
multicall,
providerName,
waku
)
} }
public async createVote(question: string, descripiton: string, tokenAmount: BigNumber) { public async createVote(question: string, descripiton: string, tokenAmount: BigNumber) {
@ -86,6 +98,16 @@ export class WakuVoting extends WakuMessaging {
voteWinner: timeLeft <= 0 ? (poll[5].gt(poll[4]) ? 1 : 2) : undefined, voteWinner: timeLeft <= 0 ? (poll[5].gt(poll[4]) ? 1 : 2) : undefined,
} }
}) })
await Promise.all(
this.lastPolls.map(async (poll) => {
if (!poll.transactionHash) {
const block = await this.provider.getBlockWithTransactions(poll.startBlock.toNumber())
poll.transactionHash = block.transactions.find(
(transaction) => transaction.to === this.votingContract.address
)?.hash
}
})
)
} }
return this.lastPolls return this.lastPolls
} }

View File

@ -16,4 +16,5 @@ export type VotingRoom = {
id: number id: number
timeLeft: number timeLeft: number
voteWinner: number | undefined voteWinner: number | undefined
transactionHash?: string
} }

View File

@ -21,7 +21,7 @@ export function ProposalCard({ theme, votingRoom, mobileVersion, availableAmount
return ( return (
<Card onClick={() => mobileVersion && history.push(`/votingRoom/${votingRoom.id.toString()}`)}> <Card onClick={() => mobileVersion && history.push(`/votingRoom/${votingRoom.id.toString()}`)}>
<ProposalInfo votingRoom={votingRoom} /> <ProposalInfo votingRoom={votingRoom} providerName={wakuVoting.providerName} />
<ProposalVote votingRoom={votingRoom} theme={theme} availableAmount={availableAmount} wakuVoting={wakuVoting} /> <ProposalVote votingRoom={votingRoom} theme={theme} availableAmount={availableAmount} wakuVoting={wakuVoting} />
</Card> </Card>
) )

View File

@ -1,3 +1,4 @@
import { WakuVoting } from '@status-waku-voting/core'
import { VotingRoom } from '@status-waku-voting/core/dist/esm/src/types/PollType' import { VotingRoom } from '@status-waku-voting/core/dist/esm/src/types/PollType'
import React from 'react' import React from 'react'
import styled from 'styled-components' import styled from 'styled-components'
@ -5,16 +6,21 @@ import { ViewLink } from './ViewLink'
type ProposalInfoProps = { type ProposalInfoProps = {
votingRoom: VotingRoom votingRoom: VotingRoom
providerName: string
mobileMode?: boolean mobileMode?: boolean
} }
export function ProposalInfo({ votingRoom, mobileMode }: ProposalInfoProps) { export function ProposalInfo({ votingRoom, mobileMode, providerName }: ProposalInfoProps) {
return ( return (
<Card> <Card>
<CardHeading>{votingRoom.question}</CardHeading> <CardHeading>{votingRoom.question}</CardHeading>
<CardText className={mobileMode ? 'mobile' : ''}>{votingRoom.description}</CardText> <CardText className={mobileMode ? 'mobile' : ''}>{votingRoom.description}</CardText>
<CardViewLink className={mobileMode ? 'mobile' : ''}> <CardViewLink className={mobileMode ? 'mobile' : ''}>
<ViewLink address={'#'} /> <ViewLink
address={
votingRoom.transactionHash ? `https://${providerName}.etherscan.io/tx/${votingRoom.transactionHash}` : '#'
}
/>
</CardViewLink> </CardViewLink>
</Card> </Card>
) )

View File

@ -30,7 +30,7 @@ export function ProposalVoteMobile({ wakuVoting, availableAmount }: ProposalVote
return ( return (
<Card> <Card>
<ProposalInfo votingRoom={votingRoom} mobileMode={true} /> <ProposalInfo votingRoom={votingRoom} mobileMode={true} providerName={wakuVoting.providerName} />
<VoteChartWrap> <VoteChartWrap>
<VoteChart votingRoom={votingRoom} selectedVote={selectedVoted} /> <VoteChart votingRoom={votingRoom} selectedVote={selectedVoted} />
</VoteChartWrap> </VoteChartWrap>