Skip to content

Commit bb1cb6f

Browse files
authored
Remove Information from ReClamm UI and make it cleaner (#1)
1 parent 1faa7e0 commit bb1cb6f

File tree

8 files changed

+874
-486
lines changed

8 files changed

+874
-486
lines changed

client/src/App.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "react-router-dom";
1010
import ReClamm from "./pool-types/reclamm/ReClamm";
1111
import StableSurge from "./pool-types/stable-surge/StableSurge";
12+
import { TimerProvider } from "./contexts/TimerContext";
1213
import styled from "styled-components";
1314

1415
// Styled components for the menus
@@ -106,16 +107,18 @@ const Navigation = () => {
106107

107108
function App() {
108109
return (
109-
<Router>
110-
<Navigation />
111-
<Routes>
112-
<Route path="/" element={<Home />} />
113-
<Route path="/reclamm" element={<ReClamm />} />
114-
<Route path="/acl-amm" element={<Navigate to="/reclamm" />} />
115-
<Route path="/stable-surge" element={<StableSurge />} />
116-
<Route path="*" element={<Navigate to="/" />} />
117-
</Routes>
118-
</Router>
110+
<TimerProvider>
111+
<Router>
112+
<Navigation />
113+
<Routes>
114+
<Route path="/" element={<Home />} />
115+
<Route path="/reclamm" element={<ReClamm />} />
116+
<Route path="/acl-amm" element={<Navigate to="/reclamm" />} />
117+
<Route path="/stable-surge" element={<StableSurge />} />
118+
<Route path="*" element={<Navigate to="/" />} />
119+
</Routes>
120+
</Router>
121+
</TimerProvider>
119122
);
120123
}
121124

client/src/components/Timer.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Paper } from "@mui/material";
2+
import { Button } from "@mui/material";
3+
import { PlayArrow, Pause, FastForward } from "@mui/icons-material";
4+
import { Typography } from "@mui/material";
5+
6+
import { formatTime } from "../utils/Time";
7+
import { useTimer } from "../contexts/TimerContext";
8+
9+
export default function Timer() {
10+
const {
11+
blockNumber,
12+
isPlaying,
13+
setIsPlaying,
14+
setSpeedMultiplier,
15+
simulationSeconds,
16+
speedMultiplier,
17+
} = useTimer();
18+
19+
return (
20+
<Paper
21+
style={{
22+
paddingTop: 16,
23+
paddingLeft: 16,
24+
paddingRight: 16,
25+
paddingBottom: 1,
26+
marginBottom: 16,
27+
}}
28+
>
29+
<div
30+
style={{
31+
display: "flex",
32+
alignItems: "center",
33+
gap: 16,
34+
marginBottom: 16,
35+
}}
36+
>
37+
<Button
38+
variant="contained"
39+
onClick={() => {
40+
setIsPlaying(!isPlaying);
41+
}}
42+
style={{
43+
paddingTop: 8,
44+
paddingBottom: 9,
45+
paddingRight: 5,
46+
minWidth: 0,
47+
}}
48+
startIcon={isPlaying ? <Pause /> : <PlayArrow />}
49+
/>
50+
<Button
51+
variant="contained"
52+
onClick={() => {
53+
setSpeedMultiplier((prev) => (prev * 10 > 1000 ? 1 : prev * 10));
54+
}}
55+
startIcon={<FastForward />}
56+
>
57+
{speedMultiplier}x
58+
</Button>
59+
<Typography
60+
style={{
61+
fontWeight: "bold",
62+
color: isPlaying ? "green" : "red",
63+
}}
64+
>
65+
Simulation time: {formatTime(simulationSeconds)} - Block:{" "}
66+
{blockNumber}
67+
</Typography>
68+
</div>
69+
</Paper>
70+
);
71+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import React, { createContext, useContext, useState, ReactNode } from "react";
2+
3+
interface TimerContextType {
4+
// Timer state
5+
isPlaying: boolean;
6+
setIsPlaying: (playing: boolean | ((p: boolean) => boolean)) => void;
7+
simulationSeconds: number;
8+
setSimulationSeconds: (seconds: number | ((s: number) => number)) => void;
9+
simulationSecondsLastTick: number;
10+
setSimulationSecondsLastTick: (
11+
seconds: number | ((s: number) => number)
12+
) => void;
13+
blockNumber: number;
14+
setBlockNumber: (block: number | ((b: number) => number)) => void;
15+
speedMultiplier: number;
16+
setSpeedMultiplier: (speed: number | ((s: number) => number)) => void;
17+
18+
// Simulation configuration
19+
simulationSecondsPerBlock: number;
20+
setSimulationSecondsPerBlock: (seconds: number) => void;
21+
22+
// Timer control functions
23+
resetTimer: () => void;
24+
pauseTimer: () => void;
25+
playTimer: () => void;
26+
}
27+
28+
const TimerContext = createContext<TimerContextType | undefined>(undefined);
29+
30+
interface TimerProviderProps {
31+
children: ReactNode;
32+
}
33+
34+
export const TimerProvider: React.FC<TimerProviderProps> = ({ children }) => {
35+
// Timer state
36+
const [isPlaying, setIsPlaying] = useState<boolean>(false);
37+
const [simulationSeconds, setSimulationSeconds] = useState<number>(0);
38+
const [simulationSecondsLastTick, setSimulationSecondsLastTick] =
39+
useState<number>(1);
40+
const [blockNumber, setBlockNumber] = useState<number>(0);
41+
const [speedMultiplier, setSpeedMultiplier] = useState<number>(1);
42+
43+
// Simulation configuration
44+
const [simulationSecondsPerBlock, setSimulationSecondsPerBlock] =
45+
useState<number>(12);
46+
47+
// Timer control functions
48+
const resetTimer = () => {
49+
setSimulationSeconds(0);
50+
setBlockNumber(0);
51+
setSimulationSecondsLastTick(1);
52+
setIsPlaying(false);
53+
};
54+
55+
const pauseTimer = () => {
56+
setIsPlaying(false);
57+
};
58+
59+
const playTimer = () => {
60+
setIsPlaying(true);
61+
};
62+
63+
const value: TimerContextType = {
64+
// Timer state
65+
isPlaying,
66+
setIsPlaying,
67+
simulationSeconds,
68+
setSimulationSeconds,
69+
simulationSecondsLastTick,
70+
setSimulationSecondsLastTick,
71+
blockNumber,
72+
setBlockNumber,
73+
speedMultiplier,
74+
setSpeedMultiplier,
75+
76+
// Simulation configuration
77+
simulationSecondsPerBlock,
78+
setSimulationSecondsPerBlock,
79+
80+
// Timer control functions
81+
resetTimer,
82+
pauseTimer,
83+
playTimer,
84+
};
85+
86+
return (
87+
<TimerContext.Provider value={value}>{children}</TimerContext.Provider>
88+
);
89+
};
90+
91+
// Custom hook to use the timer context
92+
export const useTimer = (): TimerContextType => {
93+
const context = useContext(TimerContext);
94+
if (context === undefined) {
95+
throw new Error("useTimer must be used within a TimerProvider");
96+
}
97+
return context;
98+
};

client/src/index.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
body {
22
margin: 0;
3-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4-
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
3+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
4+
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
55
sans-serif;
66
-webkit-font-smoothing: antialiased;
77
-moz-osx-font-smoothing: grayscale;
8+
background-color: #eeeeee;
89
}
910

1011
code {
11-
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12+
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
1213
monospace;
1314
}

0 commit comments

Comments
 (0)