Skip to content

Commit 57950dc

Browse files
committed
feat: claim from savings
1 parent 40bdef3 commit 57950dc

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

src/locales/en/messages.po

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ msgid "Allowance required action"
443443
msgstr "Allowance required action"
444444

445445
#: src/modules/dashboard/DashboardTopPanel.tsx
446+
#: src/modules/sGho/SGhoHeader.tsx
446447
#: src/modules/umbrella/UmbrellaHeader.tsx
447448
msgid "Available rewards"
448449
msgstr "Available rewards"
@@ -2736,6 +2737,7 @@ msgstr "There was some error. Please try changing the parameters or <0><1>copy t
27362737

27372738
#: src/modules/dashboard/DashboardTopPanel.tsx
27382739
#: src/modules/sGho/SGhoDepositPanel.tsx
2740+
#: src/modules/sGho/SGhoHeader.tsx
27392741
#: src/modules/staking/GhoStakingPanel.tsx
27402742
#: src/modules/staking/StakingPanel.tsx
27412743
#: src/modules/umbrella/UmbrellaClaimActions.tsx

src/modules/sGho/SGhoHeader.tsx

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Stake } from '@aave/contract-helpers';
22
import { valueToBigNumber } from '@aave/math-utils';
3+
import { chainId, evmAddress, useUserMeritRewards } from '@aave/react';
34
import { AaveSafetyModule } from '@bgd-labs/aave-address-book';
45
import { Trans } from '@lingui/macro';
5-
import { Box, Stack, Typography, useMediaQuery, useTheme } from '@mui/material';
6+
import { Box, Button, Stack, Typography, useMediaQuery, useTheme } from '@mui/material';
67
import NumberFlow from '@number-flow/react';
78
import { BigNumber } from 'bignumber.js';
89
import { formatEther } from 'ethers/lib/utils';
@@ -14,8 +15,10 @@ import { TopInfoPanel } from 'src/components/TopInfoPanel/TopInfoPanel';
1415
import { useAppDataContext } from 'src/hooks/app-data-provider/useAppDataProvider';
1516
import { StakeTokenFormatted, useGeneralStakeUiData } from 'src/hooks/stake/useGeneralStakeUiData';
1617
import { useUserStakeUiData } from 'src/hooks/stake/useUserStakeUiData';
18+
import { useModalContext } from 'src/hooks/useModal';
1719
import { useStakeTokenAPR } from 'src/hooks/useStakeTokenAPR';
1820
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
21+
import { ZERO_ADDRESS } from 'src/modules/governance/utils/formatProposal';
1922
import { useRootStore } from 'src/store/root';
2023
import { MarketDataType } from 'src/ui-config/marketsConfig';
2124
import { convertAprToApy } from 'src/utils/utils';
@@ -25,6 +28,19 @@ import { TopInfoPanelItem } from '../../components/TopInfoPanel/TopInfoPanelItem
2528
import { AddTokenDropdown } from '../reserve-overview/AddTokenDropdown';
2629
import { TokenLinkDropdown } from '../reserve-overview/TokenLinkDropdown';
2730

31+
interface MeritReward {
32+
amount: {
33+
usd: string;
34+
amount: {
35+
value: string;
36+
};
37+
};
38+
currency: {
39+
symbol: string;
40+
address: string;
41+
};
42+
}
43+
2844
export const SGHOHeader: React.FC = () => {
2945
const theme = useTheme();
3046
const [currentMarketData, trackEvent] = useRootStore(
@@ -113,6 +129,7 @@ const SGhoHeaderUserDetails = ({
113129
const { data: stakeAPR, isLoading: isLoadingStakeAPR } = useStakeTokenAPR();
114130
const { data: stakeUserResult } = useUserStakeUiData(currentMarketData, Stake.gho);
115131
const { reserves } = useAppDataContext();
132+
const { openClaimRewards } = useModalContext();
116133

117134
const {
118135
addERC20Token,
@@ -126,6 +143,17 @@ const SGhoHeaderUserDetails = ({
126143

127144
const downToSM = useMediaQuery(theme.breakpoints.down('sm'));
128145

146+
const { data: meritClaimRewards } = useUserMeritRewards({
147+
// Note: currentAccount is not always defined, so we need to check if it is and if not, use a fallback address
148+
user: currentAccount ? evmAddress(currentAccount) : evmAddress(ZERO_ADDRESS),
149+
chainId: chainId(currentMarketData.chainId),
150+
});
151+
152+
const claimableRewardsUsd =
153+
meritClaimRewards?.claimable?.reduce((total: number, reward: MeritReward) => {
154+
return total + Number(reward.amount.usd || 0);
155+
}, 0) || 0;
156+
129157
const stakeUserData = stakeUserResult?.[0];
130158
const userSGhoBalance = stakeUserData?.stakeTokenRedeemableAmount || '0';
131159
const userSGhoBalanceFormatted = formatEther(userSGhoBalance);
@@ -261,6 +289,45 @@ const SGhoHeaderUserDetails = ({
261289
)}
262290
</TopInfoPanelItem>
263291

292+
{currentAccount && (
293+
<TopInfoPanelItem
294+
title={<Trans>Available rewards</Trans>}
295+
loading={isLoadingStakeAPR}
296+
hideIcon
297+
>
298+
<Box
299+
sx={{
300+
display: 'flex',
301+
alignItems: { xs: 'flex-start', xsm: 'center' },
302+
flexDirection: { xs: 'column', xsm: 'row' },
303+
}}
304+
>
305+
<Box sx={{ display: 'inline-flex', alignItems: 'center' }} data-cy={'Claim_Box'}>
306+
<FormattedNumber
307+
value={claimableRewardsUsd}
308+
variant={valueTypographyVariant}
309+
visibleDecimals={2}
310+
compact
311+
symbol="USD"
312+
symbolsColor="#A5A8B6"
313+
symbolsVariant={symbolsTypographyVariant}
314+
data-cy={'Claim_Value'}
315+
/>
316+
</Box>
317+
318+
<Button
319+
variant="gradient"
320+
size="small"
321+
onClick={() => openClaimRewards()}
322+
sx={{ minWidth: 'unset', ml: { xs: 0, xsm: 2 } }}
323+
data-cy={'SGho_Claim_Button'}
324+
>
325+
<Trans>Claim</Trans>
326+
</Button>
327+
</Box>
328+
</TopInfoPanelItem>
329+
)}
330+
264331
<Box sx={{ display: 'inline-flex', alignItems: 'center', height: '40px' }}>
265332
{poolReserve && (
266333
<>

0 commit comments

Comments
 (0)