From 5f9af54a45be73ea233222edf099c6da45f79686 Mon Sep 17 00:00:00 2001 From: Yaroslav Grishajev Date: Thu, 3 Oct 2024 11:25:21 +0200 Subject: [PATCH] feat(config): extract denom constants to a dedicated config refs #163, #313 --- apps/stats-web/src/config/denom.config.ts | 8 ++++++++ .../PricingProvider/PricingProvider.tsx | 4 ++-- apps/stats-web/src/hooks/useDenom.ts | 20 +++---------------- apps/stats-web/src/lib/constants.ts | 6 ------ 4 files changed, 13 insertions(+), 25 deletions(-) create mode 100644 apps/stats-web/src/config/denom.config.ts diff --git a/apps/stats-web/src/config/denom.config.ts b/apps/stats-web/src/config/denom.config.ts new file mode 100644 index 000000000..eb079e6ba --- /dev/null +++ b/apps/stats-web/src/config/denom.config.ts @@ -0,0 +1,8 @@ +import type { MainnetNetworkId, SandboxNetworkId } from "@akashnetwork/akashjs/build/types/network"; +import { MAINNET_ID, SANDBOX_ID } from "@akashnetwork/network-store"; + +export const UAKT_DENOM = "uakt"; +export const USDC_IBC_DENOMS: Record = { + [MAINNET_ID]: "ibc/170C677610AC31DF0904FFE09CD3B5C657492170E7E52372E48756B71E56F2F1", + [SANDBOX_ID]: "ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84" +}; diff --git a/apps/stats-web/src/context/PricingProvider/PricingProvider.tsx b/apps/stats-web/src/context/PricingProvider/PricingProvider.tsx index bfc47ef9a..78347b0a3 100644 --- a/apps/stats-web/src/context/PricingProvider/PricingProvider.tsx +++ b/apps/stats-web/src/context/PricingProvider/PricingProvider.tsx @@ -2,8 +2,8 @@ import React from "react"; +import { UAKT_DENOM } from "@/config/denom.config"; import { useUsdcDenom } from "@/hooks/useDenom"; -import { uAktDenom } from "@/lib/constants"; import { roundDecimal } from "@/lib/mathHelpers"; import { useMarketData } from "@/queries"; @@ -42,7 +42,7 @@ export const PricingProvider: React.FC = ({ children }) => { const getPriceForDenom = (denom: string): number => { switch (denom) { - case uAktDenom: + case UAKT_DENOM: return marketData?.price || 0; case usdcIbcDenom: return 1; // TODO Get price from API diff --git a/apps/stats-web/src/hooks/useDenom.ts b/apps/stats-web/src/hooks/useDenom.ts index dde453160..3a2f76265 100644 --- a/apps/stats-web/src/hooks/useDenom.ts +++ b/apps/stats-web/src/hooks/useDenom.ts @@ -1,22 +1,8 @@ -import { getSelectedNetwork, useSelectedNetwork } from "./useSelectedNetwork"; +import { useSelectedNetwork } from "./useSelectedNetwork"; -import { usdcIbcDenoms } from "@/lib/constants"; +import { USDC_IBC_DENOMS } from "@/config/denom.config"; export const useUsdcDenom = () => { const selectedNetwork = useSelectedNetwork(); - return usdcIbcDenoms[selectedNetwork.id]; -}; - -export const getUsdcDenom = () => { - const selectedNetwork = getSelectedNetwork(); - return usdcIbcDenoms[selectedNetwork.id as any]; -}; - -export const useSdlDenoms = () => { - const usdcDenom = useUsdcDenom(); - - return [ - { id: "uakt", label: "uAKT", tokenLabel: "AKT", value: "uakt" }, - { id: "uusdc", label: "uUSDC", tokenLabel: "USDC", value: usdcDenom } - ]; + return USDC_IBC_DENOMS[selectedNetwork.id]; }; diff --git a/apps/stats-web/src/lib/constants.ts b/apps/stats-web/src/lib/constants.ts index 3c0974c6b..151c7e8c9 100644 --- a/apps/stats-web/src/lib/constants.ts +++ b/apps/stats-web/src/lib/constants.ts @@ -24,12 +24,6 @@ export function getNetworkBaseApiUrl(network: string | null) { } } -export const uAktDenom = "uakt"; -export const usdcIbcDenoms: { [key: string]: string } = { - [MAINNET_ID]: "ibc/170C677610AC31DF0904FFE09CD3B5C657492170E7E52372E48756B71E56F2F1", - [SANDBOX_ID]: "ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84" -}; - function getApiMainnetUrl() { if (process.env.API_MAINNET_BASE_URL) return process.env.API_MAINNET_BASE_URL; if (typeof window === "undefined") return "http://localhost:3080";