From 7701d6f783a7a314e5082cc5750c36e9cf9e51d9 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 30 Sep 2020 19:28:18 +0200 Subject: [PATCH] Be specific in endpoint detail config (#3796) * Be specific in endpoint detail config * Expand * localhost --- .../apps-config/src/settings/endpoints.ts | 121 ++++++++++++------ packages/apps/src/Endpoints/index.tsx | 14 +- 2 files changed, 85 insertions(+), 50 deletions(-) diff --git a/packages/apps-config/src/settings/endpoints.ts b/packages/apps-config/src/settings/endpoints.ts index 5dbe9b65e7..33a16c29da 100644 --- a/packages/apps-config/src/settings/endpoints.ts +++ b/packages/apps-config/src/settings/endpoints.ts @@ -10,6 +10,7 @@ export interface LinkOption extends Option { dnslink?: string; isChild?: boolean; isDevelopment?: boolean; + textHoster: string; } interface EnvWindow { @@ -26,10 +27,11 @@ function createOwn (t: TFunction): LinkOption[] { if (storedItems) { const items = JSON.parse(storedItems) as string[]; - return items.map((item) => ({ + return items.map((textHoster) => ({ info: 'local', - text: t('rpc.custom.entry', 'Custom (custom, {{WS_URL}})', { ns: 'apps-config', replace: { WS_URL: item } }), - value: item + text: t('rpc.custom.entry', 'Custom', { ns: 'apps-config' }), + textHoster, + value: textHoster })); } } catch (e) { @@ -44,7 +46,8 @@ function createDev (t: TFunction): LinkOption[] { { dnslink: 'local', info: 'local', - text: t('rpc.local', 'Local Node (Own, 127.0.0.1:9944)', { ns: 'apps-config' }), + text: t('rpc.local', 'Local Node', { ns: 'apps-config' }), + textHoster: '127.0.0.1:9944', value: 'ws://127.0.0.1:9944' } ]; @@ -56,73 +59,86 @@ function createLiveNetworks (t: TFunction): LinkOption[] { { dnslink: 'polkadot', info: 'polkadot', - text: t('rpc.polkadot.parity', 'Polkadot (Live, hosted by Parity)', { ns: 'apps-config' }), + text: t('rpc.polkadot.parity', 'Polkadot', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Parity' } }), value: 'wss://rpc.polkadot.io' }, { info: 'polkadot', - text: t('rpc.polkadot.w3f', 'Polkadot (Live, hosted by Web3 Foundation)', { ns: 'apps-config' }), + text: t('rpc.polkadot.w3f', 'Polkadot', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Web3 Foundation' } }), value: 'wss://cc1-1.polkadot.network' }, { dnslink: 'kusama', info: 'kusama', - text: t('rpc.kusama.parity', 'Kusama (Polkadot Canary, hosted by Parity)', { ns: 'apps-config' }), + text: t('rpc.kusama.parity', 'Kusama', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Parity' } }), value: 'wss://kusama-rpc.polkadot.io' }, { info: 'kusama', - text: t('rpc.kusama.w3f', 'Kusama (Polkadot Canary, hosted by Web3 Foundation)', { ns: 'apps-config' }), + text: t('rpc.kusama.w3f', 'Kusama', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Web3 Foundation' } }), value: 'wss://cc3-5.kusama.network' }, { info: 'kusama', isDisabled: true, - text: t('rpc.kusama.ava', 'Kusama (Polkadot Canary, user-run public nodes; see https://status.cloud.ava.do/)', { ns: 'apps-config' }), + text: t('rpc.kusama.ava', 'Kusama', { ns: 'apps-config' }), + textHoster: t('rpc.ava.summary', 'user-run public nodes; see https://status.cloud.ava.do/', { ns: 'apps-config' }), value: 'wss://kusama.polkadot.cloud.ava.do' }, // alphabetical based on chain name { dnslink: 'centrifuge', info: 'centrifuge', - text: t('rpc.centrifuge', 'Centrifuge (Mainnet, hosted by Centrifuge)', { ns: 'apps-config' }), + text: t('rpc.centrifuge', 'Centrifuge', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Centrifuge' } }), value: 'wss://fullnode.centrifuge.io' }, { info: 'crab', - text: t('rpc.crab', 'Darwinia Crab (Darwinia Canary, hosted by Darwinia Network)', { ns: 'apps-config' }), + text: t('rpc.crab', 'Darwinia Crab', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Darwinia Network' } }), value: 'wss://crab.darwinia.network' }, { dnslink: 'edgeware', info: 'edgeware', - text: t('rpc.edgeware', 'Edgeware (Mainnet, hosted by Commonwealth Labs)', { ns: 'apps-config' }), + text: t('rpc.edgeware', 'Edgeware', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Commonwealth Labs' } }), value: 'wss://mainnet1.edgewa.re' }, { dnslink: 'kulupu', info: 'kulupu', - text: t('rpc.kulupu', 'Kulupu (Kulupu Mainnet, hosted by Kulupu)', { ns: 'apps-config' }), + text: t('rpc.kulupu', 'Kulupu', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Kulupu' } }), value: 'wss://rpc.kulupu.corepaper.org/ws' }, { info: 'nodle', - text: t('rpc.nodle-main', 'Nodle Main (Nodle Mainnet, hosted by Nodle)', { ns: 'apps-config' }), + text: t('rpc.nodle-main', 'Nodle Main', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Nodle' } }), value: 'wss://main1.nodleprotocol.io' }, { info: 'plasm', - text: t('rpc.plasm', 'Plasm (Plasm Mainnet, hosted by Stake Technologies)', { ns: 'apps-config' }), + text: t('rpc.plasm', 'Plasm', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Stake Technologies' } }), value: 'wss://rpc.plasmnet.io/' }, { info: 'stafi', - text: t('rpc.stafi', 'Stafi (Stafi Mainnet, hosted by Stafi Foundation)', { ns: 'apps-config' }), + text: t('rpc.stafi', 'Stafi', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Stafi Foundation' } }), value: 'wss://mainnet-rpc.stafi.io' }, { info: 'subsocial', - text: t('rpc.subsocial', 'Subsocial (Subsocial Network, hosted by DappForce)', { ns: 'apps-config' }), + text: t('rpc.subsocial', 'Subsocial', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'DappForce' } }), value: 'wss://rpc.subsocial.network' } ]; @@ -134,123 +150,145 @@ function createTestNetworks (t: TFunction): LinkOption[] { { dnslink: 'rococo', info: 'rococo', - text: t('rpc.rococo', 'Rococo (Polkadot Testnet, hosted by Parity)', { ns: 'apps-config' }), + text: t('rpc.rococo', 'Rococo', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Parity' } }), value: 'wss://rococo-rpc.polkadot.io' }, { info: 'rococoTick', isChild: true, - text: t('rpc.rococo.tick', 'Tick (Polkadot Testpara, hosted by Parity)', { ns: 'apps-config' }), + text: t('rpc.rococo.tick', 'Tick', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Parity' } }), value: 'wss://tick-rpc.polkadot.io' }, { info: 'rococoTrick', isChild: true, - text: t('rpc.rococo.trick', 'Trick (Polkadot Testpara, hosted by Parity)', { ns: 'apps-config' }), + text: t('rpc.rococo.trick', 'Trick', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Prity' } }), value: 'wss://trick-rpc.polkadot.io' }, { info: 'rococoTrack', isChild: true, - text: t('rpc.rococo.track', 'Track (Polkadot Testpara, hosted by Parity)', { ns: 'apps-config' }), + text: t('rpc.rococo.track', 'Track', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Parity' } }), value: 'wss://track-rpc.polkadot.io' }, { info: 'rococoAcala', isChild: true, - text: t('rpc.rococo.acala', 'Mandala PC1 (Acala Testpara, hosted by Acala)', { ns: 'apps-config' }), + text: t('rpc.rococo.acala', 'Mandala PC1', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Acala' } }), value: 'wss://rococo-1.acala.laminar.one' }, { info: 'rococoDarwinia', isChild: true, - text: t('rpc.rococo.darwinia', 'Darwinia PC1 (Darwinia Testpara, hosted by Darwinia Network)', { ns: 'apps-config' }), + text: t('rpc.rococo.darwinia', 'Darwinia PC1', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Darwinia Network' } }), value: 'wss://parachain-rpc.darwinia.network' }, { info: 'rococoPlasm', isChild: true, - text: t('rpc.rococo.plasm', 'Plasm PC1 (Plasm Testpara, hosted by Stake Technologies)', { ns: 'apps-config' }), + text: t('rpc.rococo.plasm', 'Plasm PC1', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Stake Technologies' } }), value: 'wss://rpc.parachain.plasmnet.io' }, { info: 'rococoRobonomics', isChild: true, - text: t('rpc.rococo.robonomics', 'Robonomics PC1 (Robonomics Testpara, hosted by Airalab)', { ns: 'apps-config' }), + text: t('rpc.rococo.robonomics', 'Robonomics PC1', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Airalab' } }), value: 'wss://parachain-rpc.robonomics.network' }, { info: 'rococoLaminar', isChild: true, - text: t('rpc.rococo.laminar', 'Turbulence PC1 (Laminar Testpara, hosted by Laminar)', { ns: 'apps-config' }), + text: t('rpc.rococo.laminar', 'Turbulence PC1', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Laminar' } }), value: 'wss://rococo-1.laminar-chain.laminar.one' }, // alphabetical based on chain name { info: 'centrifuge', - text: t('rpc.amber', 'Amber (Centrifuge Testnet, hosted by Centrifuge)', { ns: 'apps-config' }), + text: t('rpc.amber', 'Amber', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Centrifuge' } }), value: 'wss://fullnode.amber.centrifuge.io' }, { info: 'nodle', - text: t('rpc.nodle-arcadia', 'Arcadia (Nodle Testnet, hosted by Nodle)', { ns: 'apps-config' }), + text: t('rpc.nodle-arcadia', 'Arcadia', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Nodle' } }), value: 'wss://arcadia1.nodleprotocol.io' }, { info: 'edgeware', - text: t('rpc.beresheet', 'Beresheet (Edgeware Testnet, hosted by Commonwealth Labs)', { ns: 'apps-config' }), + text: t('rpc.beresheet', 'Beresheet', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Commonwealth Labs' } }), value: 'wss://beresheet1.edgewa.re' }, { info: 'crust', - text: t('rpc.crust.network', 'Crust Maxwell CC2 (Crust Testnet, hosted by Crust Network)', { ns: 'apps-config' }), + text: t('rpc.crust.network', 'Crust Maxwell CC2', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Crust Network' } }), value: 'wss://api.crust.network/' }, { info: 'datahighway', isDisabled: true, - text: t('rpc.datahighway.harbour', 'Harbour (DataHighway Testnet, hosted by MXC)', { ns: 'apps-config' }), + text: t('rpc.datahighway.harbour', 'Harbour', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'MXC' } }), value: 'wss://testnet-harbour.datahighway.com' }, { info: 'dusty', - text: t('rpc.dusty', 'Dusty (Plasm Testnet, hosted by Stake Technologies)', { ns: 'apps-config' }), + text: t('rpc.dusty', 'Dusty', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Stake Technologies' } }), value: 'wss://rpc.dusty.plasmnet.io/' }, { info: 'equilibrium', - text: t('rpc.equilibriumr', 'Equilibrium Testnet', { ns: 'apps-config' }), + text: t('rpc.equilibriumr', 'Equilibrium', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Equilibrium' } }), value: 'wss://api.testnet.equilibrium.io:9944' }, { info: 'substrate', - text: t('rpc.flamingfir', 'Flaming Fir (Substrate Testnet, hosted by Parity)', { ns: 'apps-config' }), + text: t('rpc.flamingfir', 'Flaming Fir', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Parity' } }), value: 'wss://substrate-rpc.parity.io' }, { info: 'acala', - text: t('rpc.mandala', 'Mandala (Acala Testnet, hosted by Acala)', { ns: 'apps-config' }), + text: t('rpc.mandala', 'Mandala', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Acala' } }), value: 'wss://node-6684611762228215808.jm.onfinality.io/ws' }, { info: 'kilt', - text: t('rpc.kilt', 'Mashnet (KILT Canary, hosted by KILT Protocol)', { ns: 'apps-config' }), + text: t('rpc.kilt', 'Mashnet', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'KILT Protocol' } }), value: 'wss://full-nodes.kilt.io:9944/' }, { info: 'phala', - text: t('rpc.phala', 'Phala PoC-2 (Phala Testnet, hosted by Phala Network)', { ns: 'apps-config' }), + text: t('rpc.phala', 'Phala PoC-2', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Phala Network' } }), value: 'wss://poc2.phala.network/ws' }, { info: 'laminar', - text: t('rpc.turbulence', 'Turbulence (Laminar Testnet, hosted by Laminar)', { ns: 'apps-config' }), + text: t('rpc.turbulence', 'Turbulence', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Laminar' } }), value: 'wss://testnet-node-1.laminar-chain.laminar.one/ws' }, { dnslink: 'westend', info: 'westend', - text: t('rpc.westend', 'Westend (Polkadot Testnet, hosted by Parity)', { ns: 'apps-config' }), + text: t('rpc.westend', 'Westend', { ns: 'apps-config' }), + textHoster: t('rpc.hosted.by', 'hosted by {{host}}', { ns: 'apps-config', replace: { host: 'Parity' } }), value: 'wss://westend-rpc.polkadot.io' } ]; @@ -267,11 +305,13 @@ function createCustom (t: TFunction): LinkOption[] { { isHeader: true, text: t('rpc.custom', 'Custom environment', { ns: 'apps-config' }), + textHoster: '', value: '' }, { info: 'WS_URL', text: t('rpc.custom.entry', 'Custom {{WS_URL}}', { ns: 'apps-config', replace: { WS_URL } }), + textHoster: WS_URL, value: WS_URL } ] @@ -289,12 +329,14 @@ export default function create (t: TFunction): LinkOption[] { { isHeader: true, text: t('rpc.header.live', 'Live networks', { ns: 'apps-config' }), + textHoster: '', value: '' }, ...createLiveNetworks(t), { isHeader: true, text: t('rpc.header.test', 'Test networks', { ns: 'apps-config' }), + textHoster: '', value: '' }, ...createTestNetworks(t), @@ -302,6 +344,7 @@ export default function create (t: TFunction): LinkOption[] { isDevelopment: true, isHeader: true, text: t('rpc.header.dev', 'Development', { ns: 'apps-config' }), + textHoster: '', value: '' }, ...createDev(t), diff --git a/packages/apps/src/Endpoints/index.tsx b/packages/apps/src/Endpoints/index.tsx index 47d1b845da..494179ddc2 100644 --- a/packages/apps/src/Endpoints/index.tsx +++ b/packages/apps/src/Endpoints/index.tsx @@ -30,13 +30,6 @@ interface UrlState { isUrlValid: boolean; } -function textToParts (text: string): [string, string, string] { - const [first, remainder] = text.replace(')', '').split(' ('); - const [middle, last] = (remainder || '').split(', '); - - return [first, middle || '', last || '']; -} - function isValidUrl (url: string): boolean { return ( // some random length... we probably want to parse via some lib @@ -51,17 +44,16 @@ function combineEndpoints (endpoints: LinkOption[]): Group[] { if (e.isHeader) { result.push({ header: e.text, isDevelopment: e.isDevelopment, networks: [] }); } else { - const [name, , providerName] = textToParts(e.text as string); const prev = result[result.length - 1]; - const prov = { name: providerName, url: e.value as string }; + const prov = { name: e.textHoster, url: e.value as string }; - if (prev.networks[prev.networks.length - 1] && name === prev.networks[prev.networks.length - 1].name) { + if (prev.networks[prev.networks.length - 1] && e.text === prev.networks[prev.networks.length - 1].name) { prev.networks[prev.networks.length - 1].providers.push(prov); } else { prev.networks.push({ icon: e.info, isChild: e.isChild, - name, + name: e.text as string, providers: [prov] }); }