diff --git a/components/token/RateCurveChart.tsx b/components/token/RateCurveChart.tsx new file mode 100644 index 00000000..72ca7581 --- /dev/null +++ b/components/token/RateCurveChart.tsx @@ -0,0 +1,255 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { Bank } from '@blockworks-foundation/mango-v4' +import { INITIAL_ANIMATION_SETTINGS } from '@components/settings/AnimationSettings' +import ContentBox from '@components/shared/ContentBox' +import { FadeInFadeOut } from '@components/shared/Transitions' +import useLocalStorageState from 'hooks/useLocalStorageState' +import useThemeWrapper from 'hooks/useThemeWrapper' +import { useMemo, useState } from 'react' +import { + Area, + AreaChart, + Label, + ReferenceDot, + ResponsiveContainer, + Tooltip, + XAxis, + YAxis, +} from 'recharts' +import { COLORS } from 'styles/colors' +import { ANIMATION_SETTINGS_KEY } from 'utils/constants' +import FlipNumbers from 'react-flip-numbers' +import { floorToDecimal, formatNumericValue } from 'utils/numbers' +import FormatNumericValue from '@components/shared/FormatNumericValue' +import { useTranslation } from 'react-i18next' +import { NoSymbolIcon } from '@heroicons/react/20/solid' + +type RateCurveData = { + util: number + rate: number +} + +const RateCurveChart = ({ bank }: { bank: Bank | undefined }) => { + const { t } = useTranslation(['common', 'token']) + const { theme } = useThemeWrapper() + const [animationSettings] = useLocalStorageState( + ANIMATION_SETTINGS_KEY, + INITIAL_ANIMATION_SETTINGS, + ) + const [mouseData, setMouseData] = useState(null) + + const handleMouseMove = (coords: any) => { + if (coords.activePayload) { + setMouseData(coords.activePayload[0].payload) + } + } + + const handleMouseLeave = () => { + setMouseData(null) + } + + const [currentRate, currentUtil] = useMemo(() => { + if (!bank) return [0, 0] + const currentRate = bank.getDepositRateUi() + const currentUtil = (bank.uiBorrows() / bank.uiDeposits()) * 100 + return [currentRate, currentUtil] + }, [bank]) + + const rateCurveChartData = useMemo(() => { + if (!bank) return [] + const defaults = [ + { util: 0, rate: 0 }, + { + util: bank.util0.toNumber() * 100, + rate: bank.rate0.toNumber() * 100, + }, + { + util: bank.util1.toNumber() * 100, + rate: bank.rate1.toNumber() * 100, + }, + { util: 100, rate: bank.maxRate.toNumber() * 100 }, + ] + if (currentRate && currentUtil) { + defaults.push({ util: currentUtil, rate: currentRate }) + } + return defaults.sort((a, b) => a.util - b.util) + }, [bank, currentRate, currentUtil]) + + return ( + + + {rateCurveChartData.length && bank ? ( + <> +
+

{t('token:rate-curve')}

+ {mouseData ? ( +
+
+ {animationSettings['number-scroll'] ? ( + + ) : ( + + + % + + )} +
+

+ {t('utilization')}:{' '} + + {floorToDecimal(mouseData.util, 2).toString()}% + +

+
+ ) : ( +
+
+ {animationSettings['number-scroll'] ? ( + + ) : ( + + + + + % + + )} +
+

+ {t('utilization')}:{' '} + + {floorToDecimal(currentUtil, 2).toString()}% + +

+
+ )} +
+
+ + + + + + + + + + `${floorToDecimal(d, 2).toString()}%`} + type="number" + /> + `${floorToDecimal(v, 2).toString()}%`} + tickLine={false} + /> + + + } + /> + + +
+ + ) : ( +
+
+ +

{t('chart-unavailable')}

+
+
+ )} +
+
+ ) +} + +export default RateCurveChart diff --git a/components/token/TokenPage.tsx b/components/token/TokenPage.tsx index 417d0869..faddeb93 100644 --- a/components/token/TokenPage.tsx +++ b/components/token/TokenPage.tsx @@ -7,7 +7,6 @@ import FlipNumbers from 'react-flip-numbers' import { formatCurrencyValue } from 'utils/numbers' import Link from 'next/link' import SheenLoader from '@components/shared/SheenLoader' -import Tooltip from '@components/shared/Tooltip' import useMangoGroup from 'hooks/useMangoGroup' import useJupiterMints from 'hooks/useJupiterMints' import useLocalStorageState from 'hooks/useLocalStorageState' @@ -23,6 +22,7 @@ import TokenParams from './TokenParams' import { formatTokenSymbol } from 'utils/tokens' import TokenLogo from '@components/shared/TokenLogo' import { ArrowLeftIcon } from '@heroicons/react/20/solid' +import RateCurveChart from './RateCurveChart' const DEFAULT_COINGECKO_VALUES = { ath: 0, @@ -183,23 +183,8 @@ const TokenPage = () => { -
- -

{t('utilization')}:

-
- - {bank.uiDeposits() > 0 ? ( - - ) : ( - '0.0' - )} - % - +
+
{coingeckoTokenInfo?.market_data ? ( diff --git a/public/locales/en/token.json b/public/locales/en/token.json index 2ca15fd3..37b15bae 100644 --- a/public/locales/en/token.json +++ b/public/locales/en/token.json @@ -30,6 +30,7 @@ "oracle-confidence": "Oracle Confidence", "oracle-staleness": "Oracle Staleness", "parameters": "Parameters", + "rate-curve": "Interest Rate Curve", "token-stats": "{{token}} Stats", "token-fees-collected": "Token Fees Collected", "token-not-found": "Token Not Found", diff --git a/public/locales/es/token.json b/public/locales/es/token.json index 2ca15fd3..37b15bae 100644 --- a/public/locales/es/token.json +++ b/public/locales/es/token.json @@ -30,6 +30,7 @@ "oracle-confidence": "Oracle Confidence", "oracle-staleness": "Oracle Staleness", "parameters": "Parameters", + "rate-curve": "Interest Rate Curve", "token-stats": "{{token}} Stats", "token-fees-collected": "Token Fees Collected", "token-not-found": "Token Not Found", diff --git a/public/locales/ru/token.json b/public/locales/ru/token.json index 2ca15fd3..37b15bae 100644 --- a/public/locales/ru/token.json +++ b/public/locales/ru/token.json @@ -30,6 +30,7 @@ "oracle-confidence": "Oracle Confidence", "oracle-staleness": "Oracle Staleness", "parameters": "Parameters", + "rate-curve": "Interest Rate Curve", "token-stats": "{{token}} Stats", "token-fees-collected": "Token Fees Collected", "token-not-found": "Token Not Found", diff --git a/public/locales/zh/token.json b/public/locales/zh/token.json index 52be6b63..c78eaa99 100644 --- a/public/locales/zh/token.json +++ b/public/locales/zh/token.json @@ -30,6 +30,7 @@ "oracle-confidence": "预言机可信度", "oracle-staleness": "预言机不新鲜性", "parameters": "参数", + "rate-curve": "Interest Rate Curve", "token-stats": "币种细节", "token-fees-collected": "收取的币种费用", "token-not-found": "查不到币种", diff --git a/public/locales/zh_tw/token.json b/public/locales/zh_tw/token.json index 583206c5..f4a7072b 100644 --- a/public/locales/zh_tw/token.json +++ b/public/locales/zh_tw/token.json @@ -30,6 +30,7 @@ "oracle-confidence": "預言機可信度", "oracle-staleness": "預言機不新鮮性", "parameters": "參數", + "rate-curve": "Interest Rate Curve", "token-stats": "幣種細節", "token-fees-collected": "收取的幣種費用", "token-not-found": "查不到幣種",