From 05324a68fd4aa5cf1adff6bf99432283f18dd3c6 Mon Sep 17 00:00:00 2001 From: forbesus Date: Wed, 11 Dec 2024 05:03:18 -0800 Subject: [PATCH] feat(observability): utilise new logger in provider-console ref #433 --- apps/provider-console/mvm.lock | 3 +- apps/provider-console/package.json | 1 + .../src/chains/akash-sandbox.ts | 6 +- .../src/chains/akash-testnet.ts | 4 +- apps/provider-console/src/chains/akash.ts | 278 +++++++++++++----- .../become-provider/WalletImport.tsx | 8 +- .../src/config/browser-env.config.ts | 3 +- .../src/config/env-config.schema.ts | 3 +- .../src/config/logger.config.ts | 7 + .../ControlMachineProvider.tsx | 5 +- .../context/WalletProvider/WalletProvider.tsx | 8 +- .../src/hooks/useLocalStorage.ts | 10 +- apps/provider-console/src/hooks/useLogger.ts | 8 + .../src/pages/pricing/index.tsx | 5 +- .../src/store/networkStore.ts | 5 +- apps/provider-console/src/utils/authClient.ts | 5 +- .../src/utils/consoleClient.ts | 5 +- apps/provider-console/src/utils/restClient.ts | 5 +- apps/provider-console/src/utils/tokenUtils.ts | 5 +- 19 files changed, 282 insertions(+), 92 deletions(-) create mode 100644 apps/provider-console/src/config/logger.config.ts create mode 100644 apps/provider-console/src/hooks/useLogger.ts diff --git a/apps/provider-console/mvm.lock b/apps/provider-console/mvm.lock index 3120b68bf..4627f3f2e 100644 --- a/apps/provider-console/mvm.lock +++ b/apps/provider-console/mvm.lock @@ -1,6 +1,7 @@ { "dependencies": { - "@akashnetwork/ui": "1.0.0" + "@akashnetwork/ui": "1.0.0", + "@akashnetwork/logging": "2.0.2" }, "devDependencies": { "@akashnetwork/dev-config": "1.0.0" diff --git a/apps/provider-console/package.json b/apps/provider-console/package.json index 5ebc7c4cb..4bcdf84b1 100644 --- a/apps/provider-console/package.json +++ b/apps/provider-console/package.json @@ -13,6 +13,7 @@ }, "dependencies": { "@akashnetwork/ui": "*", + "@akashnetwork/logging": "*", "@chain-registry/types": "^0.50.1", "@cosmos-kit/cosmostation-extension": "^2.12.2", "@cosmos-kit/keplr": "^2.12.2", diff --git a/apps/provider-console/src/chains/akash-sandbox.ts b/apps/provider-console/src/chains/akash-sandbox.ts index f351c4e38..823718b42 100644 --- a/apps/provider-console/src/chains/akash-sandbox.ts +++ b/apps/provider-console/src/chains/akash-sandbox.ts @@ -1,11 +1,11 @@ -import { AssetList } from "@chain-registry/types"; +import { AssetList, Chain } from "@chain-registry/types"; import { akash, akashAssetList } from "./akash"; -export const akashSandbox = { +export const akashSandbox: Chain = { ...akash, chain_id: "sandbox-01", - network_type: "sandbox", + network_type: "devnet", chain_name: "akash-sandbox", pretty_name: "Akash-Sandbox", apis: { diff --git a/apps/provider-console/src/chains/akash-testnet.ts b/apps/provider-console/src/chains/akash-testnet.ts index 009d4fef5..27381e866 100644 --- a/apps/provider-console/src/chains/akash-testnet.ts +++ b/apps/provider-console/src/chains/akash-testnet.ts @@ -1,8 +1,8 @@ -import { AssetList } from "@chain-registry/types"; +import { AssetList, Chain } from "@chain-registry/types"; import { akash, akashAssetList } from "./akash"; -export const akashTestnet = { +export const akashTestnet: Chain = { ...akash, chain_id: "testnet-02", network_type: "testnet", diff --git a/apps/provider-console/src/chains/akash.ts b/apps/provider-console/src/chains/akash.ts index a509807cd..65a58f08c 100644 --- a/apps/provider-console/src/chains/akash.ts +++ b/apps/provider-console/src/chains/akash.ts @@ -1,14 +1,14 @@ -import { AssetList } from "@chain-registry/types"; +import { AssetList, Chain } from "@chain-registry/types"; import { assets } from "chain-registry"; -// Obtained from https://raw.githubusercontent.com/cosmos/chain-registry/master/akash/chain.json -export const akash = { +export const akash: Chain = { $schema: "../chain.schema.json", chain_name: "akash", status: "live", network_type: "mainnet", website: "https://akash.network/", pretty_name: "Akash", + chain_type: "cosmos", chain_id: "akashnet-2", bech32_prefix: "akash", daemon_name: "akash", @@ -18,7 +18,10 @@ export const akash = { fee_tokens: [ { denom: "uakt", - fixed_min_gas_price: 0 + fixed_min_gas_price: 0.00025, + low_gas_price: 0.00025, + average_gas_price: 0.0025, + high_gas_price: 0.025 } ] }, @@ -31,11 +34,17 @@ export const akash = { }, codebase: { git_repo: "https://github.com/akash-network/node/", - recommended_version: "v0.26.2", - compatible_versions: ["v0.26.1", "v0.26.2"], + recommended_version: "v0.36.0", + compatible_versions: ["v0.36.0"], binaries: { - "linux/amd64": "https://github.com/akash-network/node/releases/download/v0.26.2/akash_linux_amd64.zip", - "linux/arm64": "https://github.com/akash-network/node/releases/download/v0.26.2/akash_linux_arm64.zip" + "linux/amd64": "https://github.com/akash-network/node/releases/download/v0.36.0/akash_linux_amd64.zip", + "linux/arm64": "https://github.com/akash-network/node/releases/download/v0.36.0/akash_linux_arm64.zip" + }, + consensus: { + type: "cometbft", + version: "v0.34.27", + repo: "https://github.com/akash-network/cometbft", + tag: "v0.34.27-akash" }, genesis: { genesis_url: "https://raw.githubusercontent.com/akash-network/net/master/mainnet/genesis.json" @@ -71,9 +80,118 @@ export const akash = { "linux/amd64": "https://github.com/akash-network/node/releases/download/v0.26.2/akash_linux_amd64.zip", "linux/arm64": "https://github.com/akash-network/node/releases/download/v0.26.2/akash_linux_arm64.zip" }, - next_version_name: "" + next_version_name: "v0.28.0" + }, + { + name: "v0.28.0", + recommended_version: "v0.28.2", + compatible_versions: ["v0.28.2"], + proposal: 237, + height: 13759618, + binaries: { + "linux/amd64": "https://github.com/akash-network/node/releases/download/v0.28.2/akash_linux_amd64.zip", + "linux/arm64": "https://github.com/akash-network/node/releases/download/v0.28.2/akash_linux_arm64.zip" + }, + next_version_name: "v0.30.0" + }, + { + name: "v0.30.0", + recommended_version: "v0.30.0", + compatible_versions: ["v0.30.0"], + proposal: 238, + height: 1388074, + binaries: { + "linux/amd64": "https://github.com/akash-network/node/releases/download/v0.30.0/akash_linux_amd64.zip", + "linux/arm64": "https://github.com/akash-network/node/releases/download/v0.30.0/akash_linux_arm64.zip" + }, + next_version_name: "v0.32.0" + }, + { + name: "v0.32.0", + recommended_version: "v0.32.1", + compatible_versions: ["v0.32.1"], + proposal: 249, + height: 15414427, + binaries: { + "linux/amd64": "https://github.com/akash-network/node/releases/download/v0.32.1/akash_linux_amd64.zip", + "linux/arm64": "https://github.com/akash-network/node/releases/download/v0.32.1238/akash_linux_arm64.zip" + }, + consensus: { + type: "cometbft", + version: "v0.34.27", + repo: "https://github.com/akash-network/cometbft", + tag: "v0.34.27-akash" + }, + next_version_name: "v0.34.0", + sdk: { + type: "cosmos", + version: "v0.45.16" + }, + ibc: { + type: "go", + version: "v4.4.2" + } + }, + { + name: "v0.34.0", + recommended_version: "v0.34.1", + compatible_versions: ["v0.34.1"], + proposal: 256, + height: 16133283, + binaries: { + "linux/amd64": "https://github.com/akash-network/node/releases/download/v0.34.1/akash_linux_amd64.zip", + "linux/arm64": "https://github.com/akash-network/node/releases/download/v0.34.1/akash_linux_arm64.zip" + }, + consensus: { + type: "cometbft", + version: "v0.34.27", + repo: "https://github.com/akash-network/cometbft", + tag: "v0.34.27-akash" + }, + next_version_name: "v0.36.0", + sdk: { + type: "cosmos", + version: "v0.45.16" + }, + ibc: { + type: "go", + version: "v4.6.0" + } + }, + { + name: "v0.36.0", + recommended_version: "v0.36.0", + compatible_versions: ["v0.36.0"], + proposal: 257, + height: 16708237, + binaries: { + "linux/amd64": "https://github.com/akash-network/node/releases/download/v0.36.0/akash_linux_amd64.zip", + "linux/arm64": "https://github.com/akash-network/node/releases/download/v0.36.0/akash_linux_arm64.zip" + }, + consensus: { + type: "cometbft", + version: "v0.34.27", + repo: "https://github.com/akash-network/cometbft", + tag: "v0.34.27-akash" + }, + sdk: { + type: "cosmos", + version: "v0.45.16" + }, + ibc: { + type: "go", + version: "v4.6.0" + } } - ] + ], + sdk: { + type: "cosmos", + version: "v0.45.16" + }, + ibc: { + type: "go", + version: "v4.6.0" + } }, logo_URIs: { png: "https://raw.githubusercontent.com/cosmos/chain-registry/master/akash/images/akt.png", @@ -114,19 +232,23 @@ export const akash = { address: "rpc.la.akash.farm:26656" }, { - id: "e1b058e5cfa2b836ddaa496b10911da62dcf182e", - address: "akash-seed-de.allnodes.me:26656", - provider: "Allnodes.com ⚡️ Nodes & Staking" - }, - { - id: "e726816f42831689eab9378d5d577f1d06d25716", - address: "akash-seed-us.allnodes.me:26656", - provider: "Allnodes.com ⚡️ Nodes & Staking" + id: "8542cd7e6bf9d260fef543bc49e59be5a3fa9074", + address: "seed.publicnode.com:26656", + provider: "Allnodes ⚡️ Nodes & Staking" }, { id: "9aa4c9097c818871e45aaca4118a9fe5e86c60e2", address: "seed-akash-01.stakeflow.io:1506", provider: "Stakeflow" + }, + { + id: "61686e588f0af938484579adbc2093adff06c7aa", + address: "europlots.com:26656" + }, + { + id: "c28827cb96c14c905b127b92065a3fb4cd77d7f6", + address: "seeds.whispernode.com:12856", + provider: "WhisperNode 🤐" } ], persistent_peers: [ @@ -155,6 +277,11 @@ export const akash = { id: "9aa4c9097c818871e45aaca4118a9fe5e86c60e2", address: "peer-akash-01.stakeflow.io:1506", provider: "Stakeflow" + }, + { + id: "73ef1c0f9bc77fd925decf7fa41f22a35b5dc76d", + address: "akash.declab.pro:26603", + provider: "Decloud Nodes Lab" } ] }, @@ -169,41 +296,21 @@ export const akash = { provider: "ecostake" }, { - address: "https://akash-rpc.lavenderfive.com:443", + address: "https://rpc.lavenderfive.com:443/akash", provider: "Lavender.Five Nodes" }, { address: "https://akash-rpc.polkachu.com", provider: "Polkachu" }, - { - address: "https://rpc-akash.cosmos-spaces.cloud", - provider: "Cosmos Spaces" - }, - { - address: "https://rpc-akash-ia.cosmosia.notional.ventures:443", - provider: "Notional" - }, { address: "http://akash.c29r3.xyz:80/rpc", provider: "c29r3" }, - { - address: "https://akash-mainnet-rpc.autostake.com:443", - provider: "AutoStake 🛡️ Slash Protected" - }, - { - address: "https://akash.rpc.interchain.ivaldilabs.xyz", - provider: "ivaldilabs" - }, { address: "https://akash-rpc.kleomedes.network", provider: "Kleomedes" }, - { - address: "https://rpc-akash-01.stakeflow.io", - provider: "Stakeflow" - }, { address: "https://akash-mainnet-rpc.cosmonautstakes.com:443", provider: "Cosmonaut Stakes" @@ -213,12 +320,16 @@ export const akash = { provider: "w3coins" }, { - address: "https://akash-rpc.publicnode.com", - provider: "Allnodes.com ⚡️ Nodes & Staking" + address: "https://akash-rpc.publicnode.com:443", + provider: "Allnodes ⚡️ Nodes & Staking" }, { - address: "https://akash-rpc.validatornode.com", - provider: "ValidatorNode" + address: "https://akash.declab.pro:26601", + provider: "Decloud Nodes Lab" + }, + { + address: "https://rpc.akash.bronbro.io:443", + provider: "Bro_n_Bro" } ], rest: [ @@ -231,7 +342,7 @@ export const akash = { provider: "ecostake" }, { - address: "https://akash-api.lavenderfive.com:443", + address: "https://rest.lavenderfive.com:443/akash", provider: "Lavender.Five Nodes" }, { @@ -254,10 +365,6 @@ export const akash = { address: "https://akash-mainnet-lcd.autostake.com:443", provider: "AutoStake 🛡️ Slash Protected" }, - { - address: "https://akash.rest.interchain.ivaldilabs.xyz", - provider: "ivaldilabs" - }, { address: "https://akash-api.kleomedes.network", provider: "Kleomedes" @@ -276,11 +383,27 @@ export const akash = { }, { address: "https://akash-rest.publicnode.com", - provider: "Allnodes.com ⚡️ Nodes & Staking" + provider: "Allnodes ⚡️ Nodes & Staking" }, { address: "https://akash-api.validatornode.com", provider: "ValidatorNode" + }, + { + address: "https://api-akash.whispernode.com:443", + provider: "WhisperNode 🤐" + }, + { + address: "https://public.stakewolle.com/cosmos/akash/rest", + provider: "Stakewolle" + }, + { + address: "https://akash.declab.pro:443", + provider: "Decloud Nodes Lab" + }, + { + address: "https://lcd.akash.bronbro.io:443", + provider: "Bro_n_Bro" } ], grpc: [ @@ -289,7 +412,7 @@ export const akash = { provider: "Notional" }, { - address: "akash-grpc.lavenderfive.com:443", + address: "akash.lavenderfive.com:443", provider: "Lavender.Five Nodes 🐝" }, { @@ -304,10 +427,6 @@ export const akash = { address: "grpc-akash.cosmos-spaces.cloud:1110", provider: "Cosmos Spaces" }, - { - address: "akash.grpc.interchain.ivaldilabs.xyz:443", - provider: "ivaldilabs" - }, { address: "grpc-akash-01.stakeflow.io:1502", provider: "Stakeflow" @@ -318,16 +437,28 @@ export const akash = { }, { address: "akash-grpc.publicnode.com:443", - provider: "Allnodes.com ⚡️ Nodes & Staking" + provider: "Allnodes ⚡️ Nodes & Staking" + }, + { + address: "https://akash.declab.pro:9001", + provider: "Decloud Nodes Lab" + }, + { + address: "grpc-akash.whispernode.com:443", + provider: "WhisperNode 🤐" + }, + { + address: "https://grpc.akash.bronbro.io:443", + provider: "Bro_n_Bro" } ] }, explorers: [ { - kind: "EZ Staking", - url: "https://app.ezstaking.io/akash", - tx_page: "https://app.ezstaking.io/akash/txs/${txHash}", - account_page: "https://app.ezstaking.io/akash/account/${accountAddress}" + kind: "ezstaking", + url: "https://ezstaking.app/akash", + tx_page: "https://ezstaking.app/akash/txs/${txHash}", + account_page: "https://ezstaking.app/akash/account/${accountAddress}" }, { kind: "mintscan", @@ -341,9 +472,10 @@ export const akash = { tx_page: "https://ping.pub/akash-network/tx/${txHash}" }, { - kind: "bigdipper", - url: "https://akash.bigdipper.live/", - tx_page: "https://akash.bigdipper.live/transactions/${txHash}" + kind: "staking-explorer.com", + url: "https://staking-explorer.com/explorer/akash", + tx_page: "https://staking-explorer.com/transaction.php?chain=akash&tx=${txHash}", + account_page: "https://staking-explorer.com/account.php?chain=akash&addr=${accountAddress}" }, { kind: "atomscan", @@ -352,9 +484,9 @@ export const akash = { account_page: "https://atomscan.com/akash/accounts/${accountAddress}" }, { - kind: "Akash Stats", - url: "https://stats.akash.network/blocks", - tx_page: "https://stats.akash.network/transactions/${txHash}" + kind: "cloudmos", + url: "https://cloudmos.io/blocks", + tx_page: "https://cloudmos.io/transactions/${txHash}" }, { kind: "Stakeflow", @@ -365,12 +497,26 @@ export const akash = { kind: "ValidatorNode", url: "https://explorer.validatornode.com/akash-network", tx_page: "https://explorer.validatornode.com/akash-network/tx/${txHash}" + }, + { + kind: "Decloud Nodes Lab", + url: "https://explorer.declab.pro/Akash", + tx_page: "https://explorer.declab.pro/Akash/tx/${txHash}" + }, + { + kind: "WhisperNode 🤐", + url: "https://mainnet.whispernode.com/akash", + tx_page: "https://mainnet.whispernode.com/akash/tx/${txHash}", + account_page: "https://mainnet.whispernode.com/akash/account/${accountAddress}" } ], images: [ { png: "https://raw.githubusercontent.com/cosmos/chain-registry/master/akash/images/akt.png", - svg: "https://raw.githubusercontent.com/cosmos/chain-registry/master/akash/images/akt.svg" + svg: "https://raw.githubusercontent.com/cosmos/chain-registry/master/akash/images/akt.svg", + theme: { + primary_color_hex: "#bc342c" + } } ] }; diff --git a/apps/provider-console/src/components/become-provider/WalletImport.tsx b/apps/provider-console/src/components/become-provider/WalletImport.tsx index 96d72b418..5caef4546 100644 --- a/apps/provider-console/src/components/become-provider/WalletImport.tsx +++ b/apps/provider-console/src/components/become-provider/WalletImport.tsx @@ -23,6 +23,7 @@ import { z } from "zod"; import { useControlMachine } from "@src/context/ControlMachineProvider"; import { useWallet } from "@src/context/WalletProvider"; +import { useLogger } from "@src/hooks/useLogger"; import providerProcessStore from "@src/store/providerProcessStore"; import { ControlMachineWithAddress } from "@src/types/controlMachine"; import restClient from "@src/utils/restClient"; @@ -77,10 +78,11 @@ export const WalletImport: React.FC = ({ onComplete }) => { const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const router = useRouter(); - + const [providerProcess] = useAtom(providerProcessStore.providerProcessAtom); const [, resetProviderProcess] = useAtom(providerProcessStore.resetProviderProcess); const { setControlMachine } = useControlMachine(); + const logger = useLogger("apps/provider-console/src/components/become-provider/WalletImport.tsx"); const { address } = useWallet(); const defaultValues: Partial = { @@ -147,7 +149,7 @@ export const WalletImport: React.FC = ({ onComplete }) => { throw new Error("No machine information available"); } } catch (error) { - console.error("Error during wallet verification:", error); + logger.debug(`Error during wallet verification: ${error}`); setError("An error occurred while processing your request. Please try again."); } finally { setIsLoading(false); @@ -332,7 +334,7 @@ export const WalletImport: React.FC = ({ onComplete }) => { type="button" onClick={() => { // TODO: Verify Manual Wallet Import - console.log("Manual Wallet Import"); + logger.debug("Manual Wallet Import"); }} > Verify Wallet Import diff --git a/apps/provider-console/src/config/browser-env.config.ts b/apps/provider-console/src/config/browser-env.config.ts index 65aa87adb..9fa37285c 100644 --- a/apps/provider-console/src/config/browser-env.config.ts +++ b/apps/provider-console/src/config/browser-env.config.ts @@ -7,5 +7,6 @@ export const browserEnvConfig = validateStaticEnvVars({ NEXT_PUBLIC_CONSOLE_API_MAINNET_URL: process.env.NEXT_PUBLIC_CONSOLE_API_MAINNET_URL, NEXT_PUBLIC_BASE_SECURITY_URL: process.env.NEXT_PUBLIC_BASE_SECURITY_URL, NEXT_PUBLIC_MAINNET_RPC_URL: process.env.NEXT_PUBLIC_MAINNET_RPC_URL, - NEXT_PUBLIC_MAINNET_API_URL: process.env.NEXT_PUBLIC_MAINNET_API_URL + NEXT_PUBLIC_MAINNET_API_URL: process.env.NEXT_PUBLIC_MAINNET_API_URL, + NEXT_PUBLIC_LOG_LEVEL: process.env.NEXT_PUBLIC_LOG_LEVEL }); diff --git a/apps/provider-console/src/config/env-config.schema.ts b/apps/provider-console/src/config/env-config.schema.ts index 7e28db06d..a46964fbd 100644 --- a/apps/provider-console/src/config/env-config.schema.ts +++ b/apps/provider-console/src/config/env-config.schema.ts @@ -9,7 +9,8 @@ export const browserEnvSchema = z.object({ NEXT_PUBLIC_CONSOLE_API_MAINNET_URL: z.string().url(), NEXT_PUBLIC_BASE_SECURITY_URL: z.string().url(), NEXT_PUBLIC_MAINNET_RPC_URL: z.string().url(), - NEXT_PUBLIC_MAINNET_API_URL: z.string().url() + NEXT_PUBLIC_MAINNET_API_URL: z.string().url(), + NEXT_PUBLIC_LOG_LEVEL: z.enum(["fatal", "error", "warn", "info", "debug", "trace"]).optional().default("info") }); export type BrowserEnvConfig = z.infer; diff --git a/apps/provider-console/src/config/logger.config.ts b/apps/provider-console/src/config/logger.config.ts new file mode 100644 index 000000000..7e4aa54e7 --- /dev/null +++ b/apps/provider-console/src/config/logger.config.ts @@ -0,0 +1,7 @@ +"use client"; + +import { LoggerService } from "@akashnetwork/logging"; + +import { browserEnvConfig } from "./browser-env.config"; + +LoggerService.configure({ LOG_LEVEL: browserEnvConfig.NEXT_PUBLIC_LOG_LEVEL }); diff --git a/apps/provider-console/src/context/ControlMachineProvider/ControlMachineProvider.tsx b/apps/provider-console/src/context/ControlMachineProvider/ControlMachineProvider.tsx index 7698fbb2c..c5a1fb15b 100644 --- a/apps/provider-console/src/context/ControlMachineProvider/ControlMachineProvider.tsx +++ b/apps/provider-console/src/context/ControlMachineProvider/ControlMachineProvider.tsx @@ -6,6 +6,7 @@ import { cn } from "@akashnetwork/ui/utils"; import { useAtom } from "jotai"; import { ServerForm } from "@src/components/become-provider/ServerForm"; +import { useLogger } from "@src/hooks/useLogger"; import controlMachineStore from "@src/store/controlMachineStore"; import { ControlMachineWithAddress } from "@src/types/controlMachine"; import restClient from "@src/utils/restClient"; @@ -25,11 +26,13 @@ type ContextType = { const ControlMachineContext = React.createContext({} as ContextType); export function ControlMachineProvider({ children }: Props) { + const [controlMachineLoading, setControlMachineLoading] = useState(false); const [controlMachines, setControlMachines] = useAtom(controlMachineStore.controlMachineAtom); const [activeControlMachine, setActiveControlMachine] = useState(null); const { address, isWalletArbitrarySigned, isProvider } = useWallet(); const [controlMachineDrawerOpen, setControlMachineDrawerOpen] = useState(false); + const logger = useLogger("apps/provider-console/src/context/ControlMachineProvider/ControlMachineProvider.tsx"); useEffect(() => { if (isWalletArbitrarySigned || isProvider) { @@ -54,7 +57,7 @@ export function ControlMachineProvider({ children }: Props) { setActiveControlMachine(controlMachine); } } catch (error) { - console.error(error); + logger.debug(error); } finally { setControlMachineLoading(false); } diff --git a/apps/provider-console/src/context/WalletProvider/WalletProvider.tsx b/apps/provider-console/src/context/WalletProvider/WalletProvider.tsx index c25981176..bf0ab2a50 100644 --- a/apps/provider-console/src/context/WalletProvider/WalletProvider.tsx +++ b/apps/provider-console/src/context/WalletProvider/WalletProvider.tsx @@ -12,6 +12,7 @@ import { SnackbarKey, useSnackbar } from "notistack"; import { TransactionModal } from "@src/components/layout/TransactionModal"; import { browserEnvConfig } from "@src/config/browser-env.config"; import { useUsdcDenom } from "@src/hooks/useDenom"; +import { useLogger } from "@src/hooks/useLogger"; import { useSelectedNetwork } from "@src/hooks/useSelectedNetwork"; import { getSelectedNetwork } from "@src/hooks/useSelectedNetwork"; import authClient from "@src/utils/authClient"; @@ -66,6 +67,7 @@ export const WalletProvider = ({ children }) => { const sigingClient = useRef(null); const router = useRouter(); const usdcIbcDenom = useUsdcDenom(); + const logger = useLogger("apps/provider-console/src/context/WalletProvider/WalletProvider.tsx"); const { disconnect, getOfflineSigner, @@ -131,7 +133,7 @@ export const WalletProvider = ({ children }) => { setIsWalletProviderOnline(isOnlineResponse.online); } } catch (error) { - console.error("Error fetching provider status:", error); + logger.debug(`Error fetching provider status: ${error}`); } } @@ -265,7 +267,7 @@ export const WalletProvider = ({ children }) => { return true; } catch (err) { - console.error(err); + logger.debug(err); const transactionHash = err.txHash; let errorMsg = "An error has occured"; @@ -303,7 +305,7 @@ export const WalletProvider = ({ children }) => { errorMsg += `. ${log}`; } } catch (err) { - console.error(err); + logger.debug(err); } } diff --git a/apps/provider-console/src/hooks/useLocalStorage.ts b/apps/provider-console/src/hooks/useLocalStorage.ts index a43e8ed39..c124aa875 100644 --- a/apps/provider-console/src/hooks/useLocalStorage.ts +++ b/apps/provider-console/src/hooks/useLocalStorage.ts @@ -2,10 +2,11 @@ import { useEffect, useState } from "react"; import { useEventListener } from "usehooks-ts"; import { useWallet } from "@src/context/WalletProvider"; +import { useLogger } from "@src/hooks/useLogger"; export const useLocalStorage = () => { const { address } = useWallet(); - + const getLocalStorageItem = (key: string) => { const selectedNetworkId = localStorage.getItem("selectedNetworkId"); @@ -31,6 +32,7 @@ export const useLocalStorage = () => { }; export function useCustomLocalStorage(key: string, initialValue: T) { + const logger = useLogger("apps/provider-console/src/hooks/useLocalStorage.ts"); const readValue = () => { if (typeof window === "undefined") { return initialValue; @@ -40,7 +42,7 @@ export function useCustomLocalStorage(key: string, initialValue: T) { const item = window.localStorage.getItem(key); return item ? (parseJSON(item) as T) : initialValue; } catch (error) { - console.warn(`Error reading localStorage key “${key}”:`, error); + logger.debug(`Error reading localStorage key “${key}”: ${error}`); return initialValue; } }; @@ -49,7 +51,7 @@ export function useCustomLocalStorage(key: string, initialValue: T) { const setValue = (value: T | ((newValue: T) => T)) => { if (typeof window == "undefined") { - console.warn(`Tried setting localStorage key “${key}” even though environment is not a client`); + logger.debug(`Tried setting localStorage key “${key}” even though environment is not a client`); } try { @@ -58,7 +60,7 @@ export function useCustomLocalStorage(key: string, initialValue: T) { setStoredValue(newValue); window.dispatchEvent(new Event("local-storage")); } catch (error) { - console.warn(`Error setting localStorage key “${key}”:`, error); + logger.debug(`Error setting localStorage key “${key}”: ${error}`); } }; diff --git a/apps/provider-console/src/hooks/useLogger.ts b/apps/provider-console/src/hooks/useLogger.ts new file mode 100644 index 000000000..1e9bd0807 --- /dev/null +++ b/apps/provider-console/src/hooks/useLogger.ts @@ -0,0 +1,8 @@ +import "../config/logger.config"; + +import { useMemo } from "react"; +import { LoggerService } from "@akashnetwork/logging"; + +export const useLogger = (context: string) => { + return useMemo(() => LoggerService.forContext(context), [context]); +}; diff --git a/apps/provider-console/src/pages/pricing/index.tsx b/apps/provider-console/src/pages/pricing/index.tsx index 45ef05191..98e0f79da 100644 --- a/apps/provider-console/src/pages/pricing/index.tsx +++ b/apps/provider-console/src/pages/pricing/index.tsx @@ -5,6 +5,7 @@ import { ProviderPricing } from "@src/components/become-provider/ProviderPricing import { Layout } from "@src/components/layout/Layout"; import { useControlMachine } from "@src/context/ControlMachineProvider"; import { useProvider } from "@src/context/ProviderContext"; +import { useLogger } from "@src/hooks/useLogger"; import { ProviderPricingType } from "@src/types/provider"; import restClient from "@src/utils/restClient"; import { convertFromPricingAPI, sanitizeMachineAccess } from "@src/utils/sanityUtils"; @@ -14,6 +15,7 @@ const Pricing: React.FunctionComponent = () => { const [existingPricing, setExistingPricing] = useState(undefined); const [isLoading, setIsLoading] = useState(false); const { providerDetails } = useProvider(); + const logger = useLogger("apps/provider-console/src/pages/pricing/index.tsx"); const fetchPricing = async () => { try { @@ -26,7 +28,7 @@ const Pricing: React.FunctionComponent = () => { setExistingPricing(convertFromPricingAPI(response.pricing)); } } catch (error) { - console.error(error); + logger.debug(error); } finally { setIsLoading(false); } @@ -82,7 +84,6 @@ const Pricing: React.FunctionComponent = () => { {}} disabled={activeControlMachine && existingPricing ? false : true} providerDetails={providerDetails} /> diff --git a/apps/provider-console/src/store/networkStore.ts b/apps/provider-console/src/store/networkStore.ts index a9f4ded82..e1af64390 100644 --- a/apps/provider-console/src/store/networkStore.ts +++ b/apps/provider-console/src/store/networkStore.ts @@ -1,3 +1,4 @@ +import { LoggerService } from "@akashnetwork/logging"; import axios from "axios"; import { atom } from "jotai"; @@ -5,6 +6,8 @@ import { browserEnvConfig } from "@src/config/browser-env.config"; import { Network } from "@src/types/network"; import { mainnetId, } from "@src/utils/constants"; +const logger = LoggerService.forContext("apps/provider-console/src/store/networkStore.ts"); + export let networks: Network[] = [ { id: mainnetId, @@ -31,7 +34,7 @@ export const initiateNetworkData = async () => { const response = await axios.get(network.versionUrl, { timeout: 10000 }); version = response.data; } catch (error) { - console.log(error); + logger.debug(error); } return { diff --git a/apps/provider-console/src/utils/authClient.ts b/apps/provider-console/src/utils/authClient.ts index e7669c4c1..a8457a599 100644 --- a/apps/provider-console/src/utils/authClient.ts +++ b/apps/provider-console/src/utils/authClient.ts @@ -1,10 +1,13 @@ +import { LoggerService } from "@akashnetwork/logging"; import * as Sentry from "@sentry/nextjs"; import axios from "axios"; import { browserEnvConfig } from "@src/config/browser-env.config"; +const logger = LoggerService.forContext("apps/provider-console/src/utils/authClient.ts"); + const errorNotification = (error = "Error Occurred") => { - console.log(error); + logger.debug(error); }; const authClient = axios.create({ diff --git a/apps/provider-console/src/utils/consoleClient.ts b/apps/provider-console/src/utils/consoleClient.ts index bb0f03199..3c25e63e2 100644 --- a/apps/provider-console/src/utils/consoleClient.ts +++ b/apps/provider-console/src/utils/consoleClient.ts @@ -1,10 +1,13 @@ +import { LoggerService } from "@akashnetwork/logging"; import * as Sentry from "@sentry/nextjs"; import axios from "axios"; import { browserEnvConfig } from "@src/config/browser-env.config"; +const logger = LoggerService.forContext("apps/provider-console/src/utils/consoleClient.ts"); + const errorNotification = (error = "Error Occurred") => { - console.log(error); + logger.debug(error); }; const consoleClient = axios.create({ diff --git a/apps/provider-console/src/utils/restClient.ts b/apps/provider-console/src/utils/restClient.ts index d8b3b806f..cfba7d912 100644 --- a/apps/provider-console/src/utils/restClient.ts +++ b/apps/provider-console/src/utils/restClient.ts @@ -1,11 +1,14 @@ +import { LoggerService } from "@akashnetwork/logging"; import * as Sentry from "@sentry/nextjs"; import axios from "axios"; import { browserEnvConfig } from "@src/config/browser-env.config"; import { checkAndRefreshToken } from "./tokenUtils"; +const logger = LoggerService.forContext("apps/provider-console/src/utils/restClient.ts"); + const errorNotification = (error = "Error Occurred") => { - console.log(error); + logger.debug(error); }; const restClient = axios.create({ diff --git a/apps/provider-console/src/utils/tokenUtils.ts b/apps/provider-console/src/utils/tokenUtils.ts index 2b09f216c..bd0a3858a 100644 --- a/apps/provider-console/src/utils/tokenUtils.ts +++ b/apps/provider-console/src/utils/tokenUtils.ts @@ -1,7 +1,10 @@ +import { LoggerService } from "@akashnetwork/logging"; import { jwtDecode } from 'jwt-decode'; import authClient from './authClient'; +const logger = LoggerService.forContext("apps/provider-console/src/utils/tokenUtils.ts"); + interface DecodedToken { exp: number; } @@ -45,7 +48,7 @@ export async function checkAndRefreshToken(): Promise { throw new Error('Refresh token failed'); } } catch (error) { - console.error('Error checking or refreshing token:', error); + logger.debug(`Error checking or refreshing token: ${error}`); localStorage.removeItem('accessToken'); localStorage.removeItem('refreshToken'); localStorage.removeItem('walletAddress');