Skip to content

Commit 4e83b97

Browse files
committed
refactor: move incentives calculation to parent component
1 parent 3610842 commit 4e83b97

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/modules/markets/MarketAssetsList.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Trans } from '@lingui/macro';
22
import { useMediaQuery } from '@mui/material';
33
import { useState } from 'react';
4+
import { mapAaveProtocolIncentives } from 'src/components/incentives/incentives.helper';
45
import { VariableAPYTooltip } from 'src/components/infoTooltips/VariableAPYTooltip';
56
import { ListColumn } from 'src/components/lists/ListColumn';
67
import { ListHeaderTitle } from 'src/components/lists/ListHeaderTitle';
@@ -45,6 +46,10 @@ type MarketAssetsListProps = {
4546
reserves: ReserveWithId[];
4647
loading: boolean;
4748
};
49+
export type ReserveWithProtocolIncentives = ReserveWithId & {
50+
supplyProtocolIncentives: ReturnType<typeof mapAaveProtocolIncentives>;
51+
borrowProtocolIncentives: ReturnType<typeof mapAaveProtocolIncentives>;
52+
};
4853

4954
export default function MarketAssetsList({ reserves, loading }: MarketAssetsListProps) {
5055
const isTableChangedToCards = useMediaQuery('(max-width:1125px)');
@@ -93,7 +98,11 @@ export default function MarketAssetsList({ reserves, loading }: MarketAssetsList
9398
? (aValue as number) - (bValue as number)
9499
: (bValue as number) - (aValue as number);
95100
});
96-
101+
const reservesWithIncentives: ReserveWithProtocolIncentives[] = sortedReserves.map((reserve) => ({
102+
...reserve,
103+
supplyProtocolIncentives: mapAaveProtocolIncentives(reserve.incentives, 'supply'),
104+
borrowProtocolIncentives: mapAaveProtocolIncentives(reserve.incentives, 'borrow'),
105+
}));
97106
// Show loading state when loading
98107
if (loading) {
99108
return isTableChangedToCards ? (
@@ -141,7 +150,7 @@ export default function MarketAssetsList({ reserves, loading }: MarketAssetsList
141150
</ListHeaderWrapper>
142151
)}
143152

144-
{sortedReserves.map((reserve) =>
153+
{reservesWithIncentives.map((reserve) =>
145154
isTableChangedToCards ? (
146155
<MarketAssetsListMobileItem {...reserve} key={reserve.id} />
147156
) : (

src/modules/markets/MarketAssetsListItem.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ import { MARKETS } from 'src/utils/events';
1717
import { showExternalIncentivesTooltip } from 'src/utils/utils';
1818
import { useShallow } from 'zustand/shallow';
1919

20-
import { mapAaveProtocolIncentives } from '../../components/incentives/incentives.helper';
2120
import { IncentivesCard } from '../../components/incentives/IncentivesCard';
2221
import { AMPLToolTip } from '../../components/infoTooltips/AMPLToolTip';
2322
import { ListColumn } from '../../components/lists/ListColumn';
2423
import { ListItem } from '../../components/lists/ListItem';
2524
import { FormattedNumber } from '../../components/primitives/FormattedNumber';
2625
import { Link, ROUTES } from '../../components/primitives/Link';
2726
import { TokenIcon } from '../../components/primitives/TokenIcon';
28-
import { ReserveWithId } from '../../hooks/app-data-provider/useAppDataProvider';
27+
import { ReserveWithProtocolIncentives } from './MarketAssetsList';
2928

30-
export const MarketAssetsListItem = ({ ...reserve }: ReserveWithId) => {
29+
export const MarketAssetsListItem = ({ ...reserve }: ReserveWithProtocolIncentives) => {
3130
const router = useRouter();
3231
const [trackEvent, currentMarket] = useRootStore(
3332
useShallow((store) => [store.trackEvent, store.currentMarket])
@@ -55,9 +54,6 @@ export const MarketAssetsListItem = ({ ...reserve }: ReserveWithId) => {
5554
? iconSymbol
5655
: reserve.underlyingToken.symbol;
5756

58-
const supplyProtocolIncentives = mapAaveProtocolIncentives(reserve.incentives, 'supply');
59-
const borrowProtocolIncentives = mapAaveProtocolIncentives(reserve.incentives, 'borrow');
60-
6157
return (
6258
<ListItem
6359
px={6}
@@ -112,7 +108,7 @@ export const MarketAssetsListItem = ({ ...reserve }: ReserveWithId) => {
112108
<ListColumn>
113109
<IncentivesCard
114110
value={reserve.supplyInfo.apy.value}
115-
incentives={supplyProtocolIncentives}
111+
incentives={reserve.supplyProtocolIncentives}
116112
address={reserve.aToken.address}
117113
symbol={reserve.underlyingToken.symbol}
118114
variant="main16"
@@ -151,7 +147,7 @@ export const MarketAssetsListItem = ({ ...reserve }: ReserveWithId) => {
151147
? String(reserve.borrowInfo?.apy.value)
152148
: '-1'
153149
}
154-
incentives={borrowProtocolIncentives}
150+
incentives={reserve.borrowProtocolIncentives}
155151
address={reserve.vToken.address}
156152
symbol={reserve.underlyingToken.symbol}
157153
variant="main16"

src/modules/markets/MarketAssetsListMobileItem.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ import { MARKETS } from 'src/utils/events';
1313
import { showExternalIncentivesTooltip } from 'src/utils/utils';
1414
import { useShallow } from 'zustand/shallow';
1515

16-
import { mapAaveProtocolIncentives } from '../../components/incentives/incentives.helper';
1716
import { IncentivesCard } from '../../components/incentives/IncentivesCard';
1817
import { FormattedNumber } from '../../components/primitives/FormattedNumber';
1918
import { Link, ROUTES } from '../../components/primitives/Link';
2019
import { Row } from '../../components/primitives/Row';
21-
import { ReserveWithId } from '../../hooks/app-data-provider/useAppDataProvider';
2220
import { ListMobileItemWrapper } from '../dashboard/lists/ListMobileItemWrapper';
21+
import { ReserveWithProtocolIncentives } from './MarketAssetsList';
2322

24-
export const MarketAssetsListMobileItem = ({ ...reserve }: ReserveWithId) => {
23+
export const MarketAssetsListMobileItem = ({ ...reserve }: ReserveWithProtocolIncentives) => {
2524
const [trackEvent, currentMarket] = useRootStore(
2625
useShallow((store) => [store.trackEvent, store.currentMarket])
2726
);
@@ -47,9 +46,6 @@ export const MarketAssetsListMobileItem = ({ ...reserve }: ReserveWithId) => {
4746
? iconSymbol
4847
: reserve.underlyingToken.symbol;
4948

50-
const supplyProtocolIncentives = mapAaveProtocolIncentives(reserve.incentives, 'supply');
51-
const borrowProtocolIncentives = mapAaveProtocolIncentives(reserve.incentives, 'borrow');
52-
5349
return (
5450
<ListMobileItemWrapper
5551
symbol={reserve.underlyingToken.symbol}
@@ -89,7 +85,7 @@ export const MarketAssetsListMobileItem = ({ ...reserve }: ReserveWithId) => {
8985
<IncentivesCard
9086
align="flex-end"
9187
value={reserve.supplyInfo.apy.value}
92-
incentives={supplyProtocolIncentives}
88+
incentives={reserve.supplyProtocolIncentives}
9389
address={reserve.aToken.address}
9490
symbol={reserve.underlyingToken.symbol}
9591
variant="secondary14"
@@ -150,7 +146,7 @@ export const MarketAssetsListMobileItem = ({ ...reserve }: ReserveWithId) => {
150146
? String(reserve.borrowInfo.apy.value)
151147
: '-1'
152148
}
153-
incentives={borrowProtocolIncentives}
149+
incentives={reserve.borrowProtocolIncentives}
154150
address={reserve.vToken.address}
155151
symbol={reserve.underlyingToken.symbol}
156152
variant="secondary14"

0 commit comments

Comments
 (0)