From 202ed277529291c48227421a1ba9bd9dccfdf531 Mon Sep 17 00:00:00 2001 From: Michal Zielenkiewicz Date: Tue, 9 Jan 2024 10:54:01 +0100 Subject: [PATCH] Enable Consensus layer conditionally --- .changelog/1157.trivial.md | 1 + src/app/components/Search/search-utils.ts | 4 +-- .../LearningMaterials.tsx | 4 +-- src/app/utils/route-utils.ts | 25 ++++++++++++++----- src/config.ts | 3 +++ 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 .changelog/1157.trivial.md diff --git a/.changelog/1157.trivial.md b/.changelog/1157.trivial.md new file mode 100644 index 000000000..c7a4947e2 --- /dev/null +++ b/.changelog/1157.trivial.md @@ -0,0 +1 @@ +Enable Consensus layer conditionally diff --git a/src/app/components/Search/search-utils.ts b/src/app/components/Search/search-utils.ts index 6cf835f6c..3f95a9ea6 100644 --- a/src/app/components/Search/search-utils.ts +++ b/src/app/components/Search/search-utils.ts @@ -8,7 +8,7 @@ import { getEvmBech32Address, } from '../../utils/helpers' import { Network } from '../../../types/network' -import { RouteUtils, SpecifiedPerEnabledLayer } from '../../utils/route-utils' +import { RouteUtils, SpecifiedPerEnabledRuntime } from '../../utils/route-utils' import { AppError, AppErrors } from '../../../types/errors' import { Layer } from '../../../oasis-nexus/api' @@ -48,7 +48,7 @@ export const searchSuggestionTerms: Record ({ @@ -121,7 +121,7 @@ const getContent = (t: TFunction): Record => { }, }, }, - } satisfies SpecifiedPerEnabledLayer + } satisfies SpecifiedPerEnabledRuntime } type LearningSectionProps = PaperProps & { diff --git a/src/app/utils/route-utils.ts b/src/app/utils/route-utils.ts index dd38bcf08..5c7698838 100644 --- a/src/app/utils/route-utils.ts +++ b/src/app/utils/route-utils.ts @@ -5,15 +5,16 @@ import { AppError, AppErrors } from '../../types/errors' import { EvmTokenType, Layer } from '../../oasis-nexus/api' import { Network } from '../../types/network' import { SearchScope } from '../../types/searchScope' +import { isStableDeploy } from '../../config' -export type SpecifiedPerEnabledLayer = { - [N in keyof (typeof RouteUtils)['ENABLED_LAYERS_FOR_NETWORK']]: { - [L in keyof (typeof RouteUtils)['ENABLED_LAYERS_FOR_NETWORK'][N]]: T +export type SpecifiedPerEnabledRuntime = { + [N in keyof (typeof RouteUtils)['ENABLED_RUNTIMES_FOR_NETWORK']]: { + [L in keyof (typeof RouteUtils)['ENABLED_RUNTIMES_FOR_NETWORK'][N]]: T } } export abstract class RouteUtils { - private static ENABLED_LAYERS_FOR_NETWORK = { + private static ENABLED_RUNTIMES_FOR_NETWORK = { [Network.mainnet]: { [Layer.emerald]: true, [Layer.sapphire]: true, @@ -24,6 +25,12 @@ export abstract class RouteUtils { }, } satisfies Partial>>> + private static ENABLED_CONSENSUS_FOR_NETWORK = { + // Disable WIP Consensus on production an staging + [Network.mainnet]: !isStableDeploy, + [Network.testnet]: false, + } + static getDashboardRoute = ({ network, layer }: SearchScope) => { return `/${encodeURIComponent(network)}/${encodeURIComponent(layer)}` } @@ -101,7 +108,9 @@ export abstract class RouteUtils { )}/instance/${encodeURIComponent(instanceId)}` static getEnabledLayersForNetwork(network: Network): Layer[] { - return Object.keys(RouteUtils.ENABLED_LAYERS_FOR_NETWORK[network]) as Layer[] + const enabledRuntimes = Object.keys(RouteUtils.ENABLED_RUNTIMES_FOR_NETWORK[network]) as Layer[] + const enabledConsensus = RouteUtils.ENABLED_CONSENSUS_FOR_NETWORK[network] ? [Layer.consensus] : [] + return [...enabledRuntimes, ...enabledConsensus] } static getEnabledScopes(): SearchScope[] { @@ -111,7 +120,11 @@ export abstract class RouteUtils { } static getEnabledNetworks() { - return Object.keys(RouteUtils.ENABLED_LAYERS_FOR_NETWORK) as Network[] + const networks = new Set([ + ...Object.keys(RouteUtils.ENABLED_RUNTIMES_FOR_NETWORK), + ...Object.keys(RouteUtils.ENABLED_CONSENSUS_FOR_NETWORK), + ]) + return Array.from(networks) as Network[] } static getEnabledSearchScopes(): SearchScope[] { diff --git a/src/config.ts b/src/config.ts index c136c5d20..c6957cc3d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -123,3 +123,6 @@ export const deploys = { staging: 'https://explorer.stg.oasis.io', localhost: 'http://localhost:1234', } + +const stableDeploys = [...deploys.production, deploys.staging] +export const isStableDeploy = stableDeploys.some(url => window.location.origin === url)