Skip to content

Commit

Permalink
fix(web): safely fetch sortition module phase
Browse files Browse the repository at this point in the history
  • Loading branch information
alcercu committed Mar 15, 2024
1 parent 3b0bbd4 commit aa34b50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 7 additions & 0 deletions web/src/hooks/useSortitionModulePhase.ts
Original file line number Diff line number Diff line change
@@ -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 });
};
12 changes: 5 additions & 7 deletions web/src/layout/Header/navbar/Debug.tsx
Original file line number Diff line number Diff line change
@@ -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`
Expand Down Expand Up @@ -57,11 +58,8 @@ enum Phases {
}

const Phase = () => {
if (isUndefined(useSortitionModulePhase)) return <></>;
const { data: phase } = useSortitionModulePhase({
watch: true,
});
return <>{isUndefined(phase) ? null : <StyledLabel>Phase: {Phases[phase]}</StyledLabel>}</>;
const { data: phase } = useSortitionModulePhase();
return <>{isUndefined(phase) ? null : <StyledLabel>Phase: {Phases[phase as number]}</StyledLabel>}</>;
};

const Debug: React.FC = () => {
Expand Down

0 comments on commit aa34b50

Please sign in to comment.