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

Add Pontus-X as a hidden layer #1245

Merged
merged 4 commits into from
Feb 13, 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/1245.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Pontus-X as a hidden layer
3 changes: 2 additions & 1 deletion src/app/components/LayerPicker/LayerMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Layer } from '../../../oasis-nexus/api'
import { getLayerLabels } from '../../utils/content'
import { RouteUtils } from '../../utils/route-utils'
import { Network } from '../../../types/network'
import { orderByLayer } from '../../../types/layers'
import { isLayerHidden, orderByLayer } from '../../../types/layers'
import { useScreenSize } from '../../hooks/useScreensize'

type BaseLayerMenuItemProps = {
Expand Down Expand Up @@ -109,6 +109,7 @@ export const LayerMenu: FC<LayerMenuProps> = ({
}) => {
const [hoveredLayer, setHoveredLayer] = useState<undefined | Layer>()
const options = Object.values(Layer)
.filter(layer => !isLayerHidden(layer))
.map(layer => ({
layer,
enabled: RouteUtils.getEnabledLayersForNetwork(selectedNetwork || network).includes(layer),
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/Search/search-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const searchSuggestionTerms = {
suggestedTokenFragment: 'mock',
},
cipher: undefined,
pontusx: undefined,
consensus: undefined,
},
testnet: {
Expand All @@ -49,6 +50,13 @@ export const searchSuggestionTerms = {
suggestedTokenFragment: 'USD',
},
cipher: undefined,
pontusx: {
csillag marked this conversation as resolved.
Show resolved Hide resolved
// TODO: provide proper suggestions
suggestedBlock: '4260',
suggestedTransaction: '0xd9b5c08be1cb74229abedd9b3e1afb8b43228085a6abf72993db415959ab6b35',
suggestedAccount: '0xfA3AC9f65C9D75EE3978ab76c6a1105f03156204',
suggestedTokenFragment: 'USD',
},
consensus: undefined,
},
} satisfies SpecifiedPerEnabledLayer<LayerSuggestions>
Expand Down
4 changes: 4 additions & 0 deletions src/app/pages/HomePage/Graph/Graph/graph-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export abstract class GraphUtils {
x: 1.2 * width,
y: 0.7 * height,
}
case Layer.pontusx:
csillag marked this conversation as resolved.
Show resolved Hide resolved
// TODO: update this if/when we want to display this layer
// We meed this case here since this switch/case is declared to be exhaustive.
return initialValue
case Layer.sapphire:
return {
scale: 2.4,
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/HomePage/Graph/Graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ const GraphCmp: ForwardRefRenderFunction<SVGSVGElement, GraphProps> = (
return !RouteUtils.getEnabledLayersForNetwork(network).includes(Layer)
}

const disabledMap: Record<Layer, boolean> = {
const disabledMap: Partial<Record<Layer, boolean>> = {
[Layer.emerald]: isLayerDisabled(Layer.emerald),
[Layer.consensus]: isLayerDisabled(Layer.consensus),
[Layer.cipher]: isLayerDisabled(Layer.cipher),
Expand Down
6 changes: 4 additions & 2 deletions src/app/pages/HomePage/Graph/GraphTooltipMobile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const layerTooltipBodyCaption = (t: TFunction, layer: Layer, enabled: boolean, o
: t('common.paraTimeOnline')
}

const useLayerTooltipMap = (network: Network): Record<Layer, TooltipInfo> => {
const useLayerTooltipMap = (network: Network): Partial<Record<Layer, TooltipInfo>> => {
const isSapphireEnabled = RouteUtils.getEnabledLayersForNetwork(network).includes(Layer.sapphire)
const isEmeraldEnabled = RouteUtils.getEnabledLayersForNetwork(network).includes(Layer.emerald)
const isCipherEnabled = RouteUtils.getEnabledLayersForNetwork(network).includes(Layer.cipher)
Expand Down Expand Up @@ -270,7 +270,9 @@ export const GraphTooltipMobile: FC<GraphTooltipMobileProps> = ({ network, layer
const navigate = useNavigate()
const { t } = useTranslation()
const { isMobile } = useScreenSize()
const { body, disabled, failing } = useLayerTooltipMap(network)[layer]
const tooltip = useLayerTooltipMap(network)[layer]
if (!tooltip) return
const { body, disabled, failing } = tooltip

const navigateTo = () => {
if (disabled) {
Expand Down
4 changes: 3 additions & 1 deletion src/app/pages/ParatimeDashboardPage/LearningMaterials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const getContent = (t: TFunction) => {
},
},
[Layer.cipher]: undefined,
[Layer.pontusx]: undefined,
},
[Network.testnet]: {
[Layer.emerald]: {
Expand Down Expand Up @@ -99,8 +100,9 @@ const getContent = (t: TFunction) => {
},
},
[Layer.cipher]: undefined,
[Layer.pontusx]: undefined,
},
} satisfies SpecifiedPerEnabledRuntime<LayerContent>
} satisfies SpecifiedPerEnabledRuntime<LayerContent | undefined>
}

export const LearningMaterials: FC<{ scope: SearchScope }> = ({ scope }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/ParatimeDashboardPage/ParaTimeSnapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ChartDuration } from '../../utils/chart-utils'
import { useTranslation } from 'react-i18next'
import { useConstant } from '../../hooks/useConstant'
import { Network } from '../../../types/network'
import { getLayerNames } from '../../../types/layers'
import { getLayerLabels } from '../../utils/content'
import { TestnetFaucet } from './TestnetFaucet'
import { SearchScope } from '../../../types/searchScope'
import { Snapshot } from 'app/components/Snapshots/Snapshot'
Expand All @@ -23,7 +23,7 @@ export const ParaTimeSnapshot: FC<{ scope: SearchScope }> = ({ scope }) => {
const { t } = useTranslation()
const defaultChartDurationValue = useConstant<ChartDuration>(() => ChartDuration.TODAY)
const [chartDuration, setChartDuration] = useState<ChartDuration>(defaultChartDurationValue)
const paratime = getLayerNames(t)[scope.layer]
const paratime = getLayerLabels(t)[scope.layer]
const handleDurationSelectedChange = (duration: ChartDuration | null) => {
if (!duration) {
return
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/SearchResultsPage/GlobalSearchResultsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../../../types/network'
import { HideMoreResults, ShowMoreResults } from './notifications'
import { getThemesForNetworks } from '../../../styles/theme'
import { orderByLayer } from '../../../types/layers'
import { isNotOnHiddenLayer, orderByLayer } from '../../../types/layers'
import { useRedirectIfSingleResult } from './useRedirectIfSingleResult'

export const GlobalSearchResultsView: FC<{
Expand All @@ -33,7 +33,7 @@ export const GlobalSearchResultsView: FC<{
const otherNetworks = RouteUtils.getEnabledNetworks().filter(isNotMainnet)
const notificationTheme = themes[Network.testnet]
const mainnetResults = searchResults.filter(isOnMainnet).sort(orderByLayer)
const otherResults = searchResults.filter(isNotOnMainnet).sort(orderByLayer)
const otherResults = searchResults.filter(isNotOnMainnet).filter(isNotOnHiddenLayer).sort(orderByLayer)
csillag marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
Expand Down
3 changes: 2 additions & 1 deletion src/app/utils/__tests__/externalLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ onlyRunOnCI('externalLinks', () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const [_linkName, url] of Object.entries(linksGroup)) {
expect(typeof url).toBe('string')
expect(url).toMatch(/^https:/)
expect(url).toMatch(/^(https|mailto):/)
}
}
})
Expand All @@ -32,6 +32,7 @@ onlyRunOnCI('externalLinks', () => {
if (url.startsWith(externalLinksModule.github.commit)) continue // We store only partial url in constants
if (url.startsWith(externalLinksModule.github.releaseTag)) continue // We store only partial url in constants
if (url.startsWith(externalLinksModule.ipfs.proxyPrefix)) continue // We store only partial url in constants
if (url.startsWith('mailto')) continue // We can't test email addresses

it.concurrent(`${linksGroupName} ${linkName} ${url}`, async () => {
const response = await nodeFetch(url, { method: 'GET' })
Expand Down
1 change: 1 addition & 0 deletions src/app/utils/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const getLayerLabels = (t: TFunction): Record<Layer, string> => ({
[Layer.emerald]: t('common.emerald'),
[Layer.sapphire]: t('common.sapphire'),
[Layer.cipher]: t('common.cipher'),
[Layer.pontusx]: t('common.pontusx'),
[Layer.consensus]: t('common.consensus'),
})

Expand Down
1 change: 1 addition & 0 deletions src/app/utils/externalLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const faucet = {
[Layer.consensus]: faucetUrl,
[Layer.emerald]: `${faucetParaTimeBaseUrl}emerald`,
[Layer.sapphire]: `${faucetParaTimeBaseUrl}sapphire`,
[Layer.pontusx]: 'mailto:[email protected]?subject=tokens',
csillag marked this conversation as resolved.
Show resolved Hide resolved
[Layer.cipher]: `${faucetParaTimeBaseUrl}cipher`,
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/utils/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export abstract class RouteUtils {
[Layer.emerald]: true,
[Layer.sapphire]: true,
[Layer.cipher]: false,
[Layer.pontusx]: false,
// Disable WIP Consensus on production an staging
[Layer.consensus]: !isStableDeploy,
},
[Network.testnet]: {
[Layer.emerald]: true,
[Layer.sapphire]: true,
[Layer.cipher]: false,
[Layer.pontusx]: true,
[Layer.consensus]: false,
},
} satisfies Record<Network, Record<Layer, boolean>>
Expand Down
1 change: 1 addition & 0 deletions src/app/utils/rpc-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const LAYER_DECIMALS: Record<Layer, number> = {
[Layer.emerald]: paraTimesConfig[Layer.emerald].decimals,
[Layer.sapphire]: paraTimesConfig[Layer.sapphire].decimals,
[Layer.cipher]: paraTimesConfig[Layer.cipher].decimals,
[Layer.pontusx]: paraTimesConfig[Layer.pontusx].decimals,
[Layer.consensus]: consensusDecimals,
}

Expand Down
27 changes: 27 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,32 @@ const sapphireConfig: LayerConfig = {
outOfDateThreshold: 2 * 60 * 1000,
}

const pontusxConfig: LayerConfig = {
mainnet: {
activeNodes: undefined,
address: undefined,
blockGasLimit: undefined,
runtimeId: undefined,
},
testnet: {
activeNodes: 8, // TODO use correct number
address: 'oasis1qqczuf3x6glkgjuf0xgtcpjjw95r3crf7y2323xd', // TODO use correct address
// See max_batch_gas https://github.com/oasisprotocol/sapphire-paratime/blob/main/runtime/src/lib.rs#L166
blockGasLimit: 15_000_000,
runtimeId: '000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c',
csillag marked this conversation as resolved.
Show resolved Hide resolved
},
local: {
activeNodes: undefined,
address: undefined,
blockGasLimit: undefined,
runtimeId: undefined,
},

decimals: 18,
type: RuntimeTypes.Evm,
outOfDateThreshold: 2 * 60 * 1000,
}

type LayersConfig = {
[key in Layer]: LayerConfig | null
}
Expand All @@ -116,6 +142,7 @@ export const paraTimesConfig = {
[Layer.cipher]: cipherConfig,
[Layer.emerald]: emeraldConfig,
[Layer.sapphire]: sapphireConfig,
[Layer.pontusx]: pontusxConfig,
[Layer.consensus]: null,
} satisfies LayersConfig

Expand Down
2 changes: 2 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"paratime": "Paratime",
"parentheses": "({{subject}})",
"percentage": "Percentage",
"pontusx": "Pontus-X",
"proposal": "Proposal",
"proposer": "Proposer",
"rank": "Rank",
Expand Down Expand Up @@ -472,6 +473,7 @@
"sapphireParaTimeDesc": "Confidential EVM Compatible ParaTime providing a smart contract development environment with EVM compatibility",
"emeraldParaTimeDesc": "EVM Compatible ParaTime providing smart contract environment with EVM compatibility.",
"cipherParaTimeDesc": "The Cipher ParaTime is a Confidential ParaTime for executing Wasm smart contracts.",
"pontusxParaTimeDesc": "Pontus-X ParaTime",
"consensusDesc": "Our scalable, high-throughput, secure, proof-of-stake consensus layer run by a decentralized set of validator nodes.",
"close": "Close"
},
Expand Down
9 changes: 9 additions & 0 deletions src/oasis-nexus/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ function arrayify<T>(arrayOrItem: null | undefined | T | T[]): T[] {
return arrayOrItem
}

// TODO: remove when pontusx API is ready
axios.interceptors.request.use(config => {
// Mock pontusx
if (config.url?.includes('/v1/pontusx')) {
config.url = config.url.replace('/v1/pontusx', '/v1/sapphire')
}
return config
})

export const useGetConsensusTransactions: typeof generated.useGetConsensusTransactions = (
network,
params?,
Expand Down
2 changes: 2 additions & 0 deletions src/oasis-nexus/generated/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions src/types/layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { uniq } from '../app/utils/helpers'
// a cycle of imports which confuse jest
// eslint-disable-next-line no-restricted-imports
import { Layer } from '../oasis-nexus/generated/api'
import { TFunction } from 'i18next'

export const getLayerNames = (t: TFunction): Record<Layer, string> => ({
[Layer.emerald]: t('common.emerald'),
[Layer.sapphire]: t('common.sapphire'),
[Layer.cipher]: t('common.cipher'),
[Layer.consensus]: t('common.consensus'),
})

interface HasLayer {
layer: Layer
Expand All @@ -24,8 +16,11 @@ const layerOrder: Record<Layer, number> = {
[Layer.sapphire]: 2,
[Layer.emerald]: 3,
[Layer.cipher]: 4,
[Layer.pontusx]: 5,
}

const hiddenLayers: Layer[] = [Layer.pontusx]
csillag marked this conversation as resolved.
Show resolved Hide resolved

export const orderByLayer = (itemA: HasLayer, itemB: HasLayer): number =>
layerOrder[itemA.layer] - layerOrder[itemB.layer]

Expand All @@ -36,3 +31,7 @@ export const doesLayerSupportEncryptedTransactions = (layer: Layer): boolean =>

export const doesAnyOfTheseLayersSupportEncryptedTransactions = (layers: Layer[] | undefined): boolean =>
uniq(layers).some(doesLayerSupportEncryptedTransactions)

export const isLayerHidden = (layer: Layer): boolean => hiddenLayers.includes(layer)

export const isNotOnHiddenLayer = (item: HasLayer) => !isLayerHidden(item.layer)
4 changes: 2 additions & 2 deletions src/types/searchScope.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getNetworkNames, Network } from './network'
import { getLayerNames } from './layers'
import { getLayerLabels } from '../app/utils/content'
import { HasScope, Layer } from '../oasis-nexus/api'
import { TFunction } from 'i18next'

Expand All @@ -14,7 +14,7 @@ export const MainnetEmerald: SearchScope = {
}

export const getNameForScope = (t: TFunction, scope: SearchScope) =>
`${getLayerNames(t)[scope.layer]} ${getNetworkNames(t)[scope.network]}`
`${getLayerLabels(t)[scope.layer]} ${getNetworkNames(t)[scope.network]}`

export const getKeyForScope: (scope: SearchScope) => string = ({ network, layer }) => `${network}.${layer}`

Expand Down
Loading