Skip to content

Commit 58a345e

Browse files
committed
feat: added calculation to get the aggregated amount of the underlying token
1 parent a6274e9 commit 58a345e

File tree

8 files changed

+88
-26
lines changed

8 files changed

+88
-26
lines changed

src/locales/el/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,10 @@ msgstr "Asset category"
810810
msgid "Withdraw GHO"
811811
msgstr "Withdraw GHO"
812812

813+
#: src/modules/umbrella/StakeAssets/UmbrellaAssetsListMobileItem.tsx
814+
msgid "Your staked underlying"
815+
msgstr "Your staked underlying"
816+
813817
#: src/modules/reserve-overview/ReserveConfiguration.tsx
814818
msgid "This asset is frozen due to an Aave community decision. <0>More details</0>"
815819
msgstr "This asset is frozen due to an Aave community decision. <0>More details</0>"
@@ -2365,10 +2369,6 @@ msgstr "Borrowing is disabled due to an Aave community decision. <0>More details
23652369
msgid "Collateral usage"
23662370
msgstr "Collateral usage"
23672371

2368-
#: src/modules/umbrella/StakeAssets/UmbrellaAssetsListMobileItem.tsx
2369-
msgid "Your staked underlying amount"
2370-
msgstr "Your staked underlying amount"
2371-
23722372
#: src/modules/history/actions/BorrowRateModeBlock.tsx
23732373
msgid "Variable"
23742374
msgstr "Variable"

src/locales/es/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/fr/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/modules/umbrella/AmountStakedUnderlyingItem.tsx

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,73 @@
1-
import { normalize, USD_DECIMALS, valueToBigNumber } from '@aave/math-utils';
1+
//yarn import { normalize, USD_DECIMALS, valueToBigNumber } from '@aave/math-utils';
22
import { Trans } from '@lingui/macro';
33
import AccessTimeIcon from '@mui/icons-material/AccessTime';
44
import { keyframes, Stack, Typography } from '@mui/material';
55
import { formatUnits } from 'ethers/lib/utils';
66
import { ReactElement } from 'react';
77
import { ContentWithTooltip } from 'src/components/ContentWithTooltip';
88
import { FormattedNumber } from 'src/components/primitives/FormattedNumber';
9-
import { ReserveSubheader } from 'src/components/ReserveSubheader';
9+
import { TokenIcon } from 'src/components/primitives/TokenIcon';
1010
import { SecondsToString } from 'src/components/SecondsToString';
1111
import { timeMessage } from 'src/helpers/timeHelper';
1212
import { MergedStakeData } from 'src/hooks/stake/useUmbrellaSummary';
1313
import { useCurrentTimestamp } from 'src/hooks/useCurrentTimestamp';
14+
import { useRootStore } from 'src/store/root';
1415

1516
import { 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 && (

src/modules/umbrella/StakeAssets/UmbrellaAssetsListMobileItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ export const UmbrellaAssetsListMobileItem = ({ ...umbrellaStakeAsset }: MergedSt
4545
</Box>
4646
</Row>
4747
<Row
48-
caption={<Trans>Your staked underlying amount</Trans>}
48+
caption={<Trans>Your staked underlying</Trans>}
4949
captionVariant="description"
5050
mb={3}
5151
align="flex-start"
5252
>
53-
<AmountStakedUnderlyingItem stakeData={umbrellaStakeAsset} />
53+
<AmountStakedUnderlyingItem stakeData={umbrellaStakeAsset} isMobile />
5454
</Row>
5555
<Row caption={<Trans>Shares</Trans>} captionVariant="description" mb={3} align="flex-start">
5656
<AmountSharesItem stakeData={umbrellaStakeAsset} />

src/modules/umbrella/hooks/usePreviewRedeem.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export const usePreviewRedeem = (
88
amount: string,
99
decimals: number,
1010
stataTokenAddress: string,
11-
chainId: ChainId
11+
chainId: ChainId,
12+
enabled = true
1213
) => {
1314
return useQuery({
1415
queryFn: async () => {
@@ -26,5 +27,6 @@ export const usePreviewRedeem = (
2627
return formatUnits(shares, decimals);
2728
},
2829
queryKey: ['umbrella', 'previewRedeem', amount, stataTokenAddress],
30+
enabled: enabled,
2931
});
3032
};

0 commit comments

Comments
 (0)