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();
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);

View File

@ -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<WakuMessage> {
const payload = publicKeyMessage.encode();
return WakuMessage.fromBytes(payload, {
return await WakuMessage.fromBytes(payload, {
contentTopic: PublicKeyContentTopic,
});
}

View File

@ -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,
});