From ce8d0e90ba05224de2fca87e4923f07cef7a2018 Mon Sep 17 00:00:00 2001 From: Szegoo Date: Sun, 8 Sep 2024 16:17:39 +0200 Subject: [PATCH] add missing pieces --- src/consts/index.ts | 1 + src/contexts/apis/CoretimeApi/index.tsx | 20 ++++++++++++-------- src/contexts/apis/RelayApi/index.tsx | 21 ++++++++++++--------- src/contexts/network/index.tsx | 9 +++++---- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/consts/index.ts b/src/consts/index.ts index bb27719c..e4f037d8 100644 --- a/src/consts/index.ts +++ b/src/consts/index.ts @@ -42,6 +42,7 @@ export const WS_ROCOCO_RELAY_CHAIN = process.env.WS_ROCOCO_RELAY_CHAIN ?? ''; export const WS_WESTEND_RELAY_CHAIN = process.env.WS_WESTEND_RELAY_CHAIN ?? ''; export const WS_POLKADOT_CORETIME_CHAIN = process.env.WS_POLKADOT_CORETIME_CHAIN ?? ''; +export const WS_KUSAMA_CORETIME_CHAIN = process.env.WS_KUSAMA_CORETIME_CHAIN ?? ''; export const WS_ROCOCO_CORETIME_CHAIN = process.env.WS_ROCOCO_CORETIME_CHAIN ?? ''; export const WS_WESTEND_CORETIME_CHAIN = process.env.WS_WESTEND_CORETIME_CHAIN ?? ''; diff --git a/src/contexts/apis/CoretimeApi/index.tsx b/src/contexts/apis/CoretimeApi/index.tsx index b8444a04..00d45d75 100644 --- a/src/contexts/apis/CoretimeApi/index.tsx +++ b/src/contexts/apis/CoretimeApi/index.tsx @@ -2,6 +2,7 @@ import React, { useContext, useEffect, useReducer } from 'react'; import { WS_KUSAMA_CORETIME_CHAIN, + WS_POLKADOT_CORETIME_CHAIN, WS_ROCOCO_CORETIME_CHAIN, WS_WESTEND_CORETIME_CHAIN, } from '@/consts'; @@ -47,14 +48,17 @@ const CoretimeApiContextProvider = (props: any) => { const TIMESLICE_PERIOD = 80; const getUrl = (network: any): string | null => { - if (network === NetworkType.ROCOCO) { - return WS_ROCOCO_CORETIME_CHAIN; - } else if (network === NetworkType.KUSAMA) { - return WS_KUSAMA_CORETIME_CHAIN; - } else if (network === NetworkType.WESTEND) { - return WS_WESTEND_CORETIME_CHAIN; - } else { - return null; + switch (network) { + case NetworkType.POLKADOT: + return WS_POLKADOT_CORETIME_CHAIN; + case NetworkType.KUSAMA: + return WS_KUSAMA_CORETIME_CHAIN; + case NetworkType.ROCOCO: + return WS_ROCOCO_CORETIME_CHAIN; + case NetworkType.WESTEND: + return WS_WESTEND_CORETIME_CHAIN; + default: + return null; } }; diff --git a/src/contexts/apis/RelayApi/index.tsx b/src/contexts/apis/RelayApi/index.tsx index c65013c9..47d99ffe 100644 --- a/src/contexts/apis/RelayApi/index.tsx +++ b/src/contexts/apis/RelayApi/index.tsx @@ -2,7 +2,7 @@ import React, { useContext, useEffect, useReducer, useState } from 'react'; import { parseHNString } from '@/utils/functions'; -import { WS_KUSAMA_RELAY_CHAIN, WS_ROCOCO_RELAY_CHAIN, WS_WESTEND_RELAY_CHAIN } from '@/consts'; +import { WS_KUSAMA_RELAY_CHAIN, WS_POLKADOT_RELAY_CHAIN, WS_ROCOCO_RELAY_CHAIN, WS_WESTEND_RELAY_CHAIN } from '@/consts'; import { ApiState } from '@/contexts/apis/types'; import { useNetwork } from '@/contexts/network'; import { useToast } from '@/contexts/toast'; @@ -34,14 +34,17 @@ const RelayApiContextProvider = (props: any) => { const disconnectRelay = () => disconnect(state); const getUrl = (network: any): string | null => { - if (network === NetworkType.ROCOCO) { - return WS_ROCOCO_RELAY_CHAIN; - } else if (network === NetworkType.KUSAMA) { - return WS_KUSAMA_RELAY_CHAIN; - } else if (network === NetworkType.WESTEND) { - return WS_WESTEND_RELAY_CHAIN; - } else { - return null; + switch (network) { + case NetworkType.POLKADOT: + return WS_POLKADOT_RELAY_CHAIN; + case NetworkType.KUSAMA: + return WS_KUSAMA_RELAY_CHAIN; + case NetworkType.ROCOCO: + return WS_ROCOCO_RELAY_CHAIN; + case NetworkType.WESTEND: + return WS_WESTEND_RELAY_CHAIN; + default: + return null; } }; diff --git a/src/contexts/network/index.tsx b/src/contexts/network/index.tsx index 196e0e00..925d9776 100644 --- a/src/contexts/network/index.tsx +++ b/src/contexts/network/index.tsx @@ -29,17 +29,18 @@ const NetworkProvider = ({ children }: Props) => { useEffect(() => { if (!router.isReady) return; - if (network === 'rococo') setActiveNetwork(NetworkType.ROCOCO); - else if (network === 'kusama') setActiveNetwork(NetworkType.KUSAMA); + if (network === 'polkadot') setActiveNetwork(NetworkType.POLKADOT); + if (network === 'kusama') setActiveNetwork(NetworkType.KUSAMA); + else if (network === 'rococo') setActiveNetwork(NetworkType.ROCOCO); else if (network === 'westend') setActiveNetwork(NetworkType.WESTEND); else { - // invalid network param. redirect to the default chain: kusama + // invalid network param. redirect to the default chain: polkadot router.push( { pathname: router.pathname, query: { ...router.query, - network: 'kusama', + network: 'polkadot', }, }, undefined,