Skip to content

Commit be38188

Browse files
authored
Merge pull request #1974 from streamr-dev/front-1978-update-streamrconfig-to-the-typed-version-v550-clean-up
FRONT-1978: Update `@streamr/config` to the "typed" version (v5.5.0) + clean up
2 parents 7fe3f30 + d3e3c7d commit be38188

File tree

12 files changed

+32
-53
lines changed

12 files changed

+32
-53
lines changed

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@metamask/providers": "^17.1.2",
4646
"@sambego/storybook-styles": "^1.0.0",
4747
"@sentry/react": "^8.34.0",
48-
"@streamr/config": "^5.4.0",
48+
"@streamr/config": "^5.5.0",
4949
"@streamr/hub-contracts": "^1.1.2",
5050
"@streamr/sdk": "^102.0.0",
5151
"@streamr/streamr-icons": "^0.1.9",

src/components/ChainSelector.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import { Chain } from '@streamr/config'
12
import React from 'react'
23
import { useSearchParams } from 'react-router-dom'
34
import styled from 'styled-components'
45
import { SimpleDropdown, SimpleListDropdownMenu } from '~/components/SimpleDropdown'
6+
import { defaultChainKey } from '~/consts'
57
import { getEnvironmentConfig } from '~/getters/getEnvironmentConfig'
68
import UnstyledNetworkIcon from '~/shared/components/NetworkIcon'
79
import SvgIcon from '~/shared/components/SvgIcon'
8-
import { getSymbolicChainName, useCurrentChain } from '~/utils/chains'
910
import { COLORS, LAPTOP } from '~/shared/utils/styled'
1011
import { StreamDraft } from '~/stores/streamDraft'
11-
import { Chain } from '~/types'
12+
import { getSymbolicChainName, useCurrentChain } from '~/utils/chains'
1213

1314
type MenuItemProps = {
1415
chain: Chain
@@ -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/getClientConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function getClientConfig(
1717
if (chainConfig.entryPoints && chainConfig.entryPoints.length > 0) {
1818
config.network = {
1919
controlLayer: {
20-
entryPoints: chainConfig.entryPoints,
20+
entryPoints: [...chainConfig.entryPoints],
2121
},
2222
}
2323
}

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/pages/ProjectPage/ProjectEditorPage.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Chain } from '@streamr/config'
12
import React, { useMemo } from 'react'
23
import { useNavigate } from 'react-router-dom'
34
import styled, { css } from 'styled-components'
@@ -21,18 +22,17 @@ import { deleteProject } from '~/services/projects'
2122
import { DetailsPageHeader } from '~/shared/components/DetailsPageHeader'
2223
import LoadingIndicator from '~/shared/components/LoadingIndicator'
2324
import useIsMounted from '~/shared/hooks/useIsMounted'
25+
import { ProjectType, SalePoint } from '~/shared/types'
26+
import { ProjectDraft } from '~/stores/projectDraft'
27+
import { SalePointsPayload } from '~/types/projects'
28+
import { formatChainName } from '~/utils'
2429
import {
2530
getChainConfig,
2631
getChainConfigExtension,
2732
useCurrentChainId,
2833
} from '~/utils/chains'
29-
import { ProjectType, SalePoint } from '~/shared/types'
30-
import { ProjectDraft } from '~/stores/projectDraft'
31-
import { Chain } from '~/types'
32-
import { SalePointsPayload } from '~/types/projects'
33-
import { formatChainName } from '~/utils'
34-
import { toastedOperation } from '~/utils/toastedOperation'
3534
import { Route as R, routeOptions } from '~/utils/routes'
35+
import { toastedOperation } from '~/utils/toastedOperation'
3636
import DataUnionFee from './DataUnionFee'
3737
import DataUnionPayment from './DataUnionPayment'
3838
import EditorHero from './EditorHero'

src/parsers/ProjectParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Chain } from '@streamr/config'
12
import { z } from 'zod'
23
import { address0 } from '~/consts'
34
import { getProjectImageUrl } from '~/getters'
@@ -9,7 +10,6 @@ import {
910
timeUnitSecondsMultiplierMap,
1011
timeUnits,
1112
} from '~/shared/utils/timeUnit'
12-
import { Chain } from '~/types'
1313
import { toBigInt } from '~/utils/bn'
1414
import {
1515
getChainConfig,

src/types/index.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { config as configs } from '@streamr/config'
21
import { MessageID } from '@streamr/sdk'
32
import { TheGraph } from '~/shared/types'
43

@@ -42,32 +41,6 @@ export type ChainConfigKey =
4241
| 'minimumDelegationWei'
4342
| 'earlyLeaverPenaltyWei'
4443

45-
type ContractAddressKey = typeof configs extends Record<
46-
any,
47-
Record<'contracts', Partial<Record<infer K, string>>>
48-
>
49-
? K
50-
: never
51-
52-
export interface Chain {
53-
name: string
54-
id: number
55-
theGraphUrl?: string
56-
rpcEndpoints: { url: string }[]
57-
contracts: Partial<Record<ContractAddressKey | (string & {}), string>>
58-
entryPoints?: {
59-
nodeId: string
60-
websocket: {
61-
host: string
62-
port: number
63-
tls: boolean
64-
}
65-
}[]
66-
nativeCurrency: { symbol: string; name: string; decimals: number }
67-
blockExplorerUrl?: string
68-
adminPrivateKey?: string
69-
}
70-
7144
export type OrderDirection = 'asc' | 'desc'
7245

7346
export interface DataPoint {

src/utils/chains.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { config as configs } from '@streamr/config'
1+
import { Chain, config as configs } from '@streamr/config'
22
import { produce } from 'immer'
33
import { useMemo } from 'react'
44
import { useSearchParams } from 'react-router-dom'
5+
import { ethereumNetworks } from '~/shared/utils/constants'
6+
import { defaultChainKey } from '~/consts'
57
import {
68
ChainConfigExtension,
79
fallbackChainConfigExtension,
810
parsedChainConfigExtension,
911
} from '~/utils/chainConfigExtension'
10-
import { Chain } from '~/types'
11-
import { ethereumNetworks } from '~/shared/utils/constants'
1212
import formatConfigUrl from './formatConfigUrl'
1313

1414
function getPreferredChainName(chainName: string) {
@@ -24,12 +24,12 @@ function getChainConfigWithFallback(chainName: string): Chain {
2424
return getChainConfig(chainName)
2525
} catch (_) {}
2626

27-
return getChainConfig('polygon')
27+
return getChainConfig(defaultChainKey)
2828
}
2929

3030
export function getCurrentChain() {
3131
return getChainConfigWithFallback(
32-
new URLSearchParams(window.location.search).get('chain') || 'polygon',
32+
new URLSearchParams(window.location.search).get('chain') || defaultChainKey,
3333
)
3434
}
3535

@@ -38,7 +38,7 @@ export function getCurrentChainId() {
3838
}
3939

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

4343
return useMemo(() => getChainConfigWithFallback(chainName), [chainName])
4444
}

0 commit comments

Comments
 (0)