Skip to content

Commit

Permalink
feat(config): replace network ids constants with imports from network…
Browse files Browse the repository at this point in the history
… store

refs #163, #313
  • Loading branch information
ygrishajev committed Oct 8, 2024
1 parent bc68df8 commit 149c1b5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"deployment",
"certificate",
"dx",
"config",
"stats"
]
]
Expand Down
1 change: 1 addition & 0 deletions apps/stats-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@akashnetwork/ui": "*",
"@akashnetwork/network-store": "*",
"@cosmjs/encoding": "^0.32.4",
"@json2csv/plainjs": "^7.0.4",
"@nivo/line": "^0.87.0",
Expand Down
9 changes: 5 additions & 4 deletions apps/stats-web/src/components/layout/NetworkSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use client";
import React, { useEffect, useState } from "react";
import { MAINNET_ID, Network } from "@akashnetwork/network-store";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, Spinner } from "@akashnetwork/ui/components";

import { mainnetId, setNetworkVersion } from "@/lib/constants";
import { setNetworkVersion } from "@/lib/constants";
import { cn } from "@/lib/utils";
import { initiateNetworkData, networks } from "@/store/networkStore";

Expand All @@ -12,14 +13,14 @@ interface NetworkSelectProps {

const NetworkSelect: React.FC<NetworkSelectProps> = ({ className }) => {
const [isLoadingSettings, setIsLoadingSettings] = useState(true);
const [selectedNetworkId, setSelectedNetworkId] = useState(mainnetId);
const [selectedNetworkId, setSelectedNetworkId] = useState<Network["id"]>(MAINNET_ID);

useEffect(() => {
async function init() {
await initiateNetworkData();
setNetworkVersion();

const selectedNetworkId = localStorage.getItem("selectedNetworkId");
const selectedNetworkId = localStorage.getItem("selectedNetworkId") as Network["id"];
if (selectedNetworkId) {
setSelectedNetworkId(selectedNetworkId);
}
Expand All @@ -30,7 +31,7 @@ const NetworkSelect: React.FC<NetworkSelectProps> = ({ className }) => {
init();
}, []);

const onSelectNetworkChange = (networkId: string) => {
const onSelectNetworkChange = (networkId: Network["id"]) => {
setSelectedNetworkId(networkId);

// Set in the settings and local storage
Expand Down
6 changes: 3 additions & 3 deletions apps/stats-web/src/hooks/useSelectedNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MAINNET_ID } from "@akashnetwork/network-store";
import { useAtom } from "jotai";
import { useEffectOnce } from "usehooks-ts";

import { mainnetId } from "@/lib/constants";
import networkStore, { networks } from "@/store/networkStore";

export const getSelectedNetwork = () => {
const selectedNetworkId = localStorage.getItem("selectedNetworkId") ?? mainnetId;
const selectedNetworkId = localStorage.getItem("selectedNetworkId") ?? MAINNET_ID;
const selectedNetwork = networks.find(n => n.id === selectedNetworkId);

// return mainnet if selected network is not found
Expand All @@ -16,7 +16,7 @@ export const useSelectedNetwork = () => {
const [selectedNetwork, setSelectedNetwork] = useAtom(networkStore.selectedNetwork);

useEffectOnce(() => {
const selectedNetworkId = localStorage.getItem("selectedNetworkId") ?? mainnetId;
const selectedNetworkId = localStorage.getItem("selectedNetworkId") ?? MAINNET_ID;
setSelectedNetwork(networks.find(n => n.id === selectedNetworkId) || networks[0]);
});

Expand Down
26 changes: 12 additions & 14 deletions apps/stats-web/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export const mainnetId = "mainnet";
export const testnetId = "testnet";
export const sandboxId = "sandbox";
import { MAINNET_ID, SANDBOX_ID, TESTNET_ID } from "@akashnetwork/network-store";

export const selectedRangeValues: { [key: string]: number } = {
"7D": 7,
Expand All @@ -23,9 +21,9 @@ export const BASE_API_URL = getApiUrl();

export function getNetworkBaseApiUrl(network: string | null) {
switch (network) {
case testnetId:
case TESTNET_ID:
return BASE_API_TESTNET_URL;
case sandboxId:
case SANDBOX_ID:
return BASE_API_SANDBOX_URL;
default:
return BASE_API_MAINNET_URL;
Expand All @@ -34,8 +32,8 @@ export function getNetworkBaseApiUrl(network: string | null) {

export const uAktDenom = "uakt";
export const usdcIbcDenoms: { [key: string]: string } = {
[mainnetId]: "ibc/170C677610AC31DF0904FFE09CD3B5C657492170E7E52372E48756B71E56F2F1",
[sandboxId]: "ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84"
[MAINNET_ID]: "ibc/170C677610AC31DF0904FFE09CD3B5C657492170E7E52372E48756B71E56F2F1",
[SANDBOX_ID]: "ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84"
};

function getApiMainnetUrl() {
Expand Down Expand Up @@ -81,22 +79,22 @@ export function setNetworkVersion() {
const _selectedNetworkId = localStorage.getItem("selectedNetworkId");

switch (_selectedNetworkId) {
case mainnetId:
case MAINNET_ID:
networkVersion = "v1beta3";
selectedNetworkId = mainnetId;
selectedNetworkId = MAINNET_ID;
break;
case testnetId:
case TESTNET_ID:
networkVersion = "v1beta3";
selectedNetworkId = testnetId;
selectedNetworkId = TESTNET_ID;
break;
case sandboxId:
case SANDBOX_ID:
networkVersion = "v1beta3";
selectedNetworkId = sandboxId;
selectedNetworkId = SANDBOX_ID;
break;

default:
networkVersion = "v1beta3";
selectedNetworkId = mainnetId;
selectedNetworkId = MAINNET_ID;
break;
}
}
8 changes: 4 additions & 4 deletions apps/stats-web/src/store/networkStore.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { MAINNET_ID, SANDBOX_ID, TESTNET_ID } from "@akashnetwork/network-store";
import axios from "axios";
import { atom } from "jotai";

import { ApiUrlService } from "@/lib/apiUtils";
import { mainnetId, sandboxId, testnetId } from "@/lib/constants";
import { Network } from "@/types/network";

export let networks: Network[] = [
{
id: mainnetId,
id: MAINNET_ID,
title: "Mainnet",
description: "Akash Network mainnet network.",
chainId: "akashnet-2",
Expand All @@ -17,7 +17,7 @@ export let networks: Network[] = [
version: null // Set asynchronously
},
{
id: testnetId,
id: TESTNET_ID,
title: "GPU Testnet",
description: "Testnet of the new GPU features.",
chainId: "testnet-02",
Expand All @@ -26,7 +26,7 @@ export let networks: Network[] = [
version: null // Set asynchronously
},
{
id: sandboxId,
id: SANDBOX_ID,
title: "Sandbox",
description: "Sandbox of the mainnet version.",
chainId: "sandbox-01",
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ services:
- /app/node_modules
- /app/apps/stats-web/node_modules
- /app/apps/stats-web/.next
- ./packages:/app/packages

0 comments on commit 149c1b5

Please sign in to comment.