Align examples

This commit is contained in:
Franck Royer 2021-07-09 11:39:31 +10:00
parent 22c716e0e6
commit 4f50ca1732
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 26 additions and 13 deletions

View File

@ -104,8 +104,9 @@ export default async function startChat(): Promise<void> {
rl.prompt(); rl.prompt();
const chatMessage = ChatMessage.fromUtf8String(new Date(), nick, line); const chatMessage = ChatMessage.fromUtf8String(new Date(), nick, line);
const msg = WakuMessage.fromBytes(chatMessage.encode(), { const msg = await WakuMessage.fromBytes(chatMessage.encode(), {
contentTopic: ChatContentTopic, contentTopic: ChatContentTopic,
timestamp: new Date(),
}); });
if (opts.lightPush) { if (opts.lightPush) {
await waku.lightPush.push(msg); await waku.lightPush.push(msg);

View File

@ -25,18 +25,30 @@ export default function BroadcastPublicKey({
if (!waku) return; if (!waku) return;
if (publicKeyMsg) { if (publicKeyMsg) {
const wakuMsg = encodePublicKeyWakuMessage(publicKeyMsg); encodePublicKeyWakuMessage(publicKeyMsg)
waku.lightPush.push(wakuMsg).catch((e) => { .then((wakuMsg) => {
console.error('Failed to send Public Key Message', e); 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 { } else {
createPublicKeyMessage(signer, ethDmKeyPair.publicKey) createPublicKeyMessage(signer, ethDmKeyPair.publicKey)
.then((msg) => { .then((msg) => {
setPublicKeyMsg(msg); setPublicKeyMsg(msg);
const wakuMsg = encodePublicKeyWakuMessage(msg); encodePublicKeyWakuMessage(msg)
waku.lightPush.push(wakuMsg).catch((e) => { .then((wakuMsg) => {
console.error('Failed to send Public Key Message', e); 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) => { .catch((e) => {
console.error('Failed to create public key message', 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 publicKeyMessage: PublicKeyMessage
): WakuMessage { ): Promise<WakuMessage> {
const payload = publicKeyMessage.encode(); const payload = publicKeyMessage.encode();
return WakuMessage.fromBytes(payload, { return await WakuMessage.fromBytes(payload, {
contentTopic: PublicKeyContentTopic, contentTopic: PublicKeyContentTopic,
}); });
} }

View File

@ -55,7 +55,7 @@ async function handleMessage(
} else { } else {
const timestamp = new Date(); const timestamp = new Date();
const chatMessage = ChatMessage.fromUtf8String(timestamp, nick, message); const chatMessage = ChatMessage.fromUtf8String(timestamp, nick, message);
const wakuMsg = WakuMessage.fromBytes(chatMessage.encode(), { const wakuMsg = await WakuMessage.fromBytes(chatMessage.encode(), {
contentTopic: ChatContentTopic, contentTopic: ChatContentTopic,
timestamp, timestamp,
}); });