Introduce WakuVoting (#2)
This commit is contained in:
parent
ae8ea050a3
commit
5cddb61d72
|
@ -1,12 +1,33 @@
|
|||
#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
|
||||
|
||||
###Creating time-limited poll
|
||||
|
||||
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:
|
||||
|
||||
|
|
|
@ -1,5 +1,29 @@
|
|||
function foo() {
|
||||
return 'Hello world'
|
||||
import { Waku, getStatusFleetNodes } from 'js-waku'
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export { foo }
|
||||
constructor(appName: string, waku?: Waku) {
|
||||
this.appName = appName
|
||||
if (waku) {
|
||||
this.waku = waku
|
||||
} else {
|
||||
this.createWaku()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default WakuVoting
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { expect } from 'chai'
|
||||
import { foo } from '../src'
|
||||
import { Waku } from 'js-waku'
|
||||
import WakuVoting from '../src'
|
||||
|
||||
describe('test', () => {
|
||||
it('foo', async () => {
|
||||
expect(foo()).to.eq('Hello world')
|
||||
})
|
||||
it('not foo', async () => {
|
||||
expect(foo()).to.not.eq('asdas')
|
||||
describe('WakuVoting', () => {
|
||||
it('success', async () => {
|
||||
const wakuVoting = new WakuVoting('test', {} as unknown as Waku)
|
||||
|
||||
expect(wakuVoting).to.not.be.undefined
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
import React from 'react'
|
||||
import { foo } from '@status-waku-voting/core'
|
||||
|
||||
function Example() {
|
||||
return (
|
||||
<div>
|
||||
This is example components
|
||||
{foo()}
|
||||
</div>
|
||||
)
|
||||
return <div>This is example components</div>
|
||||
}
|
||||
|
||||
export { Example }
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { expect } from 'chai'
|
||||
import { foo } from '@status-waku-voting/core'
|
||||
|
||||
describe('test react-components', () => {
|
||||
it('foo', async () => {
|
||||
expect(foo()).to.eq('Hello world')
|
||||
expect('Hello world').to.eq('Hello world')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue