Add mock waku (#29)

This commit is contained in:
Szymon Szlachtowicz 2021-08-30 15:35:45 +02:00 committed by GitHub
parent 3ad13cceaa
commit 9907887acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -17,7 +17,7 @@ export function Polling() {
return ( return (
<Wrapper> <Wrapper>
<TopBar logo={pollingIcon} title={'Polling Dapp'} /> <TopBar logo={pollingIcon} title={'Polling Dapp'} />
<WakuPolling appName={'testApp_'} signer={signer} /> <WakuPolling appName={'testApp_'} signer={signer} localhost={process.env.ENV === 'localhost'} />
</Wrapper> </Wrapper>
) )
} }

View File

@ -10,14 +10,35 @@ import { JsonRpcSigner } from '@ethersproject/providers'
type WakuPollingProps = { type WakuPollingProps = {
appName: string appName: string
signer: JsonRpcSigner | undefined signer: JsonRpcSigner | undefined
localhost?: boolean
} }
function WakuPolling({ appName, signer }: WakuPollingProps) { function WakuPolling({ appName, signer, localhost }: WakuPollingProps) {
const [wakuVoting, setWakuVoting] = useState<WakuVoting | undefined>(undefined) const [wakuVoting, setWakuVoting] = useState<WakuVoting | undefined>(undefined)
const [showPollCreation, setShowPollCreation] = useState(false) const [showPollCreation, setShowPollCreation] = useState(false)
let waku: any | undefined = undefined
if (localhost) {
waku = {
messages: {},
relay: {
send(msg: any) {
if (!(this as any).messages[msg.contentTopic]) {
;(this as any).messages[msg.contentTopic] = []
}
;(this as any).messages[msg.contentTopic] = [...(this as any).messages[msg.contentTopic], msg]
},
},
store: {
queryHistory(topic: any) {
return (this as any).messages[topic[0]]
},
},
}
waku.relay.send = waku.relay.send.bind(waku)
waku.store.queryHistory = waku.store.queryHistory.bind(waku)
}
useEffect(() => { useEffect(() => {
WakuVoting.create(appName, '0x01').then((e) => setWakuVoting(e)) WakuVoting.create(appName, '0x01', waku).then((e) => setWakuVoting(e))
}, []) }, [])
return ( return (