Skip to content

Commit

Permalink
Enable Consensus layer conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Jan 17, 2024
1 parent cb01ae1 commit 7077ff6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions .changelog/1157.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable Consensus layer conditionally
4 changes: 2 additions & 2 deletions src/app/components/Search/search-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -48,7 +48,7 @@ export const searchSuggestionTerms: Record<Network, Partial<Record<Layer, LayerS
suggestedTokenFragment: 'USD',
},
},
} satisfies SpecifiedPerEnabledLayer
} satisfies SpecifiedPerEnabledRuntime

export const textSearchMininumLength = 3

Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/ParatimeDashboardPage/LearningMaterials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { docs } from '../../utils/externalLinks'
import { Layer } from '../../../oasis-nexus/api'
import { getLayerLabels } from '../../utils/content'
import { Network } from '../../../types/network'
import { SpecifiedPerEnabledLayer } from '../../utils/route-utils'
import { SpecifiedPerEnabledRuntime } from '../../utils/route-utils'
import { SearchScope } from '../../../types/searchScope'

const StyledLink = styled(Link)(() => ({
Expand Down Expand Up @@ -121,7 +121,7 @@ const getContent = (t: TFunction): Record<Network, NetworkContent> => {
},
},
},
} satisfies SpecifiedPerEnabledLayer
} satisfies SpecifiedPerEnabledRuntime
}

type LearningSectionProps = PaperProps & {
Expand Down
27 changes: 21 additions & 6 deletions src/app/utils/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { AppError, AppErrors } from '../../types/errors'
import { EvmTokenType, Layer } from '../../oasis-nexus/api'
import { Network } from '../../types/network'
import { SearchScope } from '../../types/searchScope'
import { stableDeploys } from '../../config'

export type SpecifiedPerEnabledLayer<T = any> = {
[N in keyof (typeof RouteUtils)['ENABLED_LAYERS_FOR_NETWORK']]: {
[L in keyof (typeof RouteUtils)['ENABLED_LAYERS_FOR_NETWORK'][N]]: T
export const isProduction = stableDeploys.some(url => window.location.origin === url)

export type SpecifiedPerEnabledRuntime<T = any> = {
[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,
Expand All @@ -24,6 +27,12 @@ export abstract class RouteUtils {
},
} satisfies Partial<Record<Network, Partial<Record<Layer, true>>>>

private static ENABLED_CONSENSUS_FOR_NETWORK = {
// Disable WIP Consensus on production an staging
[Network.mainnet]: !isProduction,
[Network.testnet]: false,
}

static getDashboardRoute = ({ network, layer }: SearchScope) => {
return `/${encodeURIComponent(network)}/${encodeURIComponent(layer)}`
}
Expand Down Expand Up @@ -101,7 +110,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[] {
Expand All @@ -111,7 +122,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[] {
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,5 @@ export const deploys = {
staging: 'https://explorer.stg.oasis.io',
localhost: 'http://localhost:1234',
}

export const stableDeploys = [...deploys.production, deploys.staging]

0 comments on commit 7077ff6

Please sign in to comment.