Skip to content

Commit

Permalink
feat/qb-2301: Add apis for coingecko/marketcap
Browse files Browse the repository at this point in the history
  • Loading branch information
BoThe1K committed Nov 16, 2023
1 parent 0261a3b commit d77c7eb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
16 changes: 16 additions & 0 deletions apps/web-stratos/src/pages/api/circulating-supply.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getMetrics } from '@/screens/home/components/tokenomics/queries';
import { bigToNativeDecimals } from '@/screens/home/components/tokenomics/utils';
import type { NextApiRequest, NextApiResponse } from 'next';

type MetricsData = {
circulation_supply: string;
};

export default async function handler(req: NextApiRequest, res: NextApiResponse<string>) {
try {
const result: MetricsData = await getMetrics();
res.status(200).send(bigToNativeDecimals(result.circulation_supply));
} catch (err) {
res.status(400).json({ error: 'failed to load data' });
}
}
16 changes: 16 additions & 0 deletions apps/web-stratos/src/pages/api/total-supply.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getMetrics } from '@/screens/home/components/tokenomics/queries';
import { bigToNativeDecimals } from '@/screens/home/components/tokenomics/utils';
import type { NextApiRequest, NextApiResponse } from 'next';

type MetricsData = {
total_supply: string;
};

export default async function handler(req: NextApiRequest, res: NextApiResponse<string>) {
try {
const result: MetricsData = await getMetrics();
res.status(200).send(bigToNativeDecimals(result.total_supply));
} catch (err) {
res.status(400).json({ error: 'failed to load data' });
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useId, FC } from 'react';

import { BigNumber } from 'ethers';

import { Tooltip, BarChart, CartesianGrid, XAxis, YAxis, Bar } from 'recharts';

interface ITokenomicChart {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FC } from 'react';
import numeral from 'numeral';
import dynamic from 'next/dynamic';

import chainConfig from '@/chainConfig';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { BigNumberish } from 'ethers';
import { BigNumberish, FixedNumber } from 'ethers';
import { formatUnits } from 'ethers/lib/utils';

export function prettyFormat(value: BigNumberish, unitName?: number, points = 8): number {
return +(+formatUnits(value, unitName)).toFixed(points);
}

export const bigToNativeDecimals = (bn: string, decimals?: number): string =>
FixedNumber.fromString(bn)
.divUnsafe(FixedNumber.from((10 ** (decimals || 18)).toString()))
.toString();

0 comments on commit d77c7eb

Please sign in to comment.