fix custom network on URI

This commit is contained in:
Josep M Sobrepere
2024-12-19 11:02:59 +01:00
parent db7f6f096f
commit 331d4a547b
3 changed files with 43 additions and 22 deletions
+22 -14
View File
@@ -18,7 +18,13 @@ import {
switchMap,
tap,
} from "rxjs"
import { defaultNetwork, Network, networkCategories } from "./networks"
import {
addCustomNetwork,
defaultNetwork,
getCustomNetwork,
Network,
networkCategories,
} from "./networks"
import {
createSmoldotSource,
getSmoldotProvider,
@@ -64,23 +70,25 @@ selectedChainChanged$.subscribe(({ network, endpoint }) =>
endpoint,
}),
)
const allNetworks = networkCategories.map((x) => x.networks).flat()
const findNetwork = (networkId: string): Network | undefined =>
allNetworks.find((x) => x.id == networkId)
const getDefaultChain = (): SelectedChain => {
const findNetwork = (networkId: string) => {
for (const { networks } of networkCategories) {
for (const network of networks) {
if (network.id === networkId) {
return network
}
}
}
return null
}
const hashParams = getHashParams()
if (hashParams.has("networkId") && hashParams.has("endpoint")) {
const network = findNetwork(hashParams.get("networkId")!)
if (network) {
return { network, endpoint: hashParams.get("endpoint")! }
const networkId = hashParams.get("networkId")!
const endpoint = hashParams.get("endpoint")!
if (networkId === "custom") {
addCustomNetwork(endpoint)
return {
network: getCustomNetwork(),
endpoint,
}
}
const network = findNetwork(networkId)
if (network) return { network, endpoint }
}
return {
+9 -4
View File
@@ -38,13 +38,13 @@ const networks = {
Kusama,
Paseo,
Westend,
Development: [
Custom: [
{
id: "localhost",
display: "Localhost",
id: "custom",
display: "Custom",
lightclient: false,
endpoints: {
"Local (ws://127.0.0.1:9944)": "ws://127.0.0.1:9944",
"ws://127.0.0.1:9944": "ws://127.0.0.1:9944",
},
} as Network,
],
@@ -54,4 +54,9 @@ export const networkCategories: NetworkCategory[] = Object.entries(
networks,
).map(([name, networks]) => ({ name, networks }))
export const getCustomNetwork = () => networks.Custom[0]
export const addCustomNetwork = (uri: string) => {
getCustomNetwork().endpoints[uri] = uri
}
export const defaultNetwork = Polkadot[0]