Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final delivery money market (includes the charts) #1004

Merged
Merged
Show file tree
Hide file tree
Changes from 138 commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
573393d
aave page static components, mobile first
matzapata Aug 7, 2024
14aa7e5
responsive panels
matzapata Aug 8, 2024
c26c396
functional static borrow asset list
matzapata Aug 8, 2024
1ba0838
cleanup
matzapata Aug 8, 2024
c31694b
renaming
matzapata Aug 8, 2024
9678ceb
lend assets list
matzapata Aug 8, 2024
c67474f
Lend positions list
matzapata Aug 8, 2024
6813ccc
fixes and cleanup
matzapata Aug 8, 2024
ba90308
cleanup
matzapata Aug 8, 2024
e42e0e2
cleanup
matzapata Aug 8, 2024
bcc105c
cleanup
matzapata Aug 8, 2024
0c02b70
static ui done. missing validations
matzapata Aug 9, 2024
eecce08
add validations
matzapata Aug 9, 2024
23a9d44
add validations
matzapata Aug 9, 2024
d48a4b2
move errors down
matzapata Aug 9, 2024
dbbc38c
borrow form modal
matzapata Aug 9, 2024
c59d8f8
pr comments
matzapata Aug 9, 2024
2a84650
pr comments
matzapata Aug 9, 2024
d625ee6
fix typo
matzapata Aug 9, 2024
292ef14
Update apps/frontend/src/app/5_pages/AavePage/components/LendPosition…
matzapata Aug 9, 2024
87b4049
repay modals
matzapata Aug 9, 2024
8434d4b
Merge pull request #1 from wakeuplabs-io/static-ui-position-tables
matzapata Aug 9, 2024
babaf69
Merge pull request #2 from wakeuplabs-io/SAF-13_withdraw-components
matzapata Aug 9, 2024
760afe4
Merge branch 'develop' into SAF-15_repay-components
matzapata Aug 9, 2024
fe53d9f
Merge branch 'develop' into SAF-10_borrow-components
matzapata Aug 9, 2024
3f43631
lend modal
matzapata Aug 9, 2024
5fa3b69
Merge pull request #3 from wakeuplabs-io/SAF-10_borrow-components
matzapata Aug 12, 2024
2973255
Merge branch 'develop' into SAF-15_repay-components
matzapata Aug 12, 2024
0370d2e
Merge pull request #4 from wakeuplabs-io/SAF-15_repay-components
matzapata Aug 12, 2024
ad384c6
Merge pull request #5 from wakeuplabs-io/SAF-37_lend-components
matzapata Aug 12, 2024
f6c103d
use simple table row
matzapata Aug 12, 2024
aa1e9b9
asset amount input
matzapata Aug 12, 2024
1f6cec5
add missing translations
matzapata Aug 12, 2024
b935c06
fix translation
matzapata Aug 12, 2024
ff19631
units and prices mock
matzapata Aug 12, 2024
a8c6b6d
setup layout for pool details screen
matzapata Aug 12, 2024
5407531
Merge pull request #6 from wakeuplabs-io/SAF-36_cleanups
matzapata Aug 12, 2024
92c87f6
wallet overview panel
matzapata Aug 12, 2024
5aa4199
emode card mock
matzapata Aug 12, 2024
5b5f826
max with for emode category
matzapata Aug 12, 2024
5c0935a
Merge branch 'develop' into SAF-42_MockEmodeCard
matzapata Aug 12, 2024
45ab4c8
Merge pull request #9 from wakeuplabs-io/SAF-42_MockEmodeCard
matzapata Aug 12, 2024
8bdcea5
top bar mock
matzapata Aug 12, 2024
2df5d70
Merge pull request #10 from wakeuplabs-io/SAF-44_MockTopBar
matzapata Aug 13, 2024
f61ea42
network switch
matzapata Aug 13, 2024
6cf3a44
cleanup
matzapata Aug 13, 2024
a3cfaed
ui fixes
matzapata Aug 13, 2024
7fede62
ui fixes, usd prices
matzapata Aug 13, 2024
488223e
Efficiency card
matzapata Aug 13, 2024
bbfe45f
ordering
matzapata Aug 13, 2024
0a1a91e
fix filter 0 balances checkbox
matzapata Aug 13, 2024
cb76d67
pr comment
matzapata Aug 13, 2024
f0d549a
Merge pull request #11 from wakeuplabs-io/SAF-45_AutomaticSwicth
matzapata Aug 13, 2024
20b3aee
token
matzapata Aug 14, 2024
b0c20de
Merge pull request #13 from wakeuplabs-io/cleanup
matzapata Aug 14, 2024
5cab202
Mocked table cards plus refactor of statistics card (#14)
matzapata Aug 14, 2024
6946a5f
Saf 41 charts (#16)
luchopcerra Aug 19, 2024
8359dbb
removed view transactions button (out of scope)
chescalante Aug 20, 2024
dd23931
fix breakpoints
matzapata Aug 20, 2024
14878b4
[SAF-41] fix color constant and background for mobile vs desktop view…
luchopcerra Aug 20, 2024
704e86c
Dashboard pool data integration (#15) (#22)
matzapata Aug 20, 2024
ce56708
Lend integration (#19)
matzapata Aug 21, 2024
1f2ab87
Cache for aave hooks (#23)
matzapata Aug 22, 2024
e3d37b2
Develop mockups (#25)
luchopcerra Aug 23, 2024
ae64540
Withdraw integration (#21)
matzapata Aug 23, 2024
b960b79
Borrow integration (#24)
matzapata Aug 23, 2024
63767a6
Repay integration (#26)
matzapata Aug 26, 2024
b4f6b1c
implement collateral switch (#27)
matzapata Aug 26, 2024
6312a54
Cleanup (#28)
matzapata Aug 26, 2024
8a4b2ab
Update apps/frontend/package.json
matzapata Aug 27, 2024
2be1e51
Update apps/frontend/src/app/2_molecules/AmountTransition/AmountTrans…
matzapata Aug 27, 2024
6bb5809
Update apps/frontend/src/app/2_molecules/AssetAmountPriceRenderer/Ass…
matzapata Aug 27, 2024
76153dd
Update apps/frontend/src/app/2_molecules/NetworkSwitch/NetworkSwitch.tsx
matzapata Aug 27, 2024
987d265
Update apps/frontend/src/app/5_pages/AaveReserveOverviewPage/componen…
matzapata Aug 27, 2024
6f46c5f
Update apps/frontend/src/app/5_pages/AaveReserveOverviewPage/componen…
matzapata Aug 27, 2024
1cc3cc7
Update apps/frontend/src/app/5_pages/AaveReserveOverviewPage/componen…
matzapata Aug 27, 2024
a282895
Apply suggestions from code review
matzapata Aug 27, 2024
e916e33
remove LinkIcon
matzapata Aug 27, 2024
99c512e
Apply suggestions from code review
matzapata Aug 27, 2024
b927ea6
Apply suggestions from code review
matzapata Aug 27, 2024
55f38c9
Apply suggestions from code review
matzapata Aug 27, 2024
ab1ae57
pr comments
matzapata Aug 27, 2024
5f0f5b4
Merge branch 'develop-mockups-pr-comments' into develop-mockups
matzapata Aug 27, 2024
f8ad82d
Merge branch 'develop-mockups' into develop
matzapata Aug 28, 2024
c648b45
fixes
matzapata Aug 28, 2024
2d10454
Merge branch 'develop-mockups' into develop
matzapata Aug 28, 2024
2cf45e6
fixes
matzapata Aug 28, 2024
1769f6b
SAF-49 setup bob (#29)
matzapata Aug 29, 2024
9d02403
SAF 50 - E-Mode (#30)
matzapata Sep 3, 2024
b57d002
Toggle lend mode
matzapata Sep 3, 2024
de0cfa2
Fixes and cleanup (#33)
matzapata Sep 5, 2024
8deb00a
Fixes UI (#35)
matzapata Sep 5, 2024
faa3d5a
Saf 20/pool details integration topbar (#40)
matzapata Sep 5, 2024
d884245
Saf 20/pool details integration sidebar (#41)
matzapata Sep 5, 2024
7b72932
Saf 20/pool details integration graphs stats (#42)
matzapata Sep 6, 2024
8525737
Merge branch 'feat/aave' into develop
matzapata Sep 6, 2024
fe0ed74
fixes
matzapata Sep 6, 2024
5870b39
Saf 20/charts integration (exclude supply and borrow by now) (#46)
luchopcerra Sep 6, 2024
b137a7a
cleanup
matzapata Sep 6, 2024
8db5467
cleanup
matzapata Sep 6, 2024
292170e
fixes
matzapata Sep 6, 2024
2b0cbf6
fix: prevent NaN in interest rate charts when no data is retrieved
luchopcerra Sep 6, 2024
7b64c5e
fix stats
matzapata Sep 6, 2024
0e00afe
fix available liquidity
matzapata Sep 6, 2024
1b0a825
Update apps/frontend/src/app/5_pages/AavePage/components/LendAssetsLi…
matzapata Sep 6, 2024
f16fd71
Update apps/frontend/src/app/5_pages/AavePage/components/BorrowPositi…
matzapata Sep 6, 2024
f8a4b5f
Update apps/frontend/src/app/5_pages/AavePage/components/BorrowPositi…
matzapata Sep 6, 2024
c75aa34
Merge pull request #44 from wakeuplabs-io/develop
chescalante Sep 6, 2024
cde6014
coments
matzapata Sep 6, 2024
a6054bd
fix borrow power
matzapata Sep 9, 2024
b3b4764
fixes and cleanup
matzapata Sep 9, 2024
b58373a
Fixes and cleanup (#48)
matzapata Sep 9, 2024
60f93c2
cleanup
matzapata Sep 9, 2024
4064d8b
Cleanup (#49)
matzapata Sep 9, 2024
dd1df1f
refactor config for same code style and handle mainnet config
matzapata Sep 9, 2024
fb0a928
Merge branch 'feat/aave' into develop
matzapata Sep 9, 2024
28b105d
Refactor config for same code style and handle mainnet config (#50)
matzapata Sep 9, 2024
6968768
small fixes
matzapata Sep 9, 2024
c9256be
remove unused files and fix repay with balance future collateral ratio
matzapata Sep 9, 2024
19dafc9
Merge branch 'feat/aave' into develop
matzapata Sep 9, 2024
e48cb0c
remove unused files and fix repay with balance future collateral rati…
matzapata Sep 9, 2024
c2917c3
cleanup and fixes
matzapata Sep 9, 2024
47a41eb
disable collateral toggle if liquidation risk arises from it
matzapata Sep 9, 2024
97e840f
add sorting in tables
matzapata Sep 9, 2024
4ec8686
precision and percentage
matzapata Sep 9, 2024
83ae7f5
fix hex chainId
matzapata Sep 10, 2024
a497df3
fix chain id
matzapata Sep 10, 2024
cb7aabf
Apply suggestions from code review
matzapata Sep 11, 2024
0935773
rename USD to Usd
matzapata Sep 11, 2024
67fa6f0
pr comments
matzapata Sep 11, 2024
ba4e595
Update apps/frontend/src/app/5_pages/AaveReserveOverviewPage/componen…
matzapata Sep 11, 2024
8364324
pr comment
matzapata Sep 11, 2024
47deadf
disable tooltip for infinite
matzapata Sep 11, 2024
7d65cab
Merge branch 'feat/aave' into develop
matzapata Sep 11, 2024
132dfca
[SAF_20] integrate charts data and api (#47)
luchopcerra Sep 12, 2024
ecef760
Merge remote-tracking branch 'sovryn/feat/money-market' into develop
luchopcerra Sep 12, 2024
783e145
fix(ui): fix size of wallet card
juandahl Sep 12, 2024
38f6159
Merge pull request #54 from wakeuplabs-io/fix/wallet-card
juandahl Sep 12, 2024
549748a
Apply suggestions from code review
luchopcerra Sep 13, 2024
500fe4c
@pietro-maximoff suggestion applied: 'it doesn't need to be changed'
luchopcerra Sep 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
REACT_APP_RATES_HISTORY_API_URL=https://bob-mm-cache.test.sovryn.app/data/rates-history

REACT_APP_GRAPH_RSK=https://subgraph.test.sovryn.app/subgraphs/name/DistributedCollective/sovryn-subgraph

REACT_APP_GRAPH_BOB=https://bob-ambient-subgraph.test.sovryn.app/subgraphs/name/DistributedCollective/bob-ambient-subgraph
Expand All @@ -23,4 +25,4 @@ REACT_APP_ENABLE_SERVICE_WORKER=false
REACT_APP_SIMULATE_TX=false
REACT_APP_ESTIMATOR_URI=https://simulator.sovryn.app

REACT_APP_DATADOG_CLIENT_TOKEN=
REACT_APP_DATADOG_CLIENT_TOKEN=
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Paragraph, Tabs, TabSize, TabType } from '@sovryn/ui';

import { useAaveReservesData } from '../../../hooks/aave/useAaveReservesData';
import { translations } from '../../../locales/i18n';
import { TAB_ITEMS } from './AaveReserveOverviewPage.constants';
import { COMMON_SYMBOLS } from '../../../utils/asset';
import { TAB_ITEMS } from './AaveReserveOverviewPage.constants';
import { BorrowDetailsGraph } from './components/BorrowDetailsGraph/BorrowDetailsGraph';
import { EModeDetails } from './components/EModeDetails/EModeDetails';
import { InterestRateModelGraph } from './components/InterestRateModelGraph/InterestRateModelGraph';
Expand Down Expand Up @@ -84,7 +84,7 @@ const AaveReserveOverviewPage: FC = () => {
<div
className={classNames(
{ hidden: activeOverviewTab !== OverviewTab.WALLET },
'lg:block space-y-4 w-[450px] shrink-0',
'lg:block space-y-4 w-full lg:w-[450px] shrink-0',
)}
>
<WalletOverview symbol={symbol} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { Accordion, Link, Paragraph } from '@sovryn/ui';

import { AmountRenderer } from '../../../../2_molecules/AmountRenderer/AmountRenderer';
import { StatisticsCard } from '../../../../2_molecules/StatisticsCard/StatisticsCard';
import { AAVE_CONTRACT_ADDRESSES } from '../../../../../constants/aave';
import { Reserve } from '../../../../../hooks/aave/useAaveReservesData';
import {
useAaveReservesHistory,
ReserveRateTimeRange,
ESupportedTimeRanges,
} from '../../../../../hooks/aave/useAaveReservesHistory';
import { useIsMobile } from '../../../../../hooks/useIsMobile';
import { translations } from '../../../../../locales/i18n';
import { formatAmountWithSuffix } from '../../../../../utils/math';
Expand All @@ -28,6 +34,23 @@ export const BorrowDetailsGraph: FC<BorrowDetailsGraphProps> = ({

const borrowStats = useMemo(() => normalizeBorrowStats(reserve), [reserve]);

const [timeRange, setTimeRange] = useState<ReserveRateTimeRange>(
ESupportedTimeRanges.OneMonth,
);
const { data: history } = useAaveReservesHistory(
`${reserve.underlyingAsset}${AAVE_CONTRACT_ADDRESSES.POOL_ADDRESSES_PROVIDER}`,
timeRange,
);

const borrowChartData = useMemo(
() =>
history.map(i => ({
x: i.date,
y: i.variableBorrowRate * 100,
})),
[history],
);

return (
<Accordion
label={
Expand Down Expand Up @@ -123,11 +146,11 @@ export const BorrowDetailsGraph: FC<BorrowDetailsGraphProps> = ({

<Chart
input={{
// TODO: implement once data is available
data: [],
label: '',
lineColor: theme.colors.primary[30],
data: borrowChartData,
label: t(pageTranslations.chart.aprVarLabel),
lineColor: theme.colors.positive,
}}
onTimeRangeChange={setTimeRange}
/>

<div className="space-y-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React, { FC, useCallback, useEffect, useRef } from 'react';
import ChartLibrary from 'chart.js/auto';
import 'chartjs-adapter-date-fns';

import { TimeRangeButtons } from '../../../TimeRangeButtons/TimeRangeButtons';
import { ReserveRateTimeRange } from './../../../../../../../hooks/aave/useAaveReservesHistory';
import {
CUSTOM_CANVAS_BACKGROUND_COLOR,
GRID_COLOR,
Expand All @@ -13,9 +15,10 @@ import { htmlLegendPlugin } from './Chart.utils';

type ChartProps = {
input: ChartData;
onTimeRangeChange: (range: ReserveRateTimeRange) => void;
};

export const Chart: FC<ChartProps> = ({ input }) => {
export const Chart: FC<ChartProps> = ({ input, onTimeRangeChange }) => {
const canvas = useRef<HTMLCanvasElement>(null);
const chartRef = useRef<ChartLibrary | null>(null);

Expand Down Expand Up @@ -111,7 +114,10 @@ export const Chart: FC<ChartProps> = ({ input }) => {

return (
<div onClick={stopPropagation} className="lg:p-6 lg:bg-gray-80">
<span id="legend-container-borrow-chart" className="text-tiny"></span>
<div className="flex items-center justify-between">
<span id="legend-container-borrow-chart" className="text-tiny"></span>
<TimeRangeButtons onChange={onTimeRangeChange} />
</div>
<canvas ref={canvas}></canvas>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FC, useMemo, useState } from 'react';

import { t } from 'i18next';
import { useSearchParams } from 'react-router-dom';

import { theme } from '@sovryn/tailwindcss-config';
import { Accordion, Link } from '@sovryn/ui';
Expand All @@ -9,12 +10,12 @@ import { Decimal } from '@sovryn/utils';
import { AmountRenderer } from '../../../../2_molecules/AmountRenderer/AmountRenderer';
import { StatisticsCard } from '../../../../2_molecules/StatisticsCard/StatisticsCard';
import { AAVE_CONTRACT_ADDRESSES } from '../../../../../constants/aave';
import { useAaveInterestRatesData } from '../../../../../hooks/aave/useAaveRates';
import { Reserve } from '../../../../../hooks/aave/useAaveReservesData';
import { useIsMobile } from '../../../../../hooks/useIsMobile';
import { translations } from '../../../../../locales/i18n';
import { getBobExplorerUrl } from '../../../../../utils/helpers';
import { Chart } from './components/Chart/Chart';
luchopcerra marked this conversation as resolved.
Show resolved Hide resolved
import { RatesData } from './components/Chart/Chart.types';

const pageTranslations = translations.aaveReserveOverviewPage.interestRateModel;

Expand All @@ -25,6 +26,9 @@ type InterestRateModelGraphProps = {
export const InterestRateModelGraph: FC<InterestRateModelGraphProps> = ({
reserve,
}) => {
const [searchParams] = useSearchParams();
const symbol = searchParams.get('asset') || 'ETH';
luchopcerra marked this conversation as resolved.
Show resolved Hide resolved
const { data: rates } = useAaveInterestRatesData(symbol);
const { isMobile } = useIsMobile();
const [open, setOpen] = useState(true);

Expand All @@ -46,6 +50,7 @@ export const InterestRateModelGraph: FC<InterestRateModelGraphProps> = ({
[reserve.borrowUsageRatio],
);

if (!rates) return null;
luchopcerra marked this conversation as resolved.
Show resolved Hide resolved
return (
<Accordion
label={
Expand Down Expand Up @@ -80,11 +85,10 @@ export const InterestRateModelGraph: FC<InterestRateModelGraphProps> = ({

<Chart
meta={{
// TODO: implement this once data is available
label: t(pageTranslations.chart.label1),
label: t(pageTranslations.chart.aprVarLabel),
lineColor: theme.colors['primary-30'],
}}
rates={{} as RatesData}
rates={rates}
/>

{/* statistics */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ export const Chart: FC<ChartProps> = ({ meta, rates }) => {
() =>
CHART_PERCENTAGES.map(x => ({
x: x * 100,
y: calculateVariableInterestRateModel(x, rates) * 100,
y: calculateVariableInterestRateModel(x, rates).mul(100).toNumber(),
})),
[rates],
);

const optimalPercentage = useMemo(
() =>
rates.optimalUsageRatio
? parseFloat((parseFloat(rates.optimalUsageRatio) * 100).toFixed(2))
? Math.round(rates.optimalUsageRatio.mul(100).toNumber() * 100) / 100
: 0,
[rates.optimalUsageRatio],
);

const currentPercentage = useMemo(
() =>
rates.currentUsageRatio
? parseFloat((parseFloat(rates.currentUsageRatio) * 100).toFixed(2))
? Math.round(rates.currentUsageRatio.mul(100).toNumber() * 100) / 100
: 0,
[rates.currentUsageRatio],
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Decimal } from '@sovryn/utils';

export type MockData<T> = {
data1: T[];
data2: T[];
Expand All @@ -8,13 +10,13 @@ export type MockData<T> = {
};

export interface RatesData {
currentUsageRatio: string;
optimalUsageRatio: string;
baseVariableBorrowRate: string;
variableRateSlope1: string;
variableRateSlope2: string;
currentUsageRatio: Decimal;
optimalUsageRatio: Decimal;
baseVariableBorrowRate: Decimal;
variableRateSlope1: Decimal;
variableRateSlope2: Decimal;
underlyingAsset: string;
name: string;
symbol: string;
decimals: string;
decimals: number;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Decimal } from '@sovryn/utils';

import { RatesData } from './Chart.types';

const getOrCreateLegendList = id => {
const getOrCreateLegendList = (id: string) => {
const legendContainer = document.getElementById(id);
if (!legendContainer) {
return;
Expand Down Expand Up @@ -92,35 +94,41 @@ export const htmlLegendPlugin = {

export const calculateInterestRateModel = (
utilization: number,
baseRate: number,
optimalUtilization: number,
initialSlope: number,
secondarySlope: number,
): number => {
baseRate: Decimal,
optimalUtilization: Decimal,
initialSlope: Decimal,
secondarySlope: Decimal,
): Decimal => {
if (utilization === 0) {
return 0;
return Decimal.ZERO;
}

if (utilization <= optimalUtilization) {
return baseRate + (utilization / optimalUtilization) * initialSlope;
const utilizationDecimal = Decimal.from(utilization);

if (utilizationDecimal.lte(optimalUtilization)) {
return baseRate.add(
utilizationDecimal.div(optimalUtilization).mul(initialSlope),
);
}

return (
baseRate +
initialSlope +
((utilization - optimalUtilization) / (1 - optimalUtilization)) *
secondarySlope
);
return baseRate
.add(initialSlope)
.add(
utilizationDecimal
.sub(optimalUtilization)
.div(Decimal.from(1).sub(optimalUtilization))
.mul(secondarySlope),
);
};

export const calculateVariableInterestRateModel = (
utilization: number,
rates: RatesData,
): number => {
const baseRate = parseFloat(rates.baseVariableBorrowRate);
const optimalUtilization = parseFloat(rates.optimalUsageRatio);
const initialSlope = parseFloat(rates.variableRateSlope1);
const secondarySlope = parseFloat(rates.variableRateSlope2);
) => {
const baseRate = rates.baseVariableBorrowRate;
const optimalUtilization = rates.optimalUsageRatio;
const initialSlope = rates.variableRateSlope1;
const secondarySlope = rates.variableRateSlope2;

return calculateInterestRateModel(
utilization,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { Accordion, Icon, IconNames, Paragraph } from '@sovryn/ui';

import { AmountRenderer } from '../../../../2_molecules/AmountRenderer/AmountRenderer';
import { StatisticsCard } from '../../../../2_molecules/StatisticsCard/StatisticsCard';
import { AAVE_CONTRACT_ADDRESSES } from '../../../../../constants/aave';
import { Reserve } from '../../../../../hooks/aave/useAaveReservesData';
import {
ESupportedTimeRanges,
ReserveRateTimeRange,
useAaveReservesHistory,
} from '../../../../../hooks/aave/useAaveReservesHistory';
import { useIsMobile } from '../../../../../hooks/useIsMobile';
import { translations } from '../../../../../locales/i18n';
import { formatAmountWithSuffix } from '../../../../../utils/math';
Expand All @@ -29,6 +35,23 @@ export const SupplyDetailsGraph: FC<SupplyDetailsGraphProps> = ({

const supplyStats = useMemo(() => normalizeSupplyStats(reserve), [reserve]);

const [timeRange, setTimeRange] = useState<ReserveRateTimeRange>(
ESupportedTimeRanges.OneMonth,
);
const { data: history } = useAaveReservesHistory(
`${reserve.underlyingAsset}${AAVE_CONTRACT_ADDRESSES.POOL_ADDRESSES_PROVIDER}`,
timeRange,
);

const supplyChartData = useMemo(
() =>
history.map(i => ({
x: i.date,
y: i.liquidityRate * 100,
})),
[history],
);

return (
<Accordion
label={
Expand Down Expand Up @@ -111,11 +134,11 @@ export const SupplyDetailsGraph: FC<SupplyDetailsGraphProps> = ({

<Chart
input={{
// TODO: implement once data is available
data: [],
label: t(pageTranslations.chart.label1),
data: supplyChartData,
label: t(pageTranslations.chart.suppApr),
lineColor: theme.colors['primary-30'],
}}
onTimeRangeChange={setTimeRange}
/>

<div className="space-y-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React, { FC, useCallback, useEffect, useRef } from 'react';
import ChartLibrary from 'chart.js/auto';
import 'chartjs-adapter-date-fns';

import { ReserveRateTimeRange } from '../../../../../../../hooks/aave/useAaveReservesHistory';
import { TimeRangeButtons } from '../../../TimeRangeButtons/TimeRangeButtons';
import {
CUSTOM_CANVAS_BACKGROUND_COLOR,
GRID_COLOR,
Expand All @@ -13,9 +15,10 @@ import { htmlLegendPlugin } from './Chart.utils';

type ChartProps = {
input: InputData<{ x: number; y: number }>;
onTimeRangeChange: (range: ReserveRateTimeRange) => void;
};

export const Chart: FC<ChartProps> = ({ input }) => {
export const Chart: FC<ChartProps> = ({ input, onTimeRangeChange }) => {
const canvas = useRef<HTMLCanvasElement>(null);
const chartRef = useRef<ChartLibrary | null>(null);

Expand Down Expand Up @@ -113,7 +116,10 @@ export const Chart: FC<ChartProps> = ({ input }) => {

return (
<div onClick={stopPropagation} className="lg:p-6 lg:bg-gray-80">
<span id="legend-container-supply-chart" className="text-tiny"></span>
<div className="flex items-center justify-between">
<span id="legend-container-supply-chart" className="text-tiny"></span>
<TimeRangeButtons onChange={onTimeRangeChange} />
</div>
<canvas ref={canvas}></canvas>
</div>
);
Expand Down
Loading