From 1370a6d0c496a64c589156dd5a6e6b02429455ab Mon Sep 17 00:00:00 2001 From: Sasha Date: Wed, 29 Nov 2023 11:57:08 +0100 Subject: [PATCH 1/3] add fixes' --- src/services/rln.ts | 9 ++++++--- src/services/waku.ts | 6 +++--- src/utils/http.ts | 17 ++++++++++------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/services/rln.ts b/src/services/rln.ts index be2a1b9..507f5e8 100644 --- a/src/services/rln.ts +++ b/src/services/rln.ts @@ -109,9 +109,12 @@ export class RLN implements IRLN { private initKeystore(): Keystore { const localKeystoreString = localStorage.getItem("keystore"); - const _keystore = Keystore.fromString(localKeystoreString || ""); - - return _keystore || Keystore.create(); + + try { + return Keystore.fromString(localKeystoreString || ""); + } catch(error) { + return Keystore.create(); + } } public addEventListener(name: RLNEventsNames, fn: EventListener) { diff --git a/src/services/waku.ts b/src/services/waku.ts index a2e69c2..bd18ac1 100644 --- a/src/services/waku.ts +++ b/src/services/waku.ts @@ -53,7 +53,7 @@ class Relay { this.subscriptionRoutine = window.setInterval(async () => { await this.fetchMessages(); - }, SECOND); + }, 10 * SECOND); this.contentTopicListeners.set(contentTopic, 1); } catch (error) { @@ -83,8 +83,8 @@ class Relay { this.contentTopicListeners.delete(contentTopic); } - private async fetchMessages(): Promise { - const contentTopic = Object.keys(this.contentTopicListeners)[0]; + private async fetchMessages(): Promise { + const contentTopic = Array.from(this.contentTopicListeners.keys())[0]; if (!contentTopic) { return; diff --git a/src/utils/http.ts b/src/utils/http.ts index 4dcfa25..461bf3f 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -5,9 +5,7 @@ export const http = { mode: "no-cors", referrerPolicy: "no-referrer", headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - "Access-Control-Allow-Origin": "*", + 'Content-Type': 'text/plain', }, body: JSON.stringify(body) }); @@ -18,14 +16,19 @@ export const http = { mode: "no-cors", referrerPolicy: "no-referrer", headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - "Access-Control-Allow-Origin": "*", + 'Content-Type': 'text/plain', }, body: JSON.stringify(body) }); }, get(url: string) { - return fetch(new URL(url)); + return fetch(new URL(url), { + method: "GET", + mode: "no-cors", + referrerPolicy: "no-referrer", + headers: { + 'Content-Type': 'text/plain' + }, + }); } }; \ No newline at end of file From d13c4ec382c0464ce2c2a6936ba93c8755094901 Mon Sep 17 00:00:00 2001 From: Sasha Date: Wed, 29 Nov 2023 11:59:32 +0100 Subject: [PATCH 2/3] remove no cors --- src/utils/http.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/utils/http.ts b/src/utils/http.ts index 461bf3f..47e8522 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -22,13 +22,6 @@ export const http = { }); }, get(url: string) { - return fetch(new URL(url), { - method: "GET", - mode: "no-cors", - referrerPolicy: "no-referrer", - headers: { - 'Content-Type': 'text/plain' - }, - }); + return fetch(new URL(url)); } }; \ No newline at end of file From 1000d4573635dda3d45b8c4046b89f0e5817121d Mon Sep 17 00:00:00 2001 From: Sasha Date: Wed, 29 Nov 2023 12:00:23 +0100 Subject: [PATCH 3/3] fix type --- src/services/waku.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/waku.ts b/src/services/waku.ts index bd18ac1..b5e3c28 100644 --- a/src/services/waku.ts +++ b/src/services/waku.ts @@ -83,7 +83,7 @@ class Relay { this.contentTopicListeners.delete(contentTopic); } - private async fetchMessages(): Promise { + private async fetchMessages(): Promise { const contentTopic = Array.from(this.contentTopicListeners.keys())[0]; if (!contentTopic) {