Skip to content

Commit 7da6c3a

Browse files
committed
feat: support market modal in prime leaderboard
1 parent 4f5780c commit 7da6c3a

3 files changed

Lines changed: 79 additions & 7 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { fireEvent, screen } from '@testing-library/react';
2+
3+
import { xvs } from '__mocks__/models/tokens';
4+
import { renderComponent } from 'testUtils/render';
5+
6+
import { MarketActions } from '..';
7+
8+
vi.mock('pages/Market/OperationForm', () => ({
9+
OperationForm: () => <div data-testid="operation-form" />,
10+
}));
11+
12+
describe('pages/PrimeLeaderboard/MarketActions', () => {
13+
it('opens the market operation modal when clicked', async () => {
14+
renderComponent(<MarketActions token={xvs} />);
15+
16+
fireEvent.click(screen.getByLabelText('Open market actions'));
17+
18+
expect(await screen.findByTestId('operation-form')).toBeInTheDocument();
19+
});
20+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { useState } from 'react';
2+
3+
import { useGetPools } from 'clients/api';
4+
import { Icon, Modal } from 'components';
5+
import { useTranslation } from 'libs/translations';
6+
import { useAccountAddress } from 'libs/wallet';
7+
import { OperationForm } from 'pages/Market/OperationForm';
8+
import type { Token } from 'types';
9+
import { areAddressesEqual } from 'utilities';
10+
11+
export interface MarketActionsProps {
12+
token: Token;
13+
}
14+
15+
export const MarketActions: React.FC<MarketActionsProps> = ({ token }) => {
16+
const { t } = useTranslation();
17+
const { accountAddress } = useAccountAddress();
18+
const { data: getPoolsData } = useGetPools({ accountAddress });
19+
const [isModalOpen, setIsModalOpen] = useState(false);
20+
21+
const market = getPoolsData?.pools
22+
.flatMap(pool =>
23+
pool.assets.map(asset => ({ asset, poolComptrollerAddress: pool.comptrollerAddress })),
24+
)
25+
.find(({ asset }) => areAddressesEqual(asset.vToken.underlyingToken.address, token.address));
26+
27+
if (!market) {
28+
return undefined;
29+
}
30+
31+
return (
32+
<>
33+
<button
34+
type="button"
35+
aria-label={t('primeLeaderboard.userRewards.marketActions')}
36+
className="ml-2 shrink-0"
37+
onClick={() => setIsModalOpen(true)}
38+
>
39+
<Icon name="dotShortcut" className="text-light-grey" />
40+
</button>
41+
42+
{isModalOpen && (
43+
<Modal
44+
isOpen
45+
title={market.asset.vToken.underlyingToken.symbol}
46+
handleClose={() => setIsModalOpen(false)}
47+
>
48+
<OperationForm
49+
vToken={market.asset.vToken}
50+
poolComptrollerAddress={market.poolComptrollerAddress}
51+
onSubmitSuccess={() => setIsModalOpen(false)}
52+
/>
53+
</Modal>
54+
)}
55+
</>
56+
);
57+
};

apps/evm/src/pages/PrimeLeaderboard/UserRewardsCard/index.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useTranslation } from 'libs/translations';
66
import type { Token } from 'types';
77
import { formatCentsToReadableValue, formatPercentageToReadableValue } from 'utilities';
88

9+
import { MarketActions } from '../MarketActions';
910
import { MarketRewardRow } from '../MarketRewardRow';
1011

1112
export interface UserMarketReward {
@@ -62,13 +63,7 @@ export const UserRewardsCard: React.FC<UserRewardsCardProps> = ({
6263
<span className="text-b1s">{formatPercentageToReadableValue(apyPercentage)}</span>
6364
</div>
6465

65-
<button
66-
type="button"
67-
aria-label={t('primeLeaderboard.userRewards.marketActions')}
68-
className="ml-2 shrink-0"
69-
>
70-
<Icon name="dots" className="text-light-grey" />
71-
</button>
66+
<MarketActions token={token} />
7267
</MarketRewardRow>
7368
))}
7469
</div>

0 commit comments

Comments
 (0)