Skip to content

Commit

Permalink
Merge pull request #3229 from OlympusDAO/coolerMetricsRPCCalls
Browse files Browse the repository at this point in the history
optimize cooler metrics network requests
  • Loading branch information
brightiron authored Oct 29, 2024
2 parents 31dff6a + d742d48 commit 5f1e9c7
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/views/Lending/Cooler/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Link, Tab, Tabs, useMediaQuery, useTheme } from "@mui/material";
import { Box, Link, Tab, Tabs } from "@mui/material";
import { Icon } from "@olympusdao/component-library";
import { useEffect, useState } from "react";
import { Link as RouterLink, useSearchParams } from "react-router-dom";
Expand All @@ -10,19 +10,16 @@ import { CoolerPositions } from "src/views/Lending/Cooler/positions/Positions";
const PARAM_TAB = "tab";

export const Cooler = () => {
const theme = useTheme();
const mobile = useMediaQuery(theme.breakpoints.down("sm"));

const [tabIndex, setTabIndex] = useState(0);
const [tabIndex, setTabIndex] = useState<string | undefined>(undefined);
const [searchParams] = useSearchParams();
const queryTab = searchParams.get(PARAM_TAB);

// When the page loads, this causes the tab to be set to the correct value
useEffect(() => {
const queryTab = searchParams.get(PARAM_TAB);
setTabIndex(queryTab ? (queryTab === "metrics" ? 1 : 0) : 0);
}, [searchParams]);
setTabIndex(queryTab === "metrics" ? "metrics" : "positions");
}, [queryTab]);

const handleTabChange = (event: React.SyntheticEvent, newValue: number) => {
const handleTabChange = (event: React.SyntheticEvent, newValue: string) => {
setTabIndex(newValue);
};

Expand Down Expand Up @@ -63,12 +60,12 @@ export const Cooler = () => {
//hides the tab underline sliding animation in while <Zoom> is loading
TabIndicatorProps={{ style: { display: "none" } }}
>
<Tab label="Positions" href={`#/lending/cooler?${getSearchParamsWithTab(0)}`} />
<Tab label="Metrics" href={`#/lending/cooler?${getSearchParamsWithTab(1)}`} />
<Tab label="Positions" href={`#/lending/cooler?${getSearchParamsWithTab(0)}`} value="positions" />
<Tab label="Metrics" href={`#/lending/cooler?${getSearchParamsWithTab(1)}`} value="metrics" />
</Tabs>

{tabIndex === 0 && <CoolerPositions />}
{tabIndex === 1 && <CoolerDashboard />}
{tabIndex === "positions" && <CoolerPositions />}
{tabIndex === "metrics" && <CoolerDashboard />}
</Box>
</div>
);
Expand Down

0 comments on commit 5f1e9c7

Please sign in to comment.