Fix js waku (#36)

This commit is contained in:
Szymon Szlachtowicz 2021-09-01 13:16:39 +02:00 committed by GitHub
parent 3de0037d8e
commit 085c4d28ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import { PollInitMsg } from './models/PollInitMsg'
import { PollType } from './types/PollType'
import { BigNumber, Wallet } from 'ethers'
import PollInit from './utils/proto/PollInit'
import { WakuMessage } from 'js-waku'
import { WakuMessage, StoreCodec } from 'js-waku'
import { TimedPollVoteMsg } from './models/TimedPollVoteMsg'
import TimedPollVote from './utils/proto/TimedPollVote'
import { DetailedTimedPoll } from './models/DetailedTimedPoll'
@ -51,6 +51,13 @@ class WakuVoting {
public static async create(appName: string, tokenAddress: string, waku?: Waku) {
if (!waku) {
waku = await Waku.create({ bootstrap: true })
await new Promise((resolve) => {
waku?.libp2p.peerStore.on('change:protocols', ({ protocols }) => {
if (protocols.includes(StoreCodec)) {
resolve('')
}
})
})
}
return new WakuVoting(appName, tokenAddress, waku)
}