From 166eca663b80e5d1783410c1d953f2e712c97aad Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 30 Jun 2020 07:34:15 +0200 Subject: [PATCH] Allow disabled flag on endpoint entries (#3092) --- .../apps-config/src/settings/endpoints.ts | 67 ++++++++++--------- packages/apps-config/src/settings/types.ts | 1 + 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/packages/apps-config/src/settings/endpoints.ts b/packages/apps-config/src/settings/endpoints.ts index 7060abdb5d..4de67d4106 100644 --- a/packages/apps-config/src/settings/endpoints.ts +++ b/packages/apps-config/src/settings/endpoints.ts @@ -4,6 +4,8 @@ import { Option } from './types'; +type TFn = (key: string, text: string, options: { ns: string, replace?: Record }) => T; + interface LinkOption extends Option { dnslink?: string; } @@ -15,7 +17,7 @@ interface EnvWindow { } } -function createDev (t: (key: string, text: string, options: { ns: string }) => T): LinkOption[] { +function createDev (t: TFn): LinkOption[] { return [ { dnslink: 'local', @@ -26,7 +28,7 @@ function createDev (t: (key: string, text: string, options: { ns: st ]; } -function createLive (t: (key: string, text: string, options: { ns: string }) => T): LinkOption[] { +function createLive (t: TFn): LinkOption[] { return [ { dnslink: 'polkadot', @@ -79,7 +81,7 @@ function createLive (t: (key: string, text: string, options: { ns: s ]; } -function createTest (t: (key: string, text: string, options: { ns: string }) => T): LinkOption[] { +function createTest (t: TFn): LinkOption[] { return [ { dnslink: 'westend', @@ -101,26 +103,46 @@ function createTest (t: (key: string, text: string, options: { ns: s info: 'nodle', text: t('rpc.arcadia', 'Arcadia (Nodle Testnet, hosted by Nodle)', { ns: 'apps-config' }), value: 'wss://arcadia1.nodleprotocol.io/' + }, + { + info: 'datahighway', + isDisabled: true, + text: t('rpc.datahighway.harbour', 'Harbour (DataHighway Testnet, hosted by MXC)', { ns: 'apps-config' }), + value: 'wss://testnet-harbour.datahighway.com' } - // { - // info: 'datahighway', - // text: t('rpc.datahighway.harbour', 'Harbour (DataHighway Testnet, hosted by MXC)', { ns: 'apps-config' }), - // value: 'wss://testnet-harbour.datahighway.com' - // } ]; } +function createCustom (t: TFn): LinkOption[] { + const WS_URL = ( + (typeof process !== 'undefined' ? process.env?.WS_URL : undefined) || + (typeof window !== 'undefined' ? (window as EnvWindow).process_env?.WS_URL : undefined) + ); + + return WS_URL + ? [ + { + isHeader: true, + text: t('rpc.custom', 'Custom environment', { ns: 'apps-config' }), + value: '' + }, + { + info: 'WS_URL', + text: t('rpc.custom.entry', 'Custom {{WS_URL}}', { ns: 'apps-config', replace: { WS_URL } }), + value: WS_URL + } + ] + : []; +} + // The available endpoints that will show in the dropdown. For the most part (with the exception of // Polkadot) we try to keep this to live chains only, with RPCs hosted by the community/chain vendor // info: The chain logo name as defined in ../logos, specifically in namedLogos // text: The text to display on teh dropdown // value: The actual hosted secure websocket endpoint -export default function create (t: (key: string, text: string, options: { ns: string, replace?: Record }) => T): LinkOption[] { - const WS_URL = ( - (typeof process !== 'undefined' ? process.env?.WS_URL : undefined) || - (typeof window !== 'undefined' ? (window as EnvWindow).process_env?.WS_URL : undefined) - ); - const endpoints = [ +export default function create (t: TFn): LinkOption[] { + return [ + ...createCustom(t), { isHeader: true, text: t('rpc.header.live', 'Live networks', { ns: 'apps-config' }), @@ -139,20 +161,5 @@ export default function create (t: (key: string, text: string, optio value: '' }, ...createDev(t) - ]; - - return WS_URL - ? ([ - { - isHeader: true, - text: t('rpc.custom', 'Custom environment', { ns: 'apps-config' }), - value: '' - }, - { - info: 'WS_URL', - text: t('rpc.custom.entry', 'Custom {{WS_URL}}', { ns: 'apps-config', replace: { WS_URL } }), - value: WS_URL - } - ] as LinkOption[]).concat(endpoints) - : endpoints; + ].filter(({ isDisabled }) => !isDisabled); } diff --git a/packages/apps-config/src/settings/types.ts b/packages/apps-config/src/settings/types.ts index 78a239cb8d..3b8a8431c7 100644 --- a/packages/apps-config/src/settings/types.ts +++ b/packages/apps-config/src/settings/types.ts @@ -4,6 +4,7 @@ export interface Option { info?: string; + isDisabled?: boolean; isHeader?: boolean; text: React.ReactNode; value: string | number;