Skip to content

Commit 9405443

Browse files
committed
Define getChainSlug for URLs
1 parent 711745d commit 9405443

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/components/ChainSelector.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import UnstyledNetworkIcon from '~/shared/components/NetworkIcon'
99
import SvgIcon from '~/shared/components/SvgIcon'
1010
import { COLORS, LAPTOP } from '~/shared/utils/styled'
1111
import { StreamDraft } from '~/stores/streamDraft'
12-
import { getChainKey, useCurrentChain } from '~/utils/chains'
12+
import { getChainSlug, useCurrentChain } from '~/utils/chains'
1313

1414
type MenuItemProps = {
1515
chain: Chain
@@ -45,14 +45,14 @@ const Menu = ({ chains, selectedChain, toggle }: MenuProps) => {
4545
onClick={() => {
4646
toggle(false)
4747

48-
const chainKey = getChainKey(c.id)
48+
const slug = getChainSlug(c.id)
4949

5050
setSearchParams((prev) => {
5151
const { chain: _, ...rest } = Object.fromEntries(prev)
5252

53-
return chainKey === defaultChainKey
53+
return slug === getChainSlug(defaultChainKey)
5454
? rest
55-
: { ...rest, chain: chainKey }
55+
: { ...rest, chain: slug }
5656
})
5757
}}
5858
/>

src/utils/chains.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ export function getChainConfigExtension(chainId: number): ChainConfigExtension {
159159
return getChainEntry(getChainKey(chainId)).configExtension
160160
}
161161

162+
export function getChainSlug(chainIdOrChainKey: ChainKey | number): string {
163+
const chainEntry = getChainEntry(getChainKey(chainIdOrChainKey))
164+
165+
return chainEntry.configExtension.slug || chainEntry.chainKey
166+
}
167+
162168
/**
163169
* Checks if a given string is a `ChainKey`.
164170
* @param candidate Any string.

src/utils/routes.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { ChainKey } from '@streamr/config'
22
import queryString from 'query-string'
33
import { defaultChainKey } from '~/consts'
4-
import { parsedChainConfigExtension } from '~/utils/chainConfigExtension'
5-
import { getChainKey } from './chains'
4+
import { getChainSlug } from './chains'
65

76
interface RouteOptions {
87
search?: Record<'chain', string> & Record<string, any>
@@ -14,15 +13,10 @@ export function routeOptions(
1413
search: Record<string, any> = {},
1514
hash = '',
1615
): RouteOptions {
17-
const chain =
18-
typeof chainIdOrChainKey === 'number'
19-
? getChainKey(chainIdOrChainKey)
20-
: parsedChainConfigExtension[chainIdOrChainKey]?.slug || chainIdOrChainKey
21-
2216
return {
2317
search: {
2418
...search,
25-
chain,
19+
chain: getChainSlug(chainIdOrChainKey),
2620
},
2721
hash,
2822
}

0 commit comments

Comments
 (0)