Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Consensus layer conditionally #1157

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 19 additions & 6 deletions src/app/utils/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T = any> = {
[N in keyof (typeof RouteUtils)['ENABLED_LAYERS_FOR_NETWORK']]: {
[L in keyof (typeof RouteUtils)['ENABLED_LAYERS_FOR_NETWORK'][N]]: T
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 +25,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]: !isStableDeploy,
[Network.testnet]: false,
}

static getDashboardRoute = ({ network, layer }: SearchScope) => {
return `/${encodeURIComponent(network)}/${encodeURIComponent(layer)}`
}
Expand Down Expand Up @@ -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[] {
Expand All @@ -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[] {
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading