ghost-dao-interface/src/containers/Stake/components/Metric.jsx
Uncle Fatso 5dffd62c5a
replace hardcoded token symbols with on-chain data hook
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2025-06-30 19:49:07 +03:00

63 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Metric from "../../../components/Metric/Metric";
import { formatCurrency, formatNumber } from "../../../helpers";
import { useCurrentIndex } from "../../../hooks/staking";
import { useCirculatingSupply } from "../../../hooks/tokens";
import { useFtsoPrice } from "../../../hooks/prices";
import { DecimalBigNumber } from "../../../helpers/DecimalBigNumber";
export const CurrentIndex = props => {
const { currentIndex } = useCurrentIndex(props.chainId);
const _props = {
...props,
label: `Current Index`,
tooltip: `The current index indicates the amount of ${props.ftsoSymbol} a holder would possess if they had staked and maintained 1 ${props.ftsoSymbol} since its launch.`,
};
if (currentIndex) _props.metric = `${formatNumber(currentIndex, 2)}`;
else _props.isLoading = true;
return <Metric {..._props} />;
};
export const Apy = props => {
const circulatingSupply = useCirculatingSupply(props.chainId, "STNK");
let apy = Infinity;
if (circulatingSupply._value > 0n) {
const value = props.distribute.div(circulatingSupply);
apy = 100 * (Math.pow(1 + parseFloat(value.toString()), 1095) - 1);
if (apy === 0) apy = Infinity;
}
const _props = {
...props,
label: "APY",
tooltip: `The annualized rate of return, accounting for compounding from ${props.stnkSymbol}s exponential rebasing.`,
};
if (apy) _props.metric = `${formatNumber(apy, 2)}${apy === Infinity ? "" : "%"}`;
else _props.isLoading = true;
return <Metric {..._props} />;
};
export const TotalDeposit = props => {
const circulatingSupply = useCirculatingSupply(props.chainId, "STNK");
const ftsoPrice = useFtsoPrice(props.chainId);
const deposit = circulatingSupply.mul(ftsoPrice);
const _props = {
...props,
label: "Total Deposit",
tooltip: `The total stablecoin reserves in the ghostDAO treasury backing the entire circulating supply of ${props.stnkSymbol}.`,
};
if (deposit) _props.metric = `${formatCurrency(deposit, 2)}`;
else _props.isLoading = true;
return <Metric {..._props} />;
};