Skip to content

Commit e43e2b0

Browse files
committed
Get rid of Layer constants
1 parent 9f5d27b commit e43e2b0

37 files changed

+281
-300
lines changed

.changelog/2016.internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prefer string literals instead of constants

src/app/components/Account/ConsensusAccountLink.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FC } from 'react'
2-
import { Layer, useGetConsensusValidatorsAddressNameMap } from './../../../oasis-nexus/api'
2+
import { useGetConsensusValidatorsAddressNameMap } from './../../../oasis-nexus/api'
33
import { Network } from '../../../types/network'
44
import { ValidatorLink } from '../Validators/ValidatorLink'
55
import { AccountLink } from './AccountLink'
@@ -36,7 +36,7 @@ export const ConsensusAccountLink: FC<ConsensusAccountLinkProps> = ({
3636
return (
3737
<AccountLink
3838
labelOnly={labelOnly}
39-
scope={{ network, layer: Layer.consensus }}
39+
scope={{ network, layer: 'consensus' }}
4040
address={address}
4141
alwaysTrim={alwaysTrim}
4242
highlightPattern={highlightPattern}

src/app/components/Account/__tests__/ShowMoreTokensLink.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Network } from '../../../../types/network'
77

88
const mockedAccount = {
99
address: 'oasis1qrvha284gfztn7wwq6z50c86ceu28jp7csqhpx9t',
10-
layer: Layer.emerald,
10+
layer: 'emerald',
1111
network: Network.mainnet,
1212
} as RuntimeAccount
1313

src/app/components/ContractVerificationIcon/AbiPlaygroundLink.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ export const AbiPlaygroundLink: FC<{
1515

1616
const scopeToPlaygroundURL: Record<Network, Partial<Record<Layer, string>>> = {
1717
[Network.mainnet]: {
18-
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42262&contractAddress=${address_eth}`,
19-
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23294&contractAddress=${address_eth}`,
18+
emerald: `${externalLinks.dapps.abiPlayground}?network=42262&contractAddress=${address_eth}`,
19+
sapphire: `${externalLinks.dapps.abiPlayground}?network=23294&contractAddress=${address_eth}`,
2020
},
2121
[Network.testnet]: {
22-
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42261&contractAddress=${address_eth}`,
23-
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23295&contractAddress=${address_eth}`,
22+
emerald: `${externalLinks.dapps.abiPlayground}?network=42261&contractAddress=${address_eth}`,
23+
sapphire: `${externalLinks.dapps.abiPlayground}?network=23295&contractAddress=${address_eth}`,
2424
},
2525
[Network.localnet]: {
26-
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42260&contractAddress=${address_eth}`,
27-
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23293&contractAddress=${address_eth}`,
26+
emerald: `${externalLinks.dapps.abiPlayground}?network=42260&contractAddress=${address_eth}`,
27+
sapphire: `${externalLinks.dapps.abiPlayground}?network=23293&contractAddress=${address_eth}`,
2828
},
2929
}
3030
const abiPlaygroundLinkProps = {

src/app/components/LayerPicker/LayerDetails.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ type NetworkDetails = Partial<Record<Layer, LayerDetailsContent>>
3535
type Details = Record<Network, NetworkDetails>
3636
const getDetails = (t: TFunction): Details => ({
3737
[Network.mainnet]: {
38-
[Layer.emerald]: {
38+
emerald: {
3939
description: t('layerPicker.mainnet.emerald'),
4040
rpcHttp: 'https://emerald.oasis.io',
4141
rpcWebSockets: 'wss://emerald.oasis.io/ws',
4242
chainHexId: '0xa516',
4343
chainDecimalId: '42262',
4444
docs: docs.emerald,
4545
},
46-
[Layer.sapphire]: {
46+
sapphire: {
4747
description: t('layerPicker.mainnet.sapphire'),
4848
rpcHttp: 'https://sapphire.oasis.io',
4949
rpcWebSockets: 'wss://sapphire.oasis.io/ws',
@@ -53,31 +53,31 @@ const getDetails = (t: TFunction): Details => ({
5353
},
5454
},
5555
[Network.testnet]: {
56-
[Layer.emerald]: {
56+
emerald: {
5757
description: t('layerPicker.testnet.emerald'),
5858
rpcHttp: 'https://testnet.emerald.oasis.io',
5959
rpcWebSockets: 'wss://testnet.emerald.oasis.io/ws',
6060
chainHexId: '0xa515',
6161
chainDecimalId: '42261',
6262
docs: docs.emerald,
6363
},
64-
[Layer.sapphire]: {
64+
sapphire: {
6565
description: t('layerPicker.testnet.sapphire'),
6666
rpcHttp: 'https://testnet.sapphire.oasis.io',
6767
rpcWebSockets: 'wss://testnet.sapphire.oasis.io/ws',
6868
chainHexId: '0x5aff',
6969
chainDecimalId: '23295',
7070
docs: docs.sapphire,
7171
},
72-
[Layer.pontusxdev]: {
72+
pontusxdev: {
7373
description: t('layerPicker.testnet.pontusxdev'),
7474
// See https://docs.pontus-x.eu/docs/Pontus-X%20Testnet/quick_start#setup-metamask
7575
rpcHttp: 'https://rpc.dev.pontus-x.eu',
7676
chainHexId: '0x7ec8',
7777
chainDecimalId: '32456',
7878
docs: docs.pontusx1,
7979
},
80-
[Layer.pontusxtest]: {
80+
pontusxtest: {
8181
description: t('layerPicker.testnet.pontusxtest'),
8282
// See https://docs.pontus-x.eu/docs/Pontus-X%20Testnet/quick_start#setup-metamask
8383
rpcHttp: 'https://rpc.test.pontus-x.eu',
@@ -87,12 +87,12 @@ const getDetails = (t: TFunction): Details => ({
8787
},
8888
},
8989
[Network.localnet]: {
90-
[Layer.sapphire]: {
90+
sapphire: {
9191
chainHexId: '0x5afd',
9292
chainDecimalId: '23293',
9393
description: t('layerPicker.localnet.sapphire'),
9494
},
95-
[Layer.emerald]: {
95+
emerald: {
9696
chainHexId: '0xa514',
9797
chainDecimalId: '42260',
9898
description: t('layerPicker.localnet.emerald'),
@@ -127,7 +127,7 @@ export const LayerDetails: FC<LayerDetailsProps> = ({
127127
selectedScope: { network, layer },
128128
...rest
129129
}: LayerDetailsProps) =>
130-
layer === Layer.consensus ? (
130+
layer === 'consensus' ? (
131131
<ConsensusDetails selectedScope={{ network, layer }} {...rest} />
132132
) : (
133133
<RuntimeDetails selectedScope={{ network, layer }} {...rest} />

src/app/components/PageLayout/NetworkSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type NetworkSelectorProps = {
3434
}
3535

3636
export const NetworkSelector: FC<NetworkSelectorProps> = ({ network, layer }) => {
37-
return layer === Layer.consensus ? (
37+
return layer === 'consensus' ? (
3838
<ConsensusNetworkSelector network={network} layer={layer} />
3939
) : (
4040
<RuntimeNetworkSelector network={network} layer={layer} />

src/app/components/PageLayout/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { NetworkOfflineBanner, RuntimeOfflineBanner, ConsensusOfflineBanner } fr
1010
import { Search } from '../Search'
1111
import { useIsApiReachable } from '../OfflineBanner/hook'
1212
import { Network } from '../../../types/network'
13-
import { Layer } from '../../../oasis-nexus/api'
1413

1514
interface PageLayoutProps {
1615
mobileFooterAction?: ReactNode
@@ -30,8 +29,8 @@ export const PageLayout: FC<PropsWithChildren<PageLayoutProps>> = ({ children, m
3029
<>
3130
<BuildBanner />
3231
<NetworkOfflineBanner />
33-
{scope && scope.layer !== Layer.consensus && <RuntimeOfflineBanner />}
34-
{scope && scope.layer === Layer.consensus && <ConsensusOfflineBanner />}
32+
{scope && scope.layer !== 'consensus' && <RuntimeOfflineBanner />}
33+
{scope && scope.layer === 'consensus' && <ConsensusOfflineBanner />}
3534
<Box
3635
sx={{
3736
minHeight: '100vh',

src/app/components/Search/SearchSuggestionsButtons.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import TokenIcon from '@mui/icons-material/Token'
1111
import { searchSuggestionTerms } from './search-utils'
1212
import { OptionalBreak } from '../OptionalBreak'
1313
import { SearchScope } from '../../../types/searchScope'
14-
import { Layer } from '../../../oasis-nexus/api'
1514
import { Network } from '../../../types/network'
1615

1716
const StyledPlainTextButton = styled(Button)({
@@ -40,7 +39,7 @@ export const SearchSuggestionsButtons: FC<Props> = ({ scope, onClickSuggestion }
4039
const { t } = useTranslation()
4140
const { suggestedBlock, suggestedTransaction, suggestedAccount, suggestedTokenFragment } =
4241
(scope?.network && scope?.layer && searchSuggestionTerms[scope.network][scope.layer]) ??
43-
searchSuggestionTerms[Network.mainnet][Layer.sapphire]!
42+
searchSuggestionTerms[Network.mainnet]['sapphire']!
4443
const defaultComponents = {
4544
OptionalBreak: <OptionalBreak />,
4645
BlockIcon: <WidgetsIcon sx={{ fontSize: '18px' }} />,
@@ -62,11 +61,11 @@ export const SearchSuggestionsButtons: FC<Props> = ({ scope, onClickSuggestion }
6261
<Trans
6362
t={t}
6463
i18nKey={
65-
scope?.layer === Layer.consensus
64+
scope?.layer === 'consensus'
6665
? 'search.searchSuggestionsForConsensus'
6766
: 'search.searchSuggestionsForRuntime'
6867
}
69-
components={scope?.layer === Layer.consensus ? defaultComponents : runtimeComponents}
68+
components={scope?.layer === 'consensus' ? defaultComponents : runtimeComponents}
7069
/>
7170
</Typography>
7271
</span>

src/app/components/Search/SearchSuggestionsLinksForNoResults.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { OptionalBreak } from '../OptionalBreak'
1212
import { SearchScope } from '../../../types/searchScope'
1313
import { useScreenSize } from '../../hooks/useScreensize'
1414
import { SxProps } from '@mui/material/styles'
15-
import { Layer } from '../../../oasis-nexus/api'
1615
import { Network } from '../../../types/network'
1716

1817
interface Props {
@@ -32,7 +31,7 @@ export const SearchSuggestionsLinksForNoResults: FC<Props> = ({ scope }) => {
3231
const { isMobile } = useScreenSize()
3332
const { suggestedBlock, suggestedTransaction, suggestedAccount, suggestedTokenFragment } =
3433
(scope?.network && scope?.layer && searchSuggestionTerms[scope.network][scope.layer]) ??
35-
searchSuggestionTerms[Network.mainnet][Layer.sapphire]!
34+
searchSuggestionTerms[Network.mainnet].sapphire!
3635
const defaultComponents = {
3736
OptionalBreak: <OptionalBreak />,
3837
BlockIcon: isMobile ? empty : <WidgetsIcon sx={iconSxProps} />,
@@ -54,11 +53,11 @@ export const SearchSuggestionsLinksForNoResults: FC<Props> = ({ scope }) => {
5453
<Trans
5554
t={t}
5655
i18nKey={
57-
scope?.layer === Layer.consensus
56+
scope?.layer === 'consensus'
5857
? 'search.searchSuggestionsForNoResultsForConsensus'
5958
: 'search.searchSuggestionsForNoResultsForRuntime'
6059
}
61-
components={scope?.layer === Layer.consensus ? defaultComponents : runtimeComponents}
60+
components={scope?.layer === 'consensus' ? defaultComponents : runtimeComponents}
6261
/>
6362
)
6463
}

src/app/components/Validators/DeferredValidatorLink.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FC } from 'react'
22
import { Network } from '../../../types/network'
3-
import { Layer, Validator } from '../../../oasis-nexus/api'
3+
import { Validator } from '../../../oasis-nexus/api'
44
import { SearchScope } from '../../../types/searchScope'
55
import { ValidatorLink } from './ValidatorLink'
66
import { HighlightPattern } from '../HighlightedText'
@@ -12,7 +12,7 @@ export const DeferredValidatorLink: FC<{
1212
isError: boolean
1313
highlightPattern?: HighlightPattern
1414
}> = ({ network, address, validator, isError, highlightPattern }) => {
15-
const scope: SearchScope = { network, layer: Layer.consensus }
15+
const scope: SearchScope = { network, layer: 'consensus' }
1616

1717
if (isError) {
1818
console.log('Warning: failed to look up validators!')

0 commit comments

Comments
 (0)