diff --git a/public/locales/en-US/page-explore-dfi.json b/public/locales/en-US/page-explore-dfi.json index 246accecd..bf42c36cf 100644 --- a/public/locales/en-US/page-explore-dfi.json +++ b/public/locales/en-US/page-explore-dfi.json @@ -3,6 +3,16 @@ "title": "EXPLORE THE POWER OF DFI", "subtitle": "Experience DeFi with DFI", "desc": "Our native token unlocks the power of decentralized finance, giving you access to a growing ecosystem of cutting-edge DeFi tools and innovative blockchain applications." + }, + "statisticsDisplay" : { + "circulatingSupply": { + "title": "CIRCULATING SUPPLY", + "desc": "{{perc}} of max supply" + }, + "dfiMinted": { + "title": "TOTAL DFI MINTED", + "desc": "out of {{value}}{{suffix}} fixed supply" + } } } diff --git a/src/hooks/useUnitSuffix.tsx b/src/hooks/useUnitSuffix.tsx index a215dbbd1..ed7f487ca 100644 --- a/src/hooks/useUnitSuffix.tsx +++ b/src/hooks/useUnitSuffix.tsx @@ -12,7 +12,7 @@ interface UnitSuffix { value: string; } -export function useUnitSuffix(value: string): UnitSuffix { +export function useUnitSuffix(value, decimalPlace = 0): UnitSuffix { const updatedValue = BigNumber(value); const places = updatedValue.e !== null ? Math.floor(updatedValue.e / 3) : 0; const suffix = `${units[places * 3] ?? ""}`; @@ -24,7 +24,7 @@ export function useUnitSuffix(value: string): UnitSuffix { if (suffix) { unitValueWithSuffix.value = updatedValue .dividedBy(1000 ** places) - .toFormat(0); + .toFormat(decimalPlace); } return unitValueWithSuffix; diff --git a/src/pages/explore/dfi/_components/DFIStatisticsDisplay.tsx b/src/pages/explore/dfi/_components/DFIStatisticsDisplay.tsx new file mode 100644 index 000000000..55f73eda9 --- /dev/null +++ b/src/pages/explore/dfi/_components/DFIStatisticsDisplay.tsx @@ -0,0 +1,59 @@ +import { useEffect, useState } from "react"; +import { SupplyData } from "@defichain/whale-api-client/dist/api/stats"; +import { StatisticPanel } from "@components/commons/StatisticPanel"; +import { Container } from "@components/commons/Container"; +import { useUnitSuffix } from "@hooks/useUnitSuffix"; +import { useTranslation } from "next-i18next"; +import { useWhaleApiClient } from "../../../../layouts/context/WhaleContext"; +import { calculatePercentage } from "../../../../shared/calculatePercentage"; + +export function DFIStatisticsDisplay() { + const api = useWhaleApiClient(); + const [supply, setSupply] = useState(); + const { t } = useTranslation("page-explore-dfi"); + + const { value: dfiMintedValue, suffix: dfiMintedSuffix } = useUnitSuffix( + supply?.max, + 1 + ); + + useEffect(() => { + api.stats.getSupply().then((supplyItem) => { + setSupply(supplyItem); + }); + }, [api.stats]); + + const supplyItems = [ + { + title: t("statisticsDisplay.circulatingSupply.title"), + stats: supply?.circulating, + desc: + supply === undefined + ? supply + : t("statisticsDisplay.circulatingSupply.desc", { + perc: calculatePercentage(supply?.circulating, supply?.total), + }), + }, + { + title: t("statisticsDisplay.dfiMinted.title"), + stats: supply?.total, + desc: + supply === undefined + ? supply + : t("statisticsDisplay.dfiMinted.desc", { + value: dfiMintedValue, + suffix: dfiMintedSuffix, + }), + }, + ]; + + return ( + + + + ); +} diff --git a/src/pages/explore/dfi/index.page.tsx b/src/pages/explore/dfi/index.page.tsx index b0b3c7eda..60f2b6ea9 100644 --- a/src/pages/explore/dfi/index.page.tsx +++ b/src/pages/explore/dfi/index.page.tsx @@ -1,18 +1,22 @@ import { HeroBanner, HeroBannerBg } from "@components/commons/HeroBanner"; import { SSRConfig, useTranslation } from "next-i18next"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; +import { DFIStatisticsDisplay } from "./_components/DFIStatisticsDisplay"; export default function ExploreDFI() { const { t } = useTranslation("page-explore-dfi"); return ( - + <> + + + ); }