Skip to content

Commit 1c15a3e

Browse files
committed
fix: handle infinity
1 parent 13c82b4 commit 1c15a3e

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

src/components/incentives/IncentivesButton.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { MeritIncentivesTooltipContent } from './MeritIncentivesTooltipContent';
2020
import { MerklIncentivesTooltipContent } from './MerklIncentivesTooltipContent';
2121
import { SonicAirdropTooltipContent } from './SonicIncentivesTooltipContent';
2222

23+
const INFINITY = 'Infinity';
24+
2325
export type IconProps = {
2426
className?: string;
2527
width?: string | number;
@@ -263,18 +265,16 @@ export const IncentivesButton = ({
263265
}
264266
}
265267

266-
const isIncentivesInfinity = incentives.some(
267-
(incentive) => incentive.incentiveAPR === 'Infinity'
268-
);
268+
const isIncentivesInfinity = incentives.some((incentive) => incentive.incentiveAPR === INFINITY);
269269
const incentivesAPRSum = isIncentivesInfinity
270-
? 'Infinity'
270+
? INFINITY
271271
: incentives.reduce((aIncentive, bIncentive) => aIncentive + +bIncentive.incentiveAPR, 0);
272272

273273
const incentivesNetAPR = isIncentivesInfinity
274-
? 'Infinity'
275-
: incentivesAPRSum !== 'Infinity'
274+
? INFINITY
275+
: incentivesAPRSum !== INFINITY
276276
? valueToBigNumber(incentivesAPRSum || 0).toNumber()
277-
: 'Infinity';
277+
: INFINITY;
278278

279279
return (
280280
<ContentWithTooltip
@@ -309,7 +309,7 @@ const Content = ({
309309
plus,
310310
}: {
311311
incentives: ReserveIncentiveResponse[];
312-
incentivesNetAPR: number | 'Infinity';
312+
incentivesNetAPR: number | typeof INFINITY;
313313
displayBlank?: boolean;
314314
plus?: boolean;
315315
}) => {
@@ -343,7 +343,7 @@ const Content = ({
343343
);
344344

345345
if (hasGhoIncentives) {
346-
if (incentivesNetAPR !== 'Infinity' && incentivesNetAPR < 10000) {
346+
if (incentivesNetAPR !== INFINITY && incentivesNetAPR < 10000) {
347347
return (
348348
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
349349
<FormattedNumber
@@ -355,7 +355,7 @@ const Content = ({
355355
<IncentivesIcon width="16" height="16" />
356356
</Box>
357357
);
358-
} else if (incentivesNetAPR !== 'Infinity' && incentivesNetAPR > 9999) {
358+
} else if (incentivesNetAPR !== INFINITY && incentivesNetAPR > 9999) {
359359
return (
360360
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
361361
<FormattedNumber
@@ -368,7 +368,7 @@ const Content = ({
368368
<IncentivesIcon width="16" height="16" />
369369
</Box>
370370
);
371-
} else if (incentivesNetAPR === 'Infinity') {
371+
} else if (incentivesNetAPR === INFINITY) {
372372
return (
373373
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
374374
<Typography variant="main12" color="text.secondary">
@@ -393,15 +393,12 @@ const Content = ({
393393
return (
394394
<Box
395395
sx={() => ({
396-
// p: { xs: '0 4px', xsm: '2px 4px' },
397-
// border: `1px solid ${open ? theme.palette.action.disabled : theme.palette.divider}`,
398396
borderRadius: '4px',
399397
cursor: 'pointer',
400398
display: 'flex',
401399
alignItems: 'center',
402400
justifyContent: 'center',
403401
transition: 'opacity 0.2s ease',
404-
// bgcolor: open ? 'action.hover' : 'transparent',
405402
'&:hover': {
406403
bgcolor: 'action.hover',
407404
borderColor: 'action.disabled',

src/components/incentives/IncentivesCard.tsx

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ProtocolAction } from '@aave/contract-helpers';
22
import { ReserveIncentiveResponse } from '@aave/math-utils/dist/esm/formatters/incentive/calculate-reserve-incentives';
3-
import { Box } from '@mui/material';
3+
import { Box, Typography } from '@mui/material';
44
import { ReactNode } from 'react';
55
import { useMeritIncentives } from 'src/hooks/useMeritIncentives';
66
import { useMerklIncentives } from 'src/hooks/useMerklIncentives';
@@ -47,8 +47,11 @@ export const IncentivesCard = ({
4747

4848
const protocolIncentivesAPR =
4949
incentives?.reduce((sum, inc) => {
50-
return sum + (inc.incentiveAPR === 'Infinity' ? 0 : +inc.incentiveAPR);
51-
}, 0) || 0;
50+
if (inc.incentiveAPR === 'Infinity' || sum === 'Infinity') {
51+
return 'Infinity';
52+
}
53+
return sum + +inc.incentiveAPR;
54+
}, 0 as number | 'Infinity') || 0;
5255

5356
const { data: meritIncentives } = useMeritIncentives({
5457
symbol,
@@ -70,9 +73,15 @@ export const IncentivesCard = ({
7073
const merklIncentivesAPR = merklIncentives?.breakdown?.merklIncentivesAPR || 0;
7174

7275
const isBorrow = protocolAction === ProtocolAction.borrow;
73-
const displayAPY = isBorrow
74-
? protocolAPY - protocolIncentivesAPR - meritIncentivesAPR - merklIncentivesAPR
75-
: protocolAPY + protocolIncentivesAPR + meritIncentivesAPR + merklIncentivesAPR;
76+
77+
// If any incentive is infinite, the total should be infinite
78+
const hasInfiniteIncentives = protocolIncentivesAPR === 'Infinity';
79+
80+
const displayAPY = hasInfiniteIncentives
81+
? 'Infinity'
82+
: isBorrow
83+
? protocolAPY - (protocolIncentivesAPR as number) - meritIncentivesAPR - merklIncentivesAPR
84+
: protocolAPY + (protocolIncentivesAPR as number) + meritIncentivesAPR + merklIncentivesAPR;
7685

7786
return (
7887
<Box
@@ -87,15 +96,21 @@ export const IncentivesCard = ({
8796
>
8897
{value.toString() !== '-1' ? (
8998
<Box sx={{ display: 'flex' }}>
90-
<FormattedNumber
91-
data-cy={`apy`}
92-
value={displayAPY}
93-
percent
94-
variant={variant}
95-
symbolsVariant={symbolsVariant}
96-
color={color}
97-
symbolsColor={color}
98-
/>
99+
{displayAPY === 'Infinity' ? (
100+
<Typography variant={variant} color={color || 'text.secondary'}>
101+
∞%
102+
</Typography>
103+
) : (
104+
<FormattedNumber
105+
data-cy={`apy`}
106+
value={displayAPY}
107+
percent
108+
variant={variant}
109+
symbolsVariant={symbolsVariant}
110+
color={color}
111+
symbolsColor={color}
112+
/>
113+
)}
99114
{tooltip}
100115
</Box>
101116
) : (

0 commit comments

Comments
 (0)