Skip to content

Commit

Permalink
Merge pull request #1974 from streamr-dev/front-1978-update-streamrco…
Browse files Browse the repository at this point in the history
…nfig-to-the-typed-version-v550-clean-up

FRONT-1978: Update `@streamr/config` to the "typed" version (v5.5.0) + clean up
  • Loading branch information
mondoreale authored Feb 11, 2025
2 parents 7fe3f30 + d3e3c7d commit be38188
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 53 deletions.
9 changes: 5 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@metamask/providers": "^17.1.2",
"@sambego/storybook-styles": "^1.0.0",
"@sentry/react": "^8.34.0",
"@streamr/config": "^5.4.0",
"@streamr/config": "^5.5.0",
"@streamr/hub-contracts": "^1.1.2",
"@streamr/sdk": "^102.0.0",
"@streamr/streamr-icons": "^0.1.9",
Expand Down
7 changes: 4 additions & 3 deletions src/components/ChainSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Chain } from '@streamr/config'
import React from 'react'
import { useSearchParams } from 'react-router-dom'
import styled from 'styled-components'
import { SimpleDropdown, SimpleListDropdownMenu } from '~/components/SimpleDropdown'
import { defaultChainKey } from '~/consts'
import { getEnvironmentConfig } from '~/getters/getEnvironmentConfig'
import UnstyledNetworkIcon from '~/shared/components/NetworkIcon'
import SvgIcon from '~/shared/components/SvgIcon'
import { getSymbolicChainName, useCurrentChain } from '~/utils/chains'
import { COLORS, LAPTOP } from '~/shared/utils/styled'
import { StreamDraft } from '~/stores/streamDraft'
import { Chain } from '~/types'
import { getSymbolicChainName, useCurrentChain } from '~/utils/chains'

type MenuItemProps = {
chain: Chain
Expand Down Expand Up @@ -49,7 +50,7 @@ const Menu = ({ chains, selectedChain, toggle }: MenuProps) => {
setSearchParams((prev) => {
const { chain: _, ...rest } = Object.fromEntries(prev)

return chainName === 'polygon'
return chainName === defaultChainKey
? rest
: { ...rest, chain: chainName }
})
Expand Down
4 changes: 4 additions & 0 deletions src/consts.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ChainKey } from '@streamr/config'

export const MaxSearchPhraseLength = 250

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

export const DayInSeconds = 86400

export const defaultChainKey: ChainKey = 'polygon'
2 changes: 1 addition & 1 deletion src/getters/getClientConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function getClientConfig(
if (chainConfig.entryPoints && chainConfig.entryPoints.length > 0) {
config.network = {
controlLayer: {
entryPoints: chainConfig.entryPoints,
entryPoints: [...chainConfig.entryPoints],
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/getters/getEnvironmentConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from 'zod'
import config from '~/config/environments.toml'
import { defaultChainKey } from '~/consts'
import { getChainConfig } from '~/utils/chains'

const EnvironmentConfig = z
Expand Down Expand Up @@ -37,7 +38,7 @@ const EnvironmentConfig = z
type EnvironmentConfig = z.infer<typeof EnvironmentConfig>

const fallbackEnvironmentConfig: EnvironmentConfig = EnvironmentConfig.parse({
availableChains: ['polygon'],
availableChains: [defaultChainKey],
})

const parsedConfig = z
Expand Down
12 changes: 6 additions & 6 deletions src/pages/ProjectPage/ProjectEditorPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Chain } from '@streamr/config'
import React, { useMemo } from 'react'
import { useNavigate } from 'react-router-dom'
import styled, { css } from 'styled-components'
Expand All @@ -21,18 +22,17 @@ import { deleteProject } from '~/services/projects'
import { DetailsPageHeader } from '~/shared/components/DetailsPageHeader'
import LoadingIndicator from '~/shared/components/LoadingIndicator'
import useIsMounted from '~/shared/hooks/useIsMounted'
import { ProjectType, SalePoint } from '~/shared/types'
import { ProjectDraft } from '~/stores/projectDraft'
import { SalePointsPayload } from '~/types/projects'
import { formatChainName } from '~/utils'
import {
getChainConfig,
getChainConfigExtension,
useCurrentChainId,
} from '~/utils/chains'
import { ProjectType, SalePoint } from '~/shared/types'
import { ProjectDraft } from '~/stores/projectDraft'
import { Chain } from '~/types'
import { SalePointsPayload } from '~/types/projects'
import { formatChainName } from '~/utils'
import { toastedOperation } from '~/utils/toastedOperation'
import { Route as R, routeOptions } from '~/utils/routes'
import { toastedOperation } from '~/utils/toastedOperation'
import DataUnionFee from './DataUnionFee'
import DataUnionPayment from './DataUnionPayment'
import EditorHero from './EditorHero'
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/ProjectParser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Chain } from '@streamr/config'
import { z } from 'zod'
import { address0 } from '~/consts'
import { getProjectImageUrl } from '~/getters'
Expand All @@ -9,7 +10,6 @@ import {
timeUnitSecondsMultiplierMap,
timeUnits,
} from '~/shared/utils/timeUnit'
import { Chain } from '~/types'
import { toBigInt } from '~/utils/bn'
import {
getChainConfig,
Expand Down
27 changes: 0 additions & 27 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { config as configs } from '@streamr/config'
import { MessageID } from '@streamr/sdk'
import { TheGraph } from '~/shared/types'

Expand Down Expand Up @@ -42,32 +41,6 @@ export type ChainConfigKey =
| 'minimumDelegationWei'
| 'earlyLeaverPenaltyWei'

type ContractAddressKey = typeof configs extends Record<
any,
Record<'contracts', Partial<Record<infer K, string>>>
>
? K
: never

export interface Chain {
name: string
id: number
theGraphUrl?: string
rpcEndpoints: { url: string }[]
contracts: Partial<Record<ContractAddressKey | (string & {}), string>>
entryPoints?: {
nodeId: string
websocket: {
host: string
port: number
tls: boolean
}
}[]
nativeCurrency: { symbol: string; name: string; decimals: number }
blockExplorerUrl?: string
adminPrivateKey?: string
}

export type OrderDirection = 'asc' | 'desc'

export interface DataPoint {
Expand Down
12 changes: 6 additions & 6 deletions src/utils/chains.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { config as configs } from '@streamr/config'
import { Chain, config as configs } from '@streamr/config'
import { produce } from 'immer'
import { useMemo } from 'react'
import { useSearchParams } from 'react-router-dom'
import { ethereumNetworks } from '~/shared/utils/constants'
import { defaultChainKey } from '~/consts'
import {
ChainConfigExtension,
fallbackChainConfigExtension,
parsedChainConfigExtension,
} from '~/utils/chainConfigExtension'
import { Chain } from '~/types'
import { ethereumNetworks } from '~/shared/utils/constants'
import formatConfigUrl from './formatConfigUrl'

function getPreferredChainName(chainName: string) {
Expand All @@ -24,12 +24,12 @@ function getChainConfigWithFallback(chainName: string): Chain {
return getChainConfig(chainName)
} catch (_) {}

return getChainConfig('polygon')
return getChainConfig(defaultChainKey)
}

export function getCurrentChain() {
return getChainConfigWithFallback(
new URLSearchParams(window.location.search).get('chain') || 'polygon',
new URLSearchParams(window.location.search).get('chain') || defaultChainKey,
)
}

Expand All @@ -38,7 +38,7 @@ export function getCurrentChainId() {
}

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

return useMemo(() => getChainConfigWithFallback(chainName), [chainName])
}
Expand Down
2 changes: 0 additions & 2 deletions src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ export function getContractAddress(
return contracts.SponsorshipStakeWeightedAllocationPolicy
case 'sponsorshipVoteKickPolicy':
return contracts.SponsorshipVoteKickPolicy
case 'sponsorshipPaymentToken':
return contracts.SponsorshipPaymentToken
case 'streamRegistry':
return contracts.StreamRegistry
case 'streamStorage':
Expand Down
3 changes: 2 additions & 1 deletion src/utils/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import queryString from 'query-string'
import { defaultChainKey } from '~/consts'
import { getSymbolicChainName } from './chains'

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

const qs = options.search
? queryString.stringify(
chain === 'polygon'
chain === defaultChainKey
? search
: {
...search,
Expand Down

0 comments on commit be38188

Please sign in to comment.