Skip to content

Commit

Permalink
add missing pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Sep 8, 2024
1 parent 6beb132 commit ce8d0e9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '';

Expand Down
20 changes: 12 additions & 8 deletions src/contexts/apis/CoretimeApi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
};

Expand Down
21 changes: 12 additions & 9 deletions src/contexts/apis/RelayApi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
};

Expand Down
9 changes: 5 additions & 4 deletions src/contexts/network/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ce8d0e9

Please sign in to comment.