Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alimaktabi committed Jan 28, 2024
2 parents 3551ee2 + ea5870e commit ab046ec
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
31 changes: 16 additions & 15 deletions components/containers/landing/stats.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { countGasClaimedAPI, countUsersAPI } from "@/utils/api"
import Widget from "./widget"
import { FC } from "react"
import { Chain } from "@/types"
import { countGasClaimedAPI, countUsersAPI } from "@/utils/api";
import Widget from "./widget";
import { FC } from "react";
import { Chain } from "@/types";
import { numberWithCommas } from "@/utils";

export const getTotalNetworks = (chains: Chain[]) => {
return chains.reduce((total, chain) => total + (!chain.isTestnet ? 1 : 0), 0)
}
return chains.reduce((total, chain) => total + (!chain.isTestnet ? 1 : 0), 0);
};

export const getTotalTestNetworks = (chains: Chain[]) => {
return chains.reduce((total, chain) => total + (chain.isTestnet ? 1 : 0), 0)
}
return chains.reduce((total, chain) => total + (chain.isTestnet ? 1 : 0), 0);
};

const LandingStats: FC<{ chains: Chain[] }> = async ({ chains }) => {
const usersCount = await countUsersAPI()
const gasClaimedCount = await countGasClaimedAPI()
const usersCount = await countUsersAPI();
const gasClaimedCount = await countGasClaimedAPI();

const stats = [
{ name: "Main Networks", number: getTotalNetworks(chains) },
{ name: "Test Networks", number: getTotalTestNetworks(chains) },
]
];

return (
<section id="home-stats" className={"flex gap-4 justify-between"}>
Expand Down Expand Up @@ -47,7 +48,7 @@ const LandingStats: FC<{ chains: Chain[] }> = async ({ chains }) => {
<div key={stat.name} className={"flex flex-col gap-2 items-center"}>
<p className={"text-xl text-space-green font-semibold"}>
{/* {numberWithCommas(typeof stat.number == 'string' ? parseFloat(stat.number) : stat.number)} */}
{stat.number}
{numberWithCommas(stat.number)}
</p>
<p className={"text-gradient-primary text-xs font-medium"}>
{stat.name}
Expand All @@ -66,7 +67,7 @@ const LandingStats: FC<{ chains: Chain[] }> = async ({ chains }) => {
</div>
</Widget>
</section>
)
}
);
};

export default LandingStats
export default LandingStats;
8 changes: 7 additions & 1 deletion context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import { GlobalContextProvider } from "./globalProvider";
import { UserContextProvider } from "./userProfile";
import { Settings } from "@/types";
import WalletProvider from "./walletProvider";
import { parseFieldSetting, snakeToCamel } from "@/utils/api";

export const UnitapProvider: FC<PropsWithChildren> = async ({ children }) => {
const settings: Settings = await fetch(
const settingsRes: { index: string; value: string }[] = await fetch(
process.env.NEXT_PUBLIC_API_URL! + "/api/gastap/settings/",
{ next: { revalidate: 180 } }
).then((res) => res.json());

const settings: Settings = settingsRes.reduce((prev, curr) => {
(prev as any)[snakeToCamel(curr.index)] = parseFieldSetting(curr.value);
return prev;
}, {} as Settings);

return (
<ErrorsProvider>
<GlobalContextProvider>
Expand Down
29 changes: 27 additions & 2 deletions utils/api/gastap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,34 @@ export const convertFaucetToChain = (faucet: Faucet) => {
} as Chain;
};

export const snakeToCamel = (str: string) => {
return str.replace(/_([a-z])/g, function (match, group) {
return group.toUpperCase();
});
};

export const parseFieldSetting = (value: string) => {
if (value === "True") return true;
if (value === "False") return false;

if (!isNaN(value as any)) return Number(value);

return value;
};

export async function getWeeklyChainClaimLimitAPI() {
const response = await axiosInstance.get<Settings>("/api/gastap/settings/");
return response.data;
const response = await axiosInstance.get<{ index: string; value: string }[]>(
"/api/gastap/settings/"
);

const result: Settings = response.data.reduce((prev, curr) => {
(prev as any)[snakeToCamel(curr.index)] = parseFieldSetting(curr.value);
return prev;
}, {} as Settings);

console.log(result);

return result;
}

export async function getRemainingClaimsAPI(token: string) {
Expand Down

0 comments on commit ab046ec

Please sign in to comment.