Skip to content

Commit d3e3c7d

Browse files
committed
Store the default chain key as a shareable const
1 parent 9cac4b2 commit d3e3c7d

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

src/components/ChainSelector.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react'
33
import { useSearchParams } from 'react-router-dom'
44
import styled from 'styled-components'
55
import { SimpleDropdown, SimpleListDropdownMenu } from '~/components/SimpleDropdown'
6+
import { defaultChainKey } from '~/consts'
67
import { getEnvironmentConfig } from '~/getters/getEnvironmentConfig'
78
import UnstyledNetworkIcon from '~/shared/components/NetworkIcon'
89
import SvgIcon from '~/shared/components/SvgIcon'
@@ -49,7 +50,7 @@ const Menu = ({ chains, selectedChain, toggle }: MenuProps) => {
4950
setSearchParams((prev) => {
5051
const { chain: _, ...rest } = Object.fromEntries(prev)
5152

52-
return chainName === 'polygon'
53+
return chainName === defaultChainKey
5354
? rest
5455
: { ...rest, chain: chainName }
5556
})

src/consts.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ChainKey } from '@streamr/config'
2+
13
export const MaxSearchPhraseLength = 250
24

35
export const address0 = '0x0000000000000000000000000000000000000000'
@@ -10,3 +12,5 @@ export const StreamGptApiUrl = process.env.STREAM_GPT_API_URL
1012
export const Minute = 60000
1113

1214
export const DayInSeconds = 86400
15+
16+
export const defaultChainKey: ChainKey = 'polygon'

src/getters/getEnvironmentConfig.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { z } from 'zod'
22
import config from '~/config/environments.toml'
3+
import { defaultChainKey } from '~/consts'
34
import { getChainConfig } from '~/utils/chains'
45

56
const EnvironmentConfig = z
@@ -37,7 +38,7 @@ const EnvironmentConfig = z
3738
type EnvironmentConfig = z.infer<typeof EnvironmentConfig>
3839

3940
const fallbackEnvironmentConfig: EnvironmentConfig = EnvironmentConfig.parse({
40-
availableChains: ['polygon'],
41+
availableChains: [defaultChainKey],
4142
})
4243

4344
const parsedConfig = z

src/utils/chains.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { produce } from 'immer'
33
import { useMemo } from 'react'
44
import { useSearchParams } from 'react-router-dom'
55
import { ethereumNetworks } from '~/shared/utils/constants'
6+
import { defaultChainKey } from '~/consts'
67
import {
78
ChainConfigExtension,
89
fallbackChainConfigExtension,
@@ -23,12 +24,12 @@ function getChainConfigWithFallback(chainName: string): Chain {
2324
return getChainConfig(chainName)
2425
} catch (_) {}
2526

26-
return getChainConfig('polygon')
27+
return getChainConfig(defaultChainKey)
2728
}
2829

2930
export function getCurrentChain() {
3031
return getChainConfigWithFallback(
31-
new URLSearchParams(window.location.search).get('chain') || 'polygon',
32+
new URLSearchParams(window.location.search).get('chain') || defaultChainKey,
3233
)
3334
}
3435

@@ -37,7 +38,7 @@ export function getCurrentChainId() {
3738
}
3839

3940
export function useCurrentChain() {
40-
const chainName = useSearchParams()[0].get('chain') || 'polygon'
41+
const chainName = useSearchParams()[0].get('chain') || defaultChainKey
4142

4243
return useMemo(() => getChainConfigWithFallback(chainName), [chainName])
4344
}

src/utils/routes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import queryString from 'query-string'
2+
import { defaultChainKey } from '~/consts'
23
import { getSymbolicChainName } from './chains'
34

45
interface RouteOptions {
@@ -27,7 +28,7 @@ function withSuffix<P extends string>(pathname: P, options: RouteOptions = {}) {
2728

2829
const qs = options.search
2930
? queryString.stringify(
30-
chain === 'polygon'
31+
chain === defaultChainKey
3132
? search
3233
: {
3334
...search,

0 commit comments

Comments
 (0)