-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): replace network management with network store package
- Loading branch information
1 parent
c3e761e
commit 3d804d5
Showing
20 changed files
with
116 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
# production | ||
/build | ||
env-config.schema.js | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NEXT_PUBLIC_API_BASE_URL=https://console-api.akash.network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NEXT_PUBLIC_API_BASE_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NEXT_PUBLIC_API_BASE_URL=https://console-api-mainnet-staging.akash.network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { validateStaticEnvVars } from "./env-config.schema"; | ||
|
||
export const browserEnvConfig = validateStaticEnvVars({ | ||
NEXT_PUBLIC_DEFAULT_NETWORK_ID: process.env.NEXT_PUBLIC_DEFAULT_NETWORK_ID, | ||
NEXT_PUBLIC_API_BASE_URL: process.env.NEXT_PUBLIC_API_BASE_URL | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { z } from "zod"; | ||
|
||
const networkId = z.enum(["mainnet", "sandbox", "testnet"]); | ||
const coercedBoolean = () => z.enum(["true", "false"]).transform(val => val === "true"); | ||
|
||
export const browserEnvSchema = z.object({ | ||
NEXT_PUBLIC_DEFAULT_NETWORK_ID: networkId.optional().default("mainnet"), | ||
NEXT_PUBLIC_API_BASE_URL: z.string().url() | ||
}); | ||
|
||
export const serverEnvSchema = browserEnvSchema.extend({ | ||
MAINTENANCE_MODE: coercedBoolean().optional().default("false"), | ||
BASE_API_MAINNET_URL: z.string().url(), | ||
BASE_API_TESTNET_URL: z.string().url(), | ||
BASE_API_SANDBOX_URL: z.string().url() | ||
}); | ||
|
||
export type BrowserEnvConfig = z.infer<typeof browserEnvSchema>; | ||
export type ServerEnvConfig = z.infer<typeof serverEnvSchema>; | ||
|
||
export const validateStaticEnvVars = (config: Record<string, unknown>) => browserEnvSchema.parse(config); | ||
export const validateRuntimeEnvVars = (config: Record<string, unknown>) => { | ||
if (process.env.NEXT_PHASE === "phase-production-build") { | ||
console.log("Skipping validation of serverEnvConfig during build"); | ||
return config as ServerEnvConfig; | ||
} else { | ||
return serverEnvSchema.parse(config); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import "@akashnetwork/env-loader"; | ||
|
||
import { validateRuntimeEnvVars } from "./env-config.schema"; | ||
|
||
export const serverEnvConfig = validateRuntimeEnvVars(process.env); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { useSelectedNetwork } from "./useSelectedNetwork"; | ||
|
||
import { USDC_IBC_DENOMS } from "@/config/denom.config"; | ||
import { networkStore } from "@/store/network.store"; | ||
|
||
export const useUsdcDenom = () => { | ||
const selectedNetwork = useSelectedNetwork(); | ||
return USDC_IBC_DENOMS[selectedNetwork.id]; | ||
const selectedNetworkId = networkStore.useSelectedNetworkId(); | ||
return USDC_IBC_DENOMS[selectedNetworkId]; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createStore } from "jotai"; | ||
|
||
export const store = createStore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NetworkStore } from "@akashnetwork/network-store"; | ||
|
||
import { browserEnvConfig } from "@/config/browser-env.config"; | ||
import { store } from "@/store/global.store"; | ||
|
||
export const networkStore = NetworkStore.create({ | ||
defaultNetworkId: browserEnvConfig.NEXT_PUBLIC_DEFAULT_NETWORK_ID, | ||
apiBaseUrl: browserEnvConfig.NEXT_PUBLIC_API_BASE_URL, | ||
store | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.