diff --git a/packages/contracts/README.md b/packages/contracts/README.md index 0165378..87edaba 100644 --- a/packages/contracts/README.md +++ b/packages/contracts/README.md @@ -131,6 +131,15 @@ For more information about EIP-712 go to [docs](https://eips.ethereum.org/EIPS/e - `getVotingRooms()` Returns votingRooms +- `getVotingRoomLength()` + Returns votingRooms length + +- `getLastNVotingRooms(uint256 amount)` + Gets last voting rooms returns amount of voting rooms + +- `getVotingRoomsFrom(uint256 id)` + Gets voting rooms from given id + - `getOngoingVotingRooms()` Returns votingRooms in which `room.endAt > block.timestamp` which means the rooms are still accepting votes. Since `votingLength` is set at contract creation and never changed, `room.endAt` is never decreasing with increasing index of votingRoom. Therefore it is enough to check from votingRooms.length up to first element which `endAt < block.timestamp` diff --git a/packages/core/README.md b/packages/core/README.md index 62926ca..cd8d6b1 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -1,4 +1,43 @@ -# Gassless voting over waku +## Waku Messaging + +Is a general class that takes care of keeping waku messages of given topic up to date as well as each address tokens. + +This class is meant to be extended by other classes. + +When creating a object of this class devs need to provide + +``` + appName: string // name of a string used for waku topics + tokenAddress: string // address of token contract used to verify messages + provider: Web3Provider + chainId: number, + multicall: string // address of multicall contract in given chainId + wakuMessagesSetup: WakuMessagesSetup[] // objects that define waku messages that are to be updated + waku?: Waku // object of Waku class +``` + +WakuMessagesSetup is defined as follows + +``` +WakuMessagesSetup = { + name: string // name of wakuMessages + tokenCheckArray: string[] // array of fields in waku message that are to be checked for token balance + decodeFunction: (wakuMessage: WakuMessage) => T | undefined // function that decodes raw WakuMessage + filterFunction?: (e: T) => boolean // function that filters waku messages +} +``` + +Waku Messages are stored in `this.wakuMessages[name]` and are of type + +``` +type WakuMessageStore = { + topic: string + hashMap: { [id: string]: boolean } + tokenCheckArray: string[] + arr: any[] // array holding + updateFunction: (msg: WakuMessage[]) => void +} +``` ## Waku Voting @@ -6,21 +45,45 @@ Objects of type of WakuVoting, hold their own Waku objects and also store list o Creating instance of WakuVoting: -WakuVoting constructor expects name of DApp and address of a token, also as optional parameter can take custom Waku object. +WakuVoting constructor expects name of DApp and address of a token, web3provider, also as optional parameter can take custom Waku object. ```ts - import WakuVoting from 'core' + import { WakuVoting } from '@status-waku-voting/core' - const wakuVoting = new WakuVoting('myDapp', '0x00000000000') + await WakuVoting.create(appName, contractAddress, provider, multicallAddress) ``` objects of type WakuVoting expose functions: -createTimedPoll(signer: JsonRpcSigner, question:string, answers: string[], pollType: enum, minToken?: BigNumber, endTime?: number) -getTimedPolls() +- `getVotingRooms()` which return a list o VotingRoom -sendTimedPollVote(signer: JsonRpcSigner, id: string, selectedAnswer:number, tokenAmount?: number) -getTimedPollVotes(id: string) +``` +export type VotingRoom = { + startBlock: BigNumber + endAt: BigNumber + question: string + description: string + totalVotesFor: BigNumber // amount of commited votes for + totalVotesAgainst: BigNumber //amount of commited votes against + wakuTotalVotesFor: BigNumber // amount of committed and uncomitted votes for + wakuTotalVotesAgainst: BigNumber // amount of committed and uncomitted votes against + wakuVotes?: { + sum: BigNumber // sum of tokens of uncomitted votes + votes: VoteMsg[] // array of uncomitted votes + } + voters: string[] // array of voters which votes has been commited + id: number + timeLeft: number + voteWinner: number | undefined + transactionHash?: string +} +``` + +- `sendVote(roomId: number, selectedAnswer: number, tokenAmount: BigNumber)` which sends waku vote + +- `commitVotes(votes: VoteMsg[])` commits votes to blockchain + +- `getVotingRoom(id: number)` gets VotingRoom with given id ## Polls diff --git a/packages/polling-example/src/assets/images/pollingIcon.png b/packages/polling-example/src/assets/images/pollingIcon.png new file mode 100644 index 0000000..10f1b2f Binary files /dev/null and b/packages/polling-example/src/assets/images/pollingIcon.png differ diff --git a/packages/polling-example/src/assets/images/pollingIcon.svg b/packages/polling-example/src/assets/images/pollingIcon.svg deleted file mode 100644 index ac67eb5..0000000 --- a/packages/polling-example/src/assets/images/pollingIcon.svg +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/packages/polling-example/src/index.tsx b/packages/polling-example/src/index.tsx index d819395..065a0a3 100644 --- a/packages/polling-example/src/index.tsx +++ b/packages/polling-example/src/index.tsx @@ -4,7 +4,7 @@ import { DAppProvider, ChainId, useEthers } from '@usedapp/core' import { DEFAULT_CONFIG } from '@usedapp/core/dist/cjs/src/model/config/default' import { WakuPolling } from './components/WakuPolling' import { TopBar, GlobalStyle } from '@status-waku-voting/react-components' -import pollingIcon from './assets/images/pollingIcon.svg' +import pollingIcon from './assets/images/pollingIcon.png' import { JsonRpcSigner } from '@ethersproject/providers' import { orangeTheme } from '@status-waku-voting/react-components/dist/esm/src/style/themes' diff --git a/packages/react-components/src/components/TopBar.tsx b/packages/react-components/src/components/TopBar.tsx index 1572128..4a8f6c5 100644 --- a/packages/react-components/src/components/TopBar.tsx +++ b/packages/react-components/src/components/TopBar.tsx @@ -22,7 +22,7 @@ export function TopBar({ logo, title, theme, activate, deactivate, account }: To return ( - + {title.split(' ').map((text, idx) => (
{text}
@@ -90,7 +90,7 @@ const TitleWrapper = styled.div` line-height: 17px; ` -const Logo = styled.div` +const Logo = styled.img` height: 30px; width: 32px; `