From aa34b50c608366b1fa0e00c7b707c75ea294be21 Mon Sep 17 00:00:00 2001
From: alcercu <333aleix333@gmail.com>
Date: Fri, 15 Mar 2024 13:43:03 +0100
Subject: [PATCH] fix(web): safely fetch sortition module phase
---
web/src/hooks/useSortitionModulePhase.ts | 7 +++++++
web/src/layout/Header/navbar/Debug.tsx | 12 +++++-------
2 files changed, 12 insertions(+), 7 deletions(-)
create mode 100644 web/src/hooks/useSortitionModulePhase.ts
diff --git a/web/src/hooks/useSortitionModulePhase.ts b/web/src/hooks/useSortitionModulePhase.ts
new file mode 100644
index 000000000..1f098cc7e
--- /dev/null
+++ b/web/src/hooks/useSortitionModulePhase.ts
@@ -0,0 +1,7 @@
+import { useSortitionModuleRead } from "hooks/contracts/generated";
+
+export const useSortitionModulePhase = () => {
+ // eslint-disable-next-line
+ // @ts-ignore
+ return useSortitionModuleRead({ functionName: "phase", watch: true });
+};
diff --git a/web/src/layout/Header/navbar/Debug.tsx b/web/src/layout/Header/navbar/Debug.tsx
index 8415b0b52..5b37f84ec 100644
--- a/web/src/layout/Header/navbar/Debug.tsx
+++ b/web/src/layout/Header/navbar/Debug.tsx
@@ -1,8 +1,9 @@
import React, { useMemo } from "react";
import styled from "styled-components";
-import { useSortitionModulePhase } from "hooks/contracts/generated";
-import { useToggleTheme } from "hooks/useToggleThemeContext";
+
import { GIT_BRANCH, GIT_DIRTY, GIT_HASH, GIT_TAGS, GIT_URL, RELEASE_VERSION } from "consts/index";
+import { useSortitionModulePhase } from "hooks/useSortitionModulePhase";
+import { useToggleTheme } from "hooks/useToggleThemeContext";
import { isUndefined } from "utils/index";
const Container = styled.div`
@@ -57,11 +58,8 @@ enum Phases {
}
const Phase = () => {
- if (isUndefined(useSortitionModulePhase)) return <>>;
- const { data: phase } = useSortitionModulePhase({
- watch: true,
- });
- return <>{isUndefined(phase) ? null : Phase: {Phases[phase]}}>;
+ const { data: phase } = useSortitionModulePhase();
+ return <>{isUndefined(phase) ? null : Phase: {Phases[phase as number]}}>;
};
const Debug: React.FC = () => {