dappconnect-vote-poll-sdk/packages/polling-example
Szymon Szlachtowicz 77e242a110
Refactor packages and update readme (#94)
2021-09-24 02:57:44 +02:00
..
src Refactor packages and update readme (#94) 2021-09-24 02:57:44 +02:00
test Refactor voting modal (#84) 2021-09-22 01:04:38 +02:00
.eslintrc.json Refactor voting modal (#84) 2021-09-22 01:04:38 +02:00
.mocharc.json Refactor voting modal (#84) 2021-09-22 01:04:38 +02:00
README.md Update readme (#93) 2021-09-24 00:08:32 +02:00
package.json Refactor voting modal (#84) 2021-09-22 01:04:38 +02:00
prettier.config.js Refactor voting modal (#84) 2021-09-22 01:04:38 +02:00
tsconfig.json Refactor voting modal (#84) 2021-09-22 01:04:38 +02:00

README.md

This package is example usage of WakuPolling

Example uses usedapp for exposing web3 provider

For using usedapp please see usedapp docs

creating WakuPolling object

to create waku polling object you can just use react hook

const wakuPolling = useWakuPolling(
    appName,
    tokenaddress,
    library,
    multicallAddress
  )

it is a good idea for token address and multicall address to be dependent on current chainId.

useWakuPolling creates a new WakuPolling object whenever chainId changes.

creating new poll

to create new poll you can use createTimedPoll function from WakuPolling class

wakuPolling.createTimedPoll(
                  question,
                  answers,
                  selectedType,
                  undefined,
                  endTime
                )

If you want you can use already created modal component for creating polls

const [showPollCreation, setShowPollCreation] = useState(false)
.
.
.
{showPollCreation && (
        <PollCreation wakuPolling={wakuPolling} setShowPollCreation={setShowPollCreation} theme={theme} />
      )}

showing polls

to show list of polls you can either use PollList component from polling-component

<PollList wakuPolling={wakuPolling} account={account} theme={theme} />

If you want to create your own react component please use

usePollList(wakuPolling: WakuPolling | undefined)

Which returns memoized DetailedTimedPoll[] array.

Waku polling also exposes getDetailedTimedPolls

const DetailedTimedPolls = await wakuPolling.getDetailedTimedPolls()