Skip to content

Commit d7ea647

Browse files
authored
Display circulating supply on home page (#95)
1 parent 02f74a8 commit d7ea647

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

web-app/src/modules/core/routes/Home/Stats/Stats.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Link, NavLink } from 'react-router-dom';
44
import useAptos from '../../../../aptos';
55
import {
66
useLedgerInfo,
7-
useTotalSupply,
7+
useCirculatingSupply,
88
useValidatorSet,
99
useAccountsStats,
1010
useTotalTransactions,
@@ -56,7 +56,7 @@ const Stats: FC = () => {
5656
const [nextEpoch, setNextEpoch] = useState<Date>();
5757
const [nextEpochDate, setNextEpochDate] = useState<string>();
5858

59-
const totalSupply = useTotalSupply();
59+
const circulatingSupply = useCirculatingSupply();
6060
const ledgerInfo = useLedgerInfo();
6161
const accountsStats = useAccountsStats();
6262
const totalTransactions = useTotalTransactions();
@@ -114,13 +114,13 @@ const Stats: FC = () => {
114114
</div>
115115

116116
<div className="flex flex-col bg-[#F5F5F5] p-5 gap-2">
117-
<span className="text-sm font-medium text-[#525252]">Total Supply</span>
117+
<span className="text-sm font-medium text-[#525252]">Circulating Supply</span>
118118
<span
119119
className={`text-2xl md:text-3xl tracking-tight text-[#141414] h-8 rounded ${
120-
!totalSupply ? 'animate-pulse bg-gray-300 text-2xl space-y-4' : ''
120+
!circulatingSupply ? 'animate-pulse bg-gray-300 text-2xl space-y-4' : ''
121121
}`}
122122
>
123-
{totalSupply ? `${d3Format('.3f')(Math.floor(totalSupply.amount / 1e6) / 1e3)}B` : null}
123+
{circulatingSupply ? `${d3Format('.3f')(Math.floor(circulatingSupply.amount / 1e3) / 1e3)}M` : null}
124124
</span>
125125
</div>
126126

web-app/src/modules/ol/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,40 @@ export const useTotalSupply = (): Money | undefined => {
114114
return value;
115115
};
116116

117+
// Code below copied from api/src/ol/ol.service.ts
118+
// TODO: fold this function into a common library used by both web-app and api
119+
export const useCirculatingSupply = (): Money | undefined => {
120+
const aptos = useAptos();
121+
const [value, setValue] = useState<Money>();
122+
123+
useEffect(() => {
124+
const load = async () => {
125+
const supplyStats = await aptos.view({
126+
function: '0x1::supply::get_stats',
127+
type_arguments: [],
128+
arguments: [],
129+
});
130+
131+
const supplyInfo = {
132+
totalSupply: parseFloat(supplyStats[0] as string) / 1e6,
133+
slowLockedSupply: parseFloat(supplyStats[1] as string) / 1e6,
134+
cwSupply: parseFloat(supplyStats[2] as string) / 1e6,
135+
infraEscrowSupply: parseFloat(supplyStats[3] as string) / 1e6,
136+
circulatingSupply: parseFloat(supplyStats[4] as string) / 1e6,
137+
}
138+
139+
setValue({
140+
amount: supplyInfo.circulatingSupply,
141+
symbol: "LIBRA",
142+
});
143+
};
144+
145+
load();
146+
}, []);
147+
148+
return value;
149+
};
150+
117151
export const useLedgerInfo = (): Types.IndexResponse | undefined => {
118152
const [ledgerInfo, setLedgerInfo] = useState<Types.IndexResponse>();
119153
const aptos = useAptos();

0 commit comments

Comments
 (0)