Introduce WakuVoting (#2)

This commit is contained in:
Szymon Szlachtowicz 2021-08-09 11:57:02 +02:00 committed by GitHub
parent ae8ea050a3
commit 5cddb61d72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 21 deletions

View File

@ -1,12 +1,33 @@
#Gassless voting over waku #Gassless voting over waku
##Waku Voting
Objects of type of WakuVoting, hold their own Waku objects and also store list of polls and votes for later use.
Creating instance of WakuVoting:
WakuVoting constructor expects name of DApp and also as optional parameter can take custom Waku object.
```ts
import WakuVoting from 'core'
const wakuVoting = new WakuVoting('myDapp')
```
objects of type WakuVoting expose functions:
createTimedPoll(signer: JsonRpcSigner, question:string, answers: string[], pollType: enum, minToken?: BigNumber, endTime?: number)
getTimedPolls()
sendTimedPollVote(signer: JsonRpcSigner, pollHash: string, selectedAnswer:number, sntAmount?: number)
##Polls ##Polls
###Creating time-limited poll ###Creating time-limited poll
To create a poll user has to send a message over waku network on specific topic To create a poll user has to send a message over waku network on specific topic
`/{dapp name}/waku-polling/polls-init/proto` `/{dapp name}/waku-polling/timed-polls-init/proto`
For a poll to be started waku message has to have specific fields: For a poll to be started waku message has to have specific fields:

View File

@ -1,5 +1,29 @@
function foo() { import { Waku, getStatusFleetNodes } from 'js-waku'
return 'Hello world'
class WakuVoting {
private appName: string
private waku: Waku | undefined
private async createWaku() {
this.waku = await Waku.create()
const nodes = await getStatusFleetNodes()
await Promise.all(
nodes.map((addr) => {
if (this.waku) {
return this.waku.dial(addr)
}
})
)
}
constructor(appName: string, waku?: Waku) {
this.appName = appName
if (waku) {
this.waku = waku
} else {
this.createWaku()
}
}
} }
export { foo } export default WakuVoting

View File

@ -1,11 +1,11 @@
import { expect } from 'chai' import { expect } from 'chai'
import { foo } from '../src' import { Waku } from 'js-waku'
import WakuVoting from '../src'
describe('test', () => { describe('WakuVoting', () => {
it('foo', async () => { it('success', async () => {
expect(foo()).to.eq('Hello world') const wakuVoting = new WakuVoting('test', {} as unknown as Waku)
})
it('not foo', async () => { expect(wakuVoting).to.not.be.undefined
expect(foo()).to.not.eq('asdas')
}) })
}) })

View File

@ -1,13 +1,7 @@
import React from 'react' import React from 'react'
import { foo } from '@status-waku-voting/core'
function Example() { function Example() {
return ( return <div>This is example components</div>
<div>
This is example components
{foo()}
</div>
)
} }
export { Example } export { Example }

View File

@ -1,8 +1,7 @@
import { expect } from 'chai' import { expect } from 'chai'
import { foo } from '@status-waku-voting/core'
describe('test react-components', () => { describe('test react-components', () => {
it('foo', async () => { it('foo', async () => {
expect(foo()).to.eq('Hello world') expect('Hello world').to.eq('Hello world')
}) })
}) })