dappconnect-vote-poll-sdk/packages/poll-example
Franck Royer bddbd1359a
Release 0.4.0
2022-01-20 11:40:28 +11:00
..
src Fix lint/core functions and decimals 2022-01-20 01:19:47 +01:00
test Rename polling-example to poll-example 2021-12-07 13:18:57 +11:00
.eslintrc.json Rename polling-example to poll-example 2021-12-07 13:18:57 +11:00
.mocharc.json Rename polling-example to poll-example 2021-12-07 13:18:57 +11:00
README.md s/DappConnect/WakuConnect/ 2021-12-23 16:03:01 +11:00
package.json Release 0.4.0 2022-01-20 11:40:28 +11:00
prettier.config.js Rename polling-example to poll-example 2021-12-07 13:18:57 +11:00
tsconfig.json Rename polling-example to poll-example 2021-12-07 13:18:57 +11:00

README.md

WakuConnect Poll SDK Example

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()