1- import { normalize , USD_DECIMALS , valueToBigNumber } from '@aave/math-utils' ;
1+ //yarn import { normalize, USD_DECIMALS, valueToBigNumber } from '@aave/math-utils';
22import { Trans } from '@lingui/macro' ;
33import AccessTimeIcon from '@mui/icons-material/AccessTime' ;
44import { keyframes , Stack , Typography } from '@mui/material' ;
55import { formatUnits } from 'ethers/lib/utils' ;
66import { ReactElement } from 'react' ;
77import { ContentWithTooltip } from 'src/components/ContentWithTooltip' ;
88import { FormattedNumber } from 'src/components/primitives/FormattedNumber' ;
9- import { ReserveSubheader } from 'src/components/ReserveSubheader ' ;
9+ import { TokenIcon } from 'src/components/primitives/TokenIcon ' ;
1010import { SecondsToString } from 'src/components/SecondsToString' ;
1111import { timeMessage } from 'src/helpers/timeHelper' ;
1212import { MergedStakeData } from 'src/hooks/stake/useUmbrellaSummary' ;
1313import { useCurrentTimestamp } from 'src/hooks/useCurrentTimestamp' ;
14+ import { useRootStore } from 'src/store/root' ;
1415
1516import { ListValueColumn } from '../dashboard/lists/ListValueColumn' ;
17+ import { MultiIcon } from './helpers/MultiIcon' ;
18+ import { usePreviewRedeem } from './hooks/usePreviewRedeem' ;
1619
17- export const AmountStakedUnderlyingItem = ( { stakeData } : { stakeData : MergedStakeData } ) => {
20+ export const AmountStakedUnderlyingItem = ( {
21+ stakeData,
22+ isMobile,
23+ } : {
24+ stakeData : MergedStakeData ;
25+ isMobile : boolean ;
26+ } ) => {
1827 const now = useCurrentTimestamp ( 1 ) ;
19- const { stakeTokenRedeemableAmount } = stakeData . formattedBalances ;
28+ const currentMarketData = useRootStore ( ( s ) => s . currentMarketData ) ;
29+ const chainId = currentMarketData ?. chainId ;
30+
31+ const {
32+ stakeTokenRedeemableAmount,
33+ underlyingTokenBalance,
34+ stataTokenAssetBalance : underlyingWaTokenBalance ,
35+ } = stakeData . balances ;
36+ const { underlyingTokenAddress, underlyingTokenDecimals, underlyingIsStataToken, decimals } =
37+ stakeData ;
38+
39+ const icons = [ ] ;
40+ if ( underlyingTokenBalance ) {
41+ icons . push ( {
42+ src : stakeData . stataTokenData . assetSymbol ,
43+ aToken : false ,
44+ } ) ;
45+ }
46+ if ( underlyingWaTokenBalance ) {
47+ icons . push ( {
48+ src : stakeData . stataTokenData . assetSymbol ,
49+ aToken : true ,
50+ } ) ;
51+ }
52+ if ( underlyingTokenBalance && Number ( underlyingTokenBalance ) > 0 ) {
53+ icons . push ( {
54+ src : stakeData . stataTokenData . assetSymbol ,
55+ aToken : false ,
56+ waToken : true ,
57+ } ) ;
58+ }
59+
60+ const isGhoToken = ! underlyingIsStataToken ;
61+
62+ const { data : sharesEquivalentAssets = '0' } = usePreviewRedeem (
63+ stakeTokenRedeemableAmount ,
64+ underlyingTokenDecimals ,
65+ underlyingTokenAddress ,
66+ chainId ,
67+ ! isGhoToken
68+ ) ;
69+ const formattedGhoAmount = formatUnits ( stakeTokenRedeemableAmount , decimals ) ;
70+ const assetUnderlyingAmount = isGhoToken ? formattedGhoAmount : sharesEquivalentAssets ;
2071
2172 const endOfCooldown = stakeData ?. cooldownData . endOfCooldown || 0 ;
2273 const unstakeWindow = stakeData ?. cooldownData . withdrawalWindow || 0 ;
@@ -25,28 +76,37 @@ export const AmountStakedUnderlyingItem = ({ stakeData }: { stakeData: MergedSta
2576 stakeData . decimals
2677 ) ;
2778 const cooldownTimeRemaining = endOfCooldown - now ;
28-
2979 const isCooldownActive = cooldownTimeRemaining > 0 ;
3080 const isUnstakeWindowActive = endOfCooldown < now && now < endOfCooldown + unstakeWindow ;
3181 const unstakeTimeRemaining = endOfCooldown + unstakeWindow - now ;
32- const priceUsd = normalize ( stakeData . price , USD_DECIMALS ) ;
33- const redeemableUsd = valueToBigNumber ( stakeTokenRedeemableAmount )
34- . multipliedBy ( priceUsd )
35- . toString ( ) ;
82+
83+ // calculate price in USD
84+ // const priceUsd = normalize(stakeData.price, USD_DECIMALS);
85+ // const redeemableUsd = valueToBigNumber(assetUnderlyingAmount).multipliedBy(priceUsd) .toString();
3686
3787 return (
38- < Stack direction = "column" alignItems = "center" justifyContent = "center" >
88+ < Stack
89+ direction = { isMobile ? 'row' : 'column' }
90+ alignItems = "center"
91+ justifyContent = "center"
92+ gap = { 2 }
93+ >
3994 { ! isCooldownActive && ! isUnstakeWindowActive ? (
4095 < >
41- < FormattedNumber compact value = { stakeTokenRedeemableAmount } variant = "secondary14" />
42- < ReserveSubheader value = { redeemableUsd } />
96+ < FormattedNumber compact value = { assetUnderlyingAmount } variant = "secondary14" />
97+
98+ { stakeData . underlyingIsStataToken ? (
99+ < MultiIcon icons = { icons } />
100+ ) : (
101+ < TokenIcon symbol = { stakeData . symbol } sx = { { fontSize : '24px' } } />
102+ ) }
43103 </ >
44104 ) : (
45105 < ListValueColumn
46- value = { stakeTokenRedeemableAmount }
47- subValue = { redeemableUsd }
106+ value = { assetUnderlyingAmount }
107+ // subValue={redeemableUsd}
48108 withTooltip
49- disabled = { stakeTokenRedeemableAmount === '0' }
109+ disabled = { assetUnderlyingAmount === '0' }
50110 />
51111 ) }
52112 { isCooldownActive && (
0 commit comments