Skip to content

Commit 8ddd8c2

Browse files
committed
feat: show eth denominated value for legacy users
1 parent 62921fc commit 8ddd8c2

File tree

5 files changed

+73
-28
lines changed

5 files changed

+73
-28
lines changed

packages/frontend/src/components/Positions/CrabPosition.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ type CrabPositionType = {
2727
}
2828

2929
const CrabPosition: React.FC<CrabPositionType> = ({
30+
depositedEth,
3031
depositedUsd,
3132
loading,
3233
pnlWMidPriceInPerct,
3334
pnlWMidPriceInUSD,
3435
currentCrabPositionValue,
36+
currentCrabPositionValueInETH,
3537
version,
3638
}) => {
3739
const classes = useStyles()
@@ -66,6 +68,9 @@ const CrabPosition: React.FC<CrabPositionType> = ({
6668
<Typography variant="body1" className={classes.textMonospace}>
6769
{formatCurrency(depositedUsd.toNumber())}
6870
</Typography>
71+
<Typography variant="body2" color="textSecondary">
72+
<span id="pos-page-crab-deposited-amount">{formatNumber(depositedEth.toNumber(), 4)} ETH</span>
73+
</Typography>
6974
</div>
7075

7176
<div className={classes.positionColumn}>
@@ -75,9 +80,14 @@ const CrabPosition: React.FC<CrabPositionType> = ({
7580
{loading ? (
7681
<Loading />
7782
) : (
78-
<Typography variant="body1" className={classes.textMonospace}>
79-
{formatCurrency(currentCrabPositionValue.toNumber())}
80-
</Typography>
83+
<>
84+
<Typography variant="body1" className={classes.textMonospace}>
85+
{formatCurrency(currentCrabPositionValue.toNumber())}
86+
</Typography>
87+
<Typography variant="body2" color="textSecondary">
88+
{formatNumber(currentCrabPositionValueInETH.toNumber(), 4)} ETH
89+
</Typography>
90+
</>
8191
)}
8292
</div>
8393
</div>

packages/frontend/src/components/Positions/CrabPositionV2.tsx

+22-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import { crabStrategyCollatRatioAtom, usdcQueuedAtom, crabQueuedAtom, crabUSDVal
1010
import { Tooltips, USDC_DECIMALS } from '@constants/index'
1111
import { toTokenAmount } from '@utils/calculations'
1212
import { formatCurrency, formatNumber } from '@utils/formatter'
13+
import { useCheckLegacyCrabV2User } from '@hooks/useCheckLegacyUser'
1314
import useStyles from './useStyles'
1415

1516
const Loading: React.FC<{ isSmall?: boolean }> = ({ isSmall = false }) => {
1617
return <Typography variant={isSmall ? 'caption' : 'body1'}>loading...</Typography>
1718
}
1819

1920
type CrabPositionV2Type = {
21+
address: string
2022
depositedEth: BigNumber
2123
depositedUsd: BigNumber
2224
loading: boolean
@@ -28,11 +30,14 @@ type CrabPositionV2Type = {
2830
}
2931

3032
const CrabPositionV2: React.FC<CrabPositionV2Type> = ({
33+
address,
34+
depositedEth,
3135
depositedUsd,
3236
loading,
3337
pnlWMidPriceInPerct,
3438
pnlWMidPriceInUSD,
3539
currentCrabPositionValue,
40+
currentCrabPositionValueInETH,
3641
version,
3742
}) => {
3843
const classes = useStyles()
@@ -45,6 +50,8 @@ const CrabPositionV2: React.FC<CrabPositionV2Type> = ({
4550
useCurrentCrabPositionValue()
4651
useCurrentCrabPositionValueV2()
4752

53+
const isLegacyUser = useCheckLegacyCrabV2User(address ?? '')
54+
4855
useEffect(() => {
4956
setStrategyData()
5057
}, [collatRatio, setStrategyData])
@@ -77,6 +84,11 @@ const CrabPositionV2: React.FC<CrabPositionV2Type> = ({
7784
<Typography variant="body1" className={classes.textMonospace}>
7885
{formatCurrency(depositedUsd.toNumber())}
7986
</Typography>
87+
{isLegacyUser && (
88+
<Typography variant="body2" color="textSecondary">
89+
<span id="pos-page-crab-deposited-amount">{formatNumber(depositedEth.toNumber(), 4)} ETH</span>
90+
</Typography>
91+
)}
8092
</div>
8193

8294
<div className={classes.positionColumn}>
@@ -87,9 +99,16 @@ const CrabPositionV2: React.FC<CrabPositionV2Type> = ({
8799
{loading ? (
88100
<Loading />
89101
) : (
90-
<Typography variant="body1" className={classes.textMonospace}>
91-
{formatCurrency(currentCrabPositionValue.toNumber())}
92-
</Typography>
102+
<>
103+
<Typography variant="body1" className={classes.textMonospace}>
104+
{formatCurrency(currentCrabPositionValue.toNumber())}
105+
</Typography>
106+
{isLegacyUser && (
107+
<Typography variant="body2" color="textSecondary">
108+
{formatNumber(currentCrabPositionValueInETH.toNumber(), 4)} ETH
109+
</Typography>
110+
)}
111+
</>
93112
)}
94113
</div>
95114
</div>

packages/frontend/src/components/Positions/Positions.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import useAppEffect from '@hooks/useAppEffect'
2828
import { crabQueuedInUsdAtom } from '@state/crab/atoms'
2929
import { useBullPosition } from '@hooks/useBullPosition'
3030
import { useInitBullStrategy } from '@state/bull/hooks'
31-
import useStyles from './useStyles'
3231
import CrabPosition from './CrabPosition'
3332
import CrabPositionV2 from './CrabPositionV2'
3433
import LongSqueeth from './LongSqueeth'
@@ -38,7 +37,6 @@ import MintedSqueeth from './MintedSqueeth'
3837
import BullPosition from './BullPosition'
3938

4039
const Positions: React.FC = () => {
41-
const classes = useStyles()
4240
const address = useAtomValue(addressAtom)
4341
const positionType = useAtomValue(positionTypeAtom)
4442

@@ -145,6 +143,7 @@ const Positions: React.FC = () => {
145143

146144
{!!address && currentCrabPositionValueInETHV2.isGreaterThan(0) && (
147145
<CrabPositionV2
146+
address={address}
148147
depositedEth={depositedEthV2}
149148
depositedUsd={depositedUsdV2}
150149
loading={isCrabV2loading}

packages/frontend/src/components/Strategies/Crab/CrabTradeV2/Withdraw.tsx

+4-20
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
useQueueWithdrawCrab,
3535
} from '@state/crab/hooks'
3636
import { readyAtom } from '@state/squeethPool/atoms'
37-
import { useUserCrabV2TxHistory } from '@hooks/useUserCrabV2TxHistory'
37+
import { useCheckLegacyCrabV2User } from '@hooks/useCheckLegacyUser'
3838
import {
3939
dailyHistoricalFundingAtom,
4040
impliedVolAtom,
@@ -73,8 +73,6 @@ import { CrabTradeTransactionType, CrabTradeType, CrabTransactionConfirmation, O
7373
import { CRAB_EVENTS } from '@utils/amplitude'
7474
import useAmplitude from '@hooks/useAmplitude'
7575
import useExecuteOnce from '@hooks/useExecuteOnce'
76-
import useAppEffect from '@hooks/useAppEffect'
77-
import { CrabStrategyV2TxType, CrabStrategyTxType } from 'src/types'
7876
import useTrackTransactionFlow from '@hooks/useTrackTransactionFlow'
7977

8078
enum WithdrawSteps {
@@ -150,7 +148,6 @@ const CrabWithdraw: React.FC<{ onTxnConfirm: (txn: CrabTransactionConfirmation)
150148
const address = useAtomValue(addressAtom)
151149
const { allowance: crabAllowance, approve: approveCrab } = useUserAllowance(crabStrategy2, crabHelper)
152150
const { allowance: crabQueueAllowance, approve: approveQueueCrab } = useUserAllowance(crabStrategy2, crabNetting)
153-
const { data } = useUserCrabV2TxHistory(address ?? '')
154151

155152
const impliedVol = useAtomValue(impliedVolAtom)
156153
const normFactor = useAtomValue(normFactorAtom)
@@ -179,23 +176,10 @@ const CrabWithdraw: React.FC<{ onTxnConfirm: (txn: CrabTransactionConfirmation)
179176
[track],
180177
)
181178

182-
useAppEffect(() => {
183-
// show token toggle only if the user has deposited before 28th December 00:00 UTC, the launch date of new design
184-
const launchDate = new Date('2022-12-28T00:00:00.000Z').getTime() / 1000
185-
const isLegacyUser =
186-
data?.some((tx) => {
187-
const isDepositTx =
188-
tx.type === CrabStrategyV2TxType.FLASH_DEPOSIT ||
189-
tx.type === CrabStrategyV2TxType.DEPOSIT ||
190-
tx.type === CrabStrategyV2TxType.DEPOSIT_V1 ||
191-
tx.type === CrabStrategyTxType.DEPOSIT ||
192-
tx.type === CrabStrategyV2TxType.OTC_DEPOSIT
193-
194-
return isDepositTx && tx.timestamp < launchDate
195-
}) ?? false
196-
179+
const isLegacyUser = useCheckLegacyCrabV2User(address ?? '')
180+
useEffect(() => {
197181
setShowTokenToggle(isLegacyUser)
198-
}, [data])
182+
}, [isLegacyUser])
199183

200184
const withdrawPriceImpactWarning = useAppMemo(() => {
201185
if (useQueue) return false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useState } from 'react'
2+
3+
import { useUserCrabV2TxHistory } from './useUserCrabV2TxHistory'
4+
import useAppEffect from './useAppEffect'
5+
import { CrabStrategyV2TxType, CrabStrategyTxType } from 'src/types'
6+
7+
// legacy as in users who deposited before ETH deposit was removed
8+
export const useCheckLegacyCrabV2User = (address: string) => {
9+
const [isLegacyUser, setLegacyUser] = useState(false)
10+
11+
const { data } = useUserCrabV2TxHistory(address ?? '')
12+
13+
useAppEffect(() => {
14+
// launch date of new design, when we removed ETH deposit / withdraw
15+
const launchDate = new Date('2022-12-28T00:00:00.000Z').getTime() / 1000
16+
17+
const isLegacy =
18+
data?.some((tx) => {
19+
const isDepositTx =
20+
tx.type === CrabStrategyV2TxType.FLASH_DEPOSIT ||
21+
tx.type === CrabStrategyV2TxType.DEPOSIT ||
22+
tx.type === CrabStrategyV2TxType.DEPOSIT_V1 ||
23+
tx.type === CrabStrategyTxType.DEPOSIT ||
24+
tx.type === CrabStrategyV2TxType.OTC_DEPOSIT
25+
26+
return isDepositTx && tx.timestamp < launchDate
27+
}) ?? false
28+
29+
setLegacyUser(isLegacy)
30+
}, [data])
31+
32+
return isLegacyUser
33+
}

0 commit comments

Comments
 (0)