Skip to content

Commit

Permalink
feat(config): extract denom constants to a dedicated config
Browse files Browse the repository at this point in the history
refs #163, #313
  • Loading branch information
ygrishajev committed Oct 3, 2024
1 parent dbc6830 commit 5f9af54
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
8 changes: 8 additions & 0 deletions apps/stats-web/src/config/denom.config.ts
Original file line number Diff line number Diff line change
@@ -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<MainnetNetworkId | SandboxNetworkId, string> = {
[MAINNET_ID]: "ibc/170C677610AC31DF0904FFE09CD3B5C657492170E7E52372E48756B71E56F2F1",
[SANDBOX_ID]: "ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84"
};
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -42,7 +42,7 @@ export const PricingProvider: React.FC<any> = ({ 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
Expand Down
20 changes: 3 additions & 17 deletions apps/stats-web/src/hooks/useDenom.ts
Original file line number Diff line number Diff line change
@@ -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];
};
6 changes: 0 additions & 6 deletions apps/stats-web/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 5f9af54

Please sign in to comment.