diff --git a/packages/example/src/pages/Poling.tsx b/packages/example/src/pages/Poling.tsx index 412259b..9364142 100644 --- a/packages/example/src/pages/Poling.tsx +++ b/packages/example/src/pages/Poling.tsx @@ -17,7 +17,7 @@ export function Polling() { return ( - + ) } diff --git a/packages/react-components/src/WakuPolling/index.tsx b/packages/react-components/src/WakuPolling/index.tsx index 432ab9e..e7b166e 100644 --- a/packages/react-components/src/WakuPolling/index.tsx +++ b/packages/react-components/src/WakuPolling/index.tsx @@ -10,14 +10,35 @@ import { JsonRpcSigner } from '@ethersproject/providers' type WakuPollingProps = { appName: string signer: JsonRpcSigner | undefined + localhost?: boolean } -function WakuPolling({ appName, signer }: WakuPollingProps) { +function WakuPolling({ appName, signer, localhost }: WakuPollingProps) { const [wakuVoting, setWakuVoting] = useState(undefined) 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(() => { - WakuVoting.create(appName, '0x01').then((e) => setWakuVoting(e)) + WakuVoting.create(appName, '0x01', waku).then((e) => setWakuVoting(e)) }, []) return (