From b29546874e4a3f9ca9bd7706087026139bf4a06a Mon Sep 17 00:00:00 2001 From: ljankoschek Date: Sun, 30 Jun 2024 21:09:27 +0200 Subject: [PATCH 1/6] try fix with retry on error --- .../screens/LinkedOrganizationsScreen.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fe1-web/src/features/linked-organizations/screens/LinkedOrganizationsScreen.tsx b/fe1-web/src/features/linked-organizations/screens/LinkedOrganizationsScreen.tsx index f7eecaafaf..6006ff3e63 100644 --- a/fe1-web/src/features/linked-organizations/screens/LinkedOrganizationsScreen.tsx +++ b/fe1-web/src/features/linked-organizations/screens/LinkedOrganizationsScreen.tsx @@ -50,9 +50,17 @@ const LinkedOrganizationsScreen = () => { useEffect(() => { const fetchData = async (linkedOrgId: Hash) => { const channel = channelFromIds(linkedOrgId); - await subscribeToChannel(linkedOrgId, dispatch, channel); - await catchup(channel); - // sometimes there are erros without the extra waiting time - temporary fix + let successful = false; + + while (!successful) { + try { + await subscribeToChannel(linkedOrgId, dispatch, channel); + await catchup(channel); + successful = true; + } catch (error) { + + } + } await new Promise((f) => setTimeout(f, 1000)); setLinkedLaoId(linkedOrgId); }; From e63f180f000e50ae35c7e7e2fa359ce88a26c7d1 Mon Sep 17 00:00:00 2001 From: ljankoschek Date: Sun, 30 Jun 2024 21:54:27 +0200 Subject: [PATCH 2/6] fix eslint error --- .../screens/LinkedOrganizationsScreen.tsx | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/fe1-web/src/features/linked-organizations/screens/LinkedOrganizationsScreen.tsx b/fe1-web/src/features/linked-organizations/screens/LinkedOrganizationsScreen.tsx index 6006ff3e63..276e961d57 100644 --- a/fe1-web/src/features/linked-organizations/screens/LinkedOrganizationsScreen.tsx +++ b/fe1-web/src/features/linked-organizations/screens/LinkedOrganizationsScreen.tsx @@ -50,19 +50,24 @@ const LinkedOrganizationsScreen = () => { useEffect(() => { const fetchData = async (linkedOrgId: Hash) => { const channel = channelFromIds(linkedOrgId); - let successful = false; - - while (!successful) { - try { - await subscribeToChannel(linkedOrgId, dispatch, channel); - await catchup(channel); - successful = true; - } catch (error) { - + let counter = 0; + const subscribeAndCatchup = async (): Promise => { + try { + await subscribeToChannel(linkedOrgId, dispatch, channel); + await catchup(channel); + await new Promise((resolve) => setTimeout(resolve, 2000)); + setLinkedLaoId(linkedOrgId); + } catch (error) { + console.log(error); + if (counter >= 10) { + return; } - } - await new Promise((f) => setTimeout(f, 1000)); - setLinkedLaoId(linkedOrgId); + counter += 1; + await new Promise((resolve) => setTimeout(resolve, 5000)); // wait before retrying + await subscribeAndCatchup(); // retry by calling the function recursively + } + }; + await subscribeAndCatchup(); }; if ( recvChallengeState && From d39ab77697454d67291b2ecca35383bbac56fba1 Mon Sep 17 00:00:00 2001 From: ljankoschek Date: Sun, 30 Jun 2024 22:58:03 +0200 Subject: [PATCH 3/6] revert last change --- fe1-web/src/features/lao/reducer/LaoServerReducer.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fe1-web/src/features/lao/reducer/LaoServerReducer.ts b/fe1-web/src/features/lao/reducer/LaoServerReducer.ts index ffbc2329f6..3164513436 100644 --- a/fe1-web/src/features/lao/reducer/LaoServerReducer.ts +++ b/fe1-web/src/features/lao/reducer/LaoServerReducer.ts @@ -60,9 +60,8 @@ const serverSlice = createSlice({ } if (server.address in laoState.byAddress) { - throw Error( - `${server.address} is already part of laoState.byAddress. Use updateServer() instead of addServer()`, - ); + updateServer(new Hash(server.laoId), server.address, server); + return; } laoState.byAddress[server.address] = server; From 3a86da9e1e98beac70577900dec9563d42428689 Mon Sep 17 00:00:00 2001 From: ljankoschek Date: Sun, 30 Jun 2024 22:59:41 +0200 Subject: [PATCH 4/6] revert last change --- fe1-web/src/features/lao/reducer/LaoServerReducer.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fe1-web/src/features/lao/reducer/LaoServerReducer.ts b/fe1-web/src/features/lao/reducer/LaoServerReducer.ts index 3164513436..ffbc2329f6 100644 --- a/fe1-web/src/features/lao/reducer/LaoServerReducer.ts +++ b/fe1-web/src/features/lao/reducer/LaoServerReducer.ts @@ -60,8 +60,9 @@ const serverSlice = createSlice({ } if (server.address in laoState.byAddress) { - updateServer(new Hash(server.laoId), server.address, server); - return; + throw Error( + `${server.address} is already part of laoState.byAddress. Use updateServer() instead of addServer()`, + ); } laoState.byAddress[server.address] = server; From a35d7010399191a7911dc3e64d6b64a06bc6e20d Mon Sep 17 00:00:00 2001 From: ljankoschek Date: Sun, 30 Jun 2024 23:07:39 +0200 Subject: [PATCH 5/6] readd updateserver --- fe1-web/src/features/lao/reducer/LaoServerReducer.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fe1-web/src/features/lao/reducer/LaoServerReducer.ts b/fe1-web/src/features/lao/reducer/LaoServerReducer.ts index ffbc2329f6..3164513436 100644 --- a/fe1-web/src/features/lao/reducer/LaoServerReducer.ts +++ b/fe1-web/src/features/lao/reducer/LaoServerReducer.ts @@ -60,9 +60,8 @@ const serverSlice = createSlice({ } if (server.address in laoState.byAddress) { - throw Error( - `${server.address} is already part of laoState.byAddress. Use updateServer() instead of addServer()`, - ); + updateServer(new Hash(server.laoId), server.address, server); + return; } laoState.byAddress[server.address] = server; From b330fb9edca9e53c600d5146c058f31f8376826c Mon Sep 17 00:00:00 2001 From: ljankoschek Date: Sun, 30 Jun 2024 23:44:51 +0200 Subject: [PATCH 6/6] revert last change --- fe1-web/src/features/lao/reducer/LaoServerReducer.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fe1-web/src/features/lao/reducer/LaoServerReducer.ts b/fe1-web/src/features/lao/reducer/LaoServerReducer.ts index 3164513436..ffbc2329f6 100644 --- a/fe1-web/src/features/lao/reducer/LaoServerReducer.ts +++ b/fe1-web/src/features/lao/reducer/LaoServerReducer.ts @@ -60,8 +60,9 @@ const serverSlice = createSlice({ } if (server.address in laoState.byAddress) { - updateServer(new Hash(server.laoId), server.address, server); - return; + throw Error( + `${server.address} is already part of laoState.byAddress. Use updateServer() instead of addServer()`, + ); } laoState.byAddress[server.address] = server;