From 4f50ca173248e365d689c09a18077c0033eaccf5 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 9 Jul 2021 11:39:31 +1000 Subject: [PATCH] Align examples --- examples/cli-chat/src/chat.ts | 3 +- examples/eth-dm/src/BroadcastPublicKey.tsx | 34 +++++++++++++++------- examples/web-chat/src/Room.tsx | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/examples/cli-chat/src/chat.ts b/examples/cli-chat/src/chat.ts index ac86ec77d0..d0c3f0f7be 100644 --- a/examples/cli-chat/src/chat.ts +++ b/examples/cli-chat/src/chat.ts @@ -104,8 +104,9 @@ export default async function startChat(): Promise { rl.prompt(); const chatMessage = ChatMessage.fromUtf8String(new Date(), nick, line); - const msg = WakuMessage.fromBytes(chatMessage.encode(), { + const msg = await WakuMessage.fromBytes(chatMessage.encode(), { contentTopic: ChatContentTopic, + timestamp: new Date(), }); if (opts.lightPush) { await waku.lightPush.push(msg); diff --git a/examples/eth-dm/src/BroadcastPublicKey.tsx b/examples/eth-dm/src/BroadcastPublicKey.tsx index ccde53371b..d54235d64c 100644 --- a/examples/eth-dm/src/BroadcastPublicKey.tsx +++ b/examples/eth-dm/src/BroadcastPublicKey.tsx @@ -25,18 +25,30 @@ export default function BroadcastPublicKey({ if (!waku) return; if (publicKeyMsg) { - const wakuMsg = encodePublicKeyWakuMessage(publicKeyMsg); - waku.lightPush.push(wakuMsg).catch((e) => { - console.error('Failed to send Public Key Message', e); - }); + encodePublicKeyWakuMessage(publicKeyMsg) + .then((wakuMsg) => { + waku.lightPush.push(wakuMsg).catch((e) => { + console.error('Failed to send Public Key Message', e); + }); + }) + .catch((e) => { + console.log('Failed to encode Public Key Message in Waku Message'); + }); } else { createPublicKeyMessage(signer, ethDmKeyPair.publicKey) .then((msg) => { setPublicKeyMsg(msg); - const wakuMsg = encodePublicKeyWakuMessage(msg); - waku.lightPush.push(wakuMsg).catch((e) => { - console.error('Failed to send Public Key Message', e); - }); + encodePublicKeyWakuMessage(msg) + .then((wakuMsg) => { + waku.lightPush.push(wakuMsg).catch((e) => { + console.error('Failed to send Public Key Message', e); + }); + }) + .catch((e) => { + console.log( + 'Failed to encode Public Key Message in Waku Message' + ); + }); }) .catch((e) => { console.error('Failed to create public key message', e); @@ -56,11 +68,11 @@ export default function BroadcastPublicKey({ ); } -function encodePublicKeyWakuMessage( +async function encodePublicKeyWakuMessage( publicKeyMessage: PublicKeyMessage -): WakuMessage { +): Promise { const payload = publicKeyMessage.encode(); - return WakuMessage.fromBytes(payload, { + return await WakuMessage.fromBytes(payload, { contentTopic: PublicKeyContentTopic, }); } diff --git a/examples/web-chat/src/Room.tsx b/examples/web-chat/src/Room.tsx index 6b93a7d10f..e36981eaac 100644 --- a/examples/web-chat/src/Room.tsx +++ b/examples/web-chat/src/Room.tsx @@ -55,7 +55,7 @@ async function handleMessage( } else { const timestamp = new Date(); const chatMessage = ChatMessage.fromUtf8String(timestamp, nick, message); - const wakuMsg = WakuMessage.fromBytes(chatMessage.encode(), { + const wakuMsg = await WakuMessage.fromBytes(chatMessage.encode(), { contentTopic: ChatContentTopic, timestamp, });