Skip to content

Commit ec0e43f

Browse files
committed
refactor(web): abstract-phase-component
1 parent 1e8cd15 commit ec0e43f

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

web/src/components/Phase.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from "react";
2+
import styled from "styled-components";
3+
4+
import { useSortitionModulePhase } from "hooks/useSortitionModulePhase";
5+
6+
import { isUndefined } from "src/utils";
7+
8+
export enum Phases {
9+
staking,
10+
generating,
11+
drawing,
12+
}
13+
14+
const StyledLabel = styled.label``;
15+
16+
const Phase: React.FC<{ className?: string }> = ({ className }) => {
17+
const { data: phase } = useSortitionModulePhase();
18+
return <>{isUndefined(phase) ? null : <StyledLabel {...{ className }}>Phase: {Phases[phase]}</StyledLabel>}</>;
19+
};
20+
21+
export default Phase;

web/src/layout/Header/navbar/Debug.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import React, { useMemo } from "react";
22
import styled from "styled-components";
33

44
import { GIT_BRANCH, GIT_DIRTY, GIT_HASH, GIT_TAGS, GIT_URL, RELEASE_VERSION } from "consts/index";
5-
import { useSortitionModulePhase } from "hooks/useSortitionModulePhase";
65
import { useToggleTheme } from "hooks/useToggleThemeContext";
76
import { isUndefined } from "utils/index";
87

8+
import Phase from "components/Phase";
9+
910
const Container = styled.div`
1011
display: flex;
1112
flex-direction: column;
@@ -32,6 +33,10 @@ const StyledLabel = styled.label`
3233
padding-left: 8px;
3334
`;
3435

36+
const StyledPhase = styled(Phase)`
37+
padding-left: 8px;
38+
`;
39+
3540
const Version = () => (
3641
<StyledLabel>
3742
v{RELEASE_VERSION}{" "}
@@ -51,23 +56,12 @@ const ServicesStatus = () => {
5156
return <label>{isUndefined(statusUrl) ? null : <StyledIframe src={`${statusUrl + statusUrlParameters}`} />}</label>;
5257
};
5358

54-
enum Phases {
55-
staking,
56-
generating,
57-
drawing,
58-
}
59-
60-
export const Phase = () => {
61-
const { data: phase } = useSortitionModulePhase();
62-
return <>{isUndefined(phase) ? null : <StyledLabel>Phase: {Phases[phase as number]}</StyledLabel>}</>;
63-
};
64-
6559
const Debug: React.FC = () => {
6660
return (
6761
<Container>
6862
<ServicesStatus />
6963
<Version />
70-
<Phase />
64+
<StyledPhase />
7165
</Container>
7266
);
7367
};

web/src/pages/Courts/StakeMaintenanceButton/ExecuteDelayedStakeButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import { wrapWithToast } from "utils/wrapWithToast";
1616

1717
import { isUndefined } from "src/utils";
1818

19-
import { IBaseStakeMaintenanceButton, Phases } from ".";
19+
import { Phases } from "components/Phase";
20+
21+
import { IBaseStakeMaintenanceButton } from ".";
2022

2123
const StyledButton = styled(Button)`
2224
width: 100%;

web/src/pages/Courts/StakeMaintenanceButton/PassPhaseButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import { wrapWithToast } from "utils/wrapWithToast";
1818

1919
import { isUndefined } from "src/utils";
2020

21-
import { IBaseStakeMaintenanceButton, Phases } from ".";
21+
import { Phases } from "components/Phase";
22+
23+
import { IBaseStakeMaintenanceButton } from ".";
2224

2325
const StyledButton = styled(Button)`
2426
width: 100%;

web/src/pages/Courts/StakeMaintenanceButton/index.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import styled from "styled-components";
44
import DottedMenuButton from "components/DottedMenuButton";
55
import { EnsureChain } from "components/EnsureChain";
66
import { Overlay } from "components/Overlay";
7-
import { Phase } from "layout/Header/navbar/Debug";
7+
import Phase from "components/Phase";
88

99
import ExecuteDelayedStakeButton from "./ExecuteDelayedStakeButton";
1010
import PassPhaseButton from "./PassPhaseButton";
@@ -37,12 +37,6 @@ const PopupContainer = styled.div`
3737
transform: translate(-100%, 100%);
3838
`;
3939

40-
export enum Phases {
41-
staking,
42-
generating,
43-
drawing,
44-
}
45-
4640
export interface IBaseStakeMaintenanceButton {
4741
setIsOpen: (open: boolean) => void;
4842
}

0 commit comments

Comments
 (0)