Skip to content

Commit 60abc6d

Browse files
authored
Merge pull request #2016 from oasisprotocol/csillag/use-string-literals
Prefer string literals instead of enum constants
2 parents 9f5d27b + 51ef949 commit 60abc6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+355
-397
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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { describe, expect, it } from 'vitest'
22
import { screen } from '@testing-library/react'
33
import { renderWithProviders } from '../../../utils/__tests__/renderWithProviders.test'
4-
import { ShowMoreTokensLink } from './../ShowMoreTokensLink'
5-
import { Layer, EvmTokenType, RuntimeAccount, Token } from '../../../../oasis-nexus/api'
6-
import { Network } from '../../../../types/network'
4+
import { ShowMoreTokensLink } from '../ShowMoreTokensLink'
5+
import { EvmTokenType, RuntimeAccount, Token } from '../../../../oasis-nexus/api'
76

87
const mockedAccount = {
98
address: 'oasis1qrvha284gfztn7wwq6z50c86ceu28jp7csqhpx9t',
10-
layer: Layer.emerald,
11-
network: Network.mainnet,
9+
layer: 'emerald',
10+
network: 'mainnet',
1211
} as RuntimeAccount
1312

1413
const mockedToken1: Token = {

src/app/components/AnalyticsConsent/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import Link from '@mui/material/Link'
77
import { Trans, useTranslation } from 'react-i18next'
88
import * as matomo from './initializeMatomo'
99
import { ThemeByScope } from '../ThemeByScope'
10-
import { Network } from '../../../types/network'
1110
import { AnalyticsIsBlocked } from './AnalyticsIsBlocked'
1211
import { AnalyticsDialogLayout } from './AnalyticsDialogLayout'
1312

@@ -66,7 +65,7 @@ export const AnalyticsConsentProvider = (props: { children: React.ReactNode }) =
6665
>
6766
{props.children}
6867
{/* Theme is needed because AnalyticsConsentProvider is outside network-themed routes */}
69-
<ThemeByScope isRootTheme={false} network={Network.mainnet}>
68+
<ThemeByScope isRootTheme={false} network={'mainnet'}>
7069
<AnalyticsConsentView
7170
isOpen={hasAccepted === 'not-chosen'}
7271
onAccept={async () => {

src/app/components/ContractVerificationIcon/AbiPlaygroundLink.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ export const AbiPlaygroundLink: FC<{
1414
const { t } = useTranslation()
1515

1616
const scopeToPlaygroundURL: Record<Network, Partial<Record<Layer, string>>> = {
17-
[Network.mainnet]: {
18-
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42262&contractAddress=${address_eth}`,
19-
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23294&contractAddress=${address_eth}`,
17+
mainnet: {
18+
emerald: `${externalLinks.dapps.abiPlayground}?network=42262&contractAddress=${address_eth}`,
19+
sapphire: `${externalLinks.dapps.abiPlayground}?network=23294&contractAddress=${address_eth}`,
2020
},
21-
[Network.testnet]: {
22-
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42261&contractAddress=${address_eth}`,
23-
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23295&contractAddress=${address_eth}`,
21+
testnet: {
22+
emerald: `${externalLinks.dapps.abiPlayground}?network=42261&contractAddress=${address_eth}`,
23+
sapphire: `${externalLinks.dapps.abiPlayground}?network=23295&contractAddress=${address_eth}`,
2424
},
25-
[Network.localnet]: {
26-
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42260&contractAddress=${address_eth}`,
27-
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23293&contractAddress=${address_eth}`,
25+
localnet: {
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: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ type LayerDetailsContent = {
3434
type NetworkDetails = Partial<Record<Layer, LayerDetailsContent>>
3535
type Details = Record<Network, NetworkDetails>
3636
const getDetails = (t: TFunction): Details => ({
37-
[Network.mainnet]: {
38-
[Layer.emerald]: {
37+
mainnet: {
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',
@@ -52,32 +52,32 @@ const getDetails = (t: TFunction): Details => ({
5252
docs: docs.sapphire,
5353
},
5454
},
55-
[Network.testnet]: {
56-
[Layer.emerald]: {
55+
testnet: {
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',
@@ -86,13 +86,13 @@ const getDetails = (t: TFunction): Details => ({
8686
docs: docs.pontusx1,
8787
},
8888
},
89-
[Network.localnet]: {
90-
[Layer.sapphire]: {
89+
localnet: {
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/OfflineBanner/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { StickyAlert } from '../StickyAlert'
1010
export const NetworkOfflineBanner: FC<{ wantedNetwork?: Network }> = ({ wantedNetwork }) => {
1111
const scope = useScopeParam()
1212
const { t } = useTranslation()
13-
const targetNetwork = wantedNetwork || scope?.network || Network.mainnet
13+
const targetNetwork = wantedNetwork ?? scope?.network ?? 'mainnet'
1414
const isNetworkReachable = useIsApiReachable(targetNetwork)
1515
const networkNames = getNetworkNames(t)
1616
const target = networkNames[targetNetwork]

src/app/components/PageLayout/NetworkSelector.tsx

Lines changed: 2 additions & 2 deletions
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} />
@@ -88,7 +88,7 @@ const NetworkSelectorView: FC<NetworkSelectorViewProps> = ({ isOutOfDate, layer,
8888
{!isMobile && (
8989
<NetworkButton isOutOfDate={isOutOfDate} layer={layer} network={network} onClick={handleDrawerOpen} />
9090
)}
91-
{!fixedNetwork && !fixedLayer && !isTablet && network !== Network.mainnet && (
91+
{!fixedNetwork && !fixedLayer && !isTablet && network !== 'mainnet' && (
9292
<StyledBox>
9393
<Typography
9494
component="span"

src/app/components/PageLayout/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { useScopeParam } from '../../hooks/useScopeParam'
99
import { NetworkOfflineBanner, RuntimeOfflineBanner, ConsensusOfflineBanner } from '../OfflineBanner'
1010
import { Search } from '../Search'
1111
import { useIsApiReachable } from '../OfflineBanner/hook'
12-
import { Network } from '../../../types/network'
13-
import { Layer } from '../../../oasis-nexus/api'
1412

1513
interface PageLayoutProps {
1614
mobileFooterAction?: ReactNode
@@ -24,14 +22,14 @@ export const PageLayout: FC<PropsWithChildren<PageLayoutProps>> = ({ children, m
2422
const theme = useTheme()
2523
const { isMobile, isTablet } = useScreenSize()
2624
const scope = useScopeParam()
27-
const isApiReachable = useIsApiReachable(scope?.network || Network.mainnet).reachable
25+
const isApiReachable = useIsApiReachable(scope?.network ?? 'mainnet').reachable
2826

2927
return (
3028
<>
3129
<BuildBanner />
3230
<NetworkOfflineBanner />
33-
{scope && scope.layer !== Layer.consensus && <RuntimeOfflineBanner />}
34-
{scope && scope.layer === Layer.consensus && <ConsensusOfflineBanner />}
31+
{scope && scope.layer !== 'consensus' && <RuntimeOfflineBanner />}
32+
{scope && scope.layer === 'consensus' && <ConsensusOfflineBanner />}
3533
<Box
3634
sx={{
3735
minHeight: '100vh',

src/app/components/Search/SearchSuggestionsButtons.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +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'
15-
import { Network } from '../../../types/network'
1614

1715
const StyledPlainTextButton = styled(Button)({
1816
fontSize: 'inherit',
@@ -40,7 +38,7 @@ export const SearchSuggestionsButtons: FC<Props> = ({ scope, onClickSuggestion }
4038
const { t } = useTranslation()
4139
const { suggestedBlock, suggestedTransaction, suggestedAccount, suggestedTokenFragment } =
4240
(scope?.network && scope?.layer && searchSuggestionTerms[scope.network][scope.layer]) ??
43-
searchSuggestionTerms[Network.mainnet][Layer.sapphire]!
41+
searchSuggestionTerms.mainnet.sapphire!
4442
const defaultComponents = {
4543
OptionalBreak: <OptionalBreak />,
4644
BlockIcon: <WidgetsIcon sx={{ fontSize: '18px' }} />,
@@ -62,11 +60,11 @@ export const SearchSuggestionsButtons: FC<Props> = ({ scope, onClickSuggestion }
6260
<Trans
6361
t={t}
6462
i18nKey={
65-
scope?.layer === Layer.consensus
63+
scope?.layer === 'consensus'
6664
? 'search.searchSuggestionsForConsensus'
6765
: 'search.searchSuggestionsForRuntime'
6866
}
69-
components={scope?.layer === Layer.consensus ? defaultComponents : runtimeComponents}
67+
components={scope?.layer === 'consensus' ? defaultComponents : runtimeComponents}
7068
/>
7169
</Typography>
7270
</span>

0 commit comments

Comments
 (0)