From a065a6b107bea008fa17579e99aeec9032912957 Mon Sep 17 00:00:00 2001 From: brightiron Date: Mon, 21 Oct 2024 21:50:43 -0500 Subject: [PATCH 1/4] allow unstaking sOHM --- src/views/MyBalances/MyOhmBalances.tsx | 19 ++++++++++----- .../StakeInputArea/StakeInputArea.tsx | 24 +++++++++++++++---- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/views/MyBalances/MyOhmBalances.tsx b/src/views/MyBalances/MyOhmBalances.tsx index 4a03fc8abb..68e24fc96f 100644 --- a/src/views/MyBalances/MyOhmBalances.tsx +++ b/src/views/MyBalances/MyOhmBalances.tsx @@ -46,9 +46,11 @@ export const MyOhmBalances = () => { {Number(ohmBalances[networks.MAINNET].data?.toString()).toFixed(4) || "0.00"} OHM - - Wrap - + + + Wrap + + )} {ohmBalances[networks.ARBITRUM].data?.gt(dust) && ( @@ -84,9 +86,14 @@ export const MyOhmBalances = () => { {Number(sOhmBalance.toString()).toFixed(4) || "0.00"} sOHM - - Wrap - +
+ + Wrap + + + Unwrap + +
)} {v1OhmBalance.gt(dust) && ( diff --git a/src/views/Stake/components/StakeArea/components/StakeInputArea/StakeInputArea.tsx b/src/views/Stake/components/StakeArea/components/StakeInputArea/StakeInputArea.tsx index 02156f92c5..fbf6ac1c7f 100644 --- a/src/views/Stake/components/StakeArea/components/StakeInputArea/StakeInputArea.tsx +++ b/src/views/Stake/components/StakeArea/components/StakeInputArea/StakeInputArea.tsx @@ -69,13 +69,15 @@ const StyledBox = styled(Box)(({ theme }) => ({ export const StakeInputArea: React.FC<{ isZoomed: boolean }> = props => { const networks = useTestableNetworks(); - const [stakedAssetType, setStakedAssetType] = useState({ name: "gOHM" }); + const [searchParams, setSearchParams] = useSearchParams(); + const [stakedAssetType, setStakedAssetType] = useState({ + name: searchParams.get("token") || "gOHM", + }); const [swapAssetType, setSwapAssetType] = useState({ name: "OHM" }); const { chain = { id: 1 } } = useNetwork(); const [tokenModalOpen, setTokenModalOpen] = useState(false); const [confirmationModalOpen, setConfirmationModalOpen] = useState(false); const wrapMutation = useWrapSohm(); - const [searchParams, setSearchParams] = useSearchParams(); const { data: needsRebase } = useCheckSecondsToNextEpoch(); const triggerRebase = useTriggerZeroDistributorRebase(); @@ -85,6 +87,7 @@ export const StakeInputArea: React.FC<{ isZoomed: boolean }> = props => { // Max balance stuff const [amount, setAmount] = useState(""); const [receiveAmount, setReceiveAmount] = useState(""); + const [targetToAsset, setTargetToAsset] = useState(false); const addresses = fromToken === "OHM" ? OHM_ADDRESSES : fromToken === "sOHM" ? SOHM_ADDRESSES : GOHM_ADDRESSES; const balance = useBalance(addresses)[networks.MAINNET].data; @@ -183,6 +186,8 @@ export const StakeInputArea: React.FC<{ isZoomed: boolean }> = props => { }; const GohmSwapCard = () => { + const dust = new DecimalBigNumber("0.000001", 9); + const balance = stakedAssetType.name === "sOHM" ? sOhmBalance : gOhmBalance; const tokenOnClick = sOhmBalance && !isStake ? { tokenOnClick: () => setTokenModalOpen(true) } : {}; @@ -192,6 +197,14 @@ export const StakeInputArea: React.FC<{ isZoomed: boolean }> = props => { inputProps={{ "data-testid": "staked-input", min: "0" }} token={stakedAssetType.name as OHMSwapCardProps["token"]} value={isStake ? receiveAmount : amount} + tokenOnClick={ + !isStake && sOhmBalance?.gt(dust) + ? () => { + setTargetToAsset(true); + setTokenModalOpen(true); + } + : undefined + } onChange={event => +event.target.value >= 0 && ohmOnChange(event.target.value, !isStake)} info={`Balance: ${balance ? balance.toString({ decimals: 2 }) : "0.00"} ${stakedAssetType.name}`} endString={!isStake ? "Max" : ""} @@ -219,8 +232,11 @@ export const StakeInputArea: React.FC<{ isZoomed: boolean }> = props => { {tokenModalOpen && ( (isStake ? setSwapAssetType(name) : setStakedAssetType(name))} - handleClose={() => setTokenModalOpen(false)} + handleSelect={name => (isStake && !targetToAsset ? setSwapAssetType(name) : setStakedAssetType(name))} + handleClose={() => { + setTokenModalOpen(false); + setTargetToAsset(false); + }} ohmBalance={ohmBalance && ohmBalance.toString({ decimals: 2 })} sOhmBalance={sOhmBalance && sOhmBalance.toString({ decimals: 2 })} gOhmBalance={gOhmBalance && gOhmBalance.toString({ decimals: 2 })} From ded33227ab54b2201773ed160fc4a0ec7bc8fb4e Mon Sep 17 00:00:00 2001 From: brightiron Date: Mon, 21 Oct 2024 21:52:11 -0500 Subject: [PATCH 2/4] cleanup --- src/views/MyBalances/MyOhmBalances.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/views/MyBalances/MyOhmBalances.tsx b/src/views/MyBalances/MyOhmBalances.tsx index 68e24fc96f..fff716f50b 100644 --- a/src/views/MyBalances/MyOhmBalances.tsx +++ b/src/views/MyBalances/MyOhmBalances.tsx @@ -46,11 +46,9 @@ export const MyOhmBalances = () => { {Number(ohmBalances[networks.MAINNET].data?.toString()).toFixed(4) || "0.00"} OHM - - - Wrap - - + + Wrap + )} {ohmBalances[networks.ARBITRUM].data?.gt(dust) && ( From 288ea8cb85185877d1ab02f09e02f8427f8b2e1c Mon Sep 17 00:00:00 2001 From: brightiron Date: Tue, 22 Oct 2024 21:20:50 -0500 Subject: [PATCH 3/4] optimize tab rendering for network requests --- src/views/Lending/Cooler/index.tsx | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/views/Lending/Cooler/index.tsx b/src/views/Lending/Cooler/index.tsx index 2ce6653e18..2455a40fa8 100644 --- a/src/views/Lending/Cooler/index.tsx +++ b/src/views/Lending/Cooler/index.tsx @@ -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"; @@ -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(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); }; @@ -63,12 +60,12 @@ export const Cooler = () => { //hides the tab underline sliding animation in while is loading TabIndicatorProps={{ style: { display: "none" } }} > - - + + - {tabIndex === 0 && } - {tabIndex === 1 && } + {tabIndex === "positions" && } + {tabIndex === "metrics" && } ); From d742d48bb12c9aca1c82cd53d4a168239cdc528f Mon Sep 17 00:00:00 2001 From: Jem <0x0xJem@gmail.com> Date: Mon, 28 Oct 2024 10:38:12 +0400 Subject: [PATCH 4/4] retrigger checks