From a065a6b107bea008fa17579e99aeec9032912957 Mon Sep 17 00:00:00 2001 From: brightiron Date: Mon, 21 Oct 2024 21:50:43 -0500 Subject: [PATCH 1/2] 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/2] 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) && (