diff --git a/packages/ui-assets/src/edgeware-circle.svg b/packages/ui-assets/src/edgeware-circle.svg new file mode 100644 index 00000000..cda424ab --- /dev/null +++ b/packages/ui-assets/src/edgeware-circle.svg @@ -0,0 +1 @@ +logo-white-with-bgCreated with Sketch. \ No newline at end of file diff --git a/packages/ui-assets/src/edgeware.svg b/packages/ui-assets/src/edgeware.svg new file mode 100644 index 00000000..9735fcba --- /dev/null +++ b/packages/ui-assets/src/edgeware.svg @@ -0,0 +1 @@ +logo-white-with-bgCreated with Sketch. \ No newline at end of file diff --git a/packages/ui-settings/src/Settings.ts b/packages/ui-settings/src/Settings.ts index bdf3dfb1..49a832b4 100644 --- a/packages/ui-settings/src/Settings.ts +++ b/packages/ui-settings/src/Settings.ts @@ -6,7 +6,7 @@ import store from 'store'; import { isUndefined } from '@polkadot/util'; import { CRYPTOS, ENDPOINT_DEFAULT, ENDPOINTS, LANGUAGE_DEFAULT, LANGUAGES, LOCKING_DEFAULT, LOCKING, PREFIX_DEFAULT, PREFIXES, UIMODE_DEFAULT, UIMODES, UITHEME_DEFAULT, UITHEMES } from './defaults'; -import { Options, SettingsStruct } from './types'; +import { Option, SettingsStruct } from './types'; export class Settings implements SettingsStruct { private _apiUrl: string; @@ -56,31 +56,31 @@ export class Settings implements SettingsStruct { return this._uiTheme; } - public get availableNodes (): Options { + public get availableNodes (): Option[] { return ENDPOINTS; } - public get availableCryptos (): Options { + public get availableCryptos (): Option[] { return CRYPTOS; } - public get availableLanguages (): Options { + public get availableLanguages (): Option[] { return LANGUAGES; } - public get availableLocking (): Options { + public get availableLocking (): Option[] { return LOCKING; } - public get availablePrefixes (): Options { + public get availablePrefixes (): Option[] { return PREFIXES; } - public get availableUIModes (): Options { + public get availableUIModes (): Option[] { return UIMODES; } - public get availableUIThemes (): Options { + public get availableUIThemes (): Option[] { return UITHEMES; } diff --git a/packages/ui-settings/src/defaults.ts b/packages/ui-settings/src/defaults.ts deleted file mode 100644 index 322ef413..00000000 --- a/packages/ui-settings/src/defaults.ts +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright 2017-2019 @polkadot/ui-settings authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { Options } from './types'; - -// matches https://polkadot.js.org & https://*.polkadot.io -const isPolkadot = typeof window !== 'undefined' && window.location.host.includes('polkadot'); - -const WSS_NODES = { - parity: { - hosted: 'hosted by Parity', - nodes: { - alex: 'wss://poc3-rpc.polkadot.io/', - fir: 'wss://substrate-rpc.parity.io/', - kusama: 'wss://kusama-rpc.polkadot.io/' - } - }, - unfra: { - hosted: 'hosted by Centrality UNfrastructure', - nodes: { - alex: 'wss://alex.unfrastructure.io/public/ws' - } - }, - w3f: { - hosted: 'hosted by Web3 Foundation', - nodes: { - kusama: 'wss://canary-5.kusama.network/' - } - } -}; -const LANGUAGE_DEFAULT = 'default'; -const LOCKING_DEFAULT = 'session'; - -const CRYPTOS: Options = [ - { - info: 'ed25519', - text: 'Edwards (ed25519)', - value: 'ed25519' - }, - { - info: 'sr25519', - text: 'Schnorrkel (sr25519)', - value: 'sr25519' - } -]; - -const ENDPOINTS: Options = [ - { - info: 'kusama', - text: `Kusama (Polkadot Canary, ${WSS_NODES.parity.hosted})`, - value: WSS_NODES.parity.nodes.kusama - }, - { - info: 'kusama', - text: `Kusama (Polkadot Canary, ${WSS_NODES.w3f.hosted})`, - value: WSS_NODES.w3f.nodes.kusama - }, - { - info: 'alexander', - text: `Alexander (Polkadot Test, ${WSS_NODES.parity.hosted})`, - value: WSS_NODES.parity.nodes.alex - }, - { - info: 'alexander', - text: `Alexander (Polkadot Test, ${WSS_NODES.unfra.hosted})`, - value: WSS_NODES.unfra.nodes.alex - }, - { - info: 'substrate', - text: `Flaming Fir (Substrate Test, ${WSS_NODES.parity.hosted})`, - value: WSS_NODES.parity.nodes.fir - }, - { - info: 'local', - text: 'Local Node (127.0.0.1:9944)', - value: 'ws://127.0.0.1:9944/' - } -]; - -const LANGUAGES: Options = [ - { - info: 'detect', - text: 'Default browser language (auto-detect)', - value: LANGUAGE_DEFAULT - } -]; - -const LOCKING: Options = [ - { - info: 'session', - text: 'Once per session', - value: 'session' - }, - { - info: 'tx', - text: 'On each transaction', - value: 'tx' - } -]; - -const PREFIXES: Options = [ - { - info: 'default', - text: 'Default for the connected node', - value: -1 - }, - { - info: 'substrate', - text: 'Substrate (development)', - value: 42 - }, - { - info: 'kusama', - text: 'Kusama (canary)', - value: 2 - }, - { - info: 'polkadot', - text: 'Polkadot (live)', - value: 0 - } -]; - -const UIMODES: Options = [ - { - info: 'full', - text: 'Fully featured', - value: 'full' - }, - { - info: 'light', - text: 'Basic features only', - value: 'light' - } -]; - -const UITHEMES: Options = [ - { - info: 'polkadot', - text: 'Polkadot', - value: 'polkadot' - }, - { - info: 'substrate', - text: 'Substrate', - value: 'substrate' - } -]; - -const ENDPOINT_DEFAULT = isPolkadot - ? WSS_NODES.parity.nodes.kusama - : WSS_NODES.parity.nodes.fir; - -const PREFIX_DEFAULT = -1; - -const UITHEME_DEFAULT = isPolkadot - ? 'polkadot' - : 'substrate'; - -const UIMODE_DEFAULT = !isPolkadot && typeof window !== 'undefined' && window.location.host.includes('ui-light') - ? 'light' - : 'full'; - -export { - CRYPTOS, - ENDPOINT_DEFAULT, - ENDPOINTS, - LANGUAGE_DEFAULT, - LANGUAGES, - LOCKING_DEFAULT, - LOCKING, - PREFIX_DEFAULT, - PREFIXES, - UIMODE_DEFAULT, - UIMODES, - UITHEME_DEFAULT, - UITHEMES -}; diff --git a/packages/ui-settings/src/defaults/crypto.ts b/packages/ui-settings/src/defaults/crypto.ts new file mode 100644 index 00000000..4618256b --- /dev/null +++ b/packages/ui-settings/src/defaults/crypto.ts @@ -0,0 +1,18 @@ +// Copyright 2017-2019 @polkadot/ui-settings authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { Option } from '../types'; + +export const CRYPTOS: Option[] = [ + { + info: 'ed25519', + text: 'Edwards (ed25519)', + value: 'ed25519' + }, + { + info: 'sr25519', + text: 'Schnorrkel (sr25519)', + value: 'sr25519' + } +]; diff --git a/packages/ui-settings/src/defaults/endpoints.ts b/packages/ui-settings/src/defaults/endpoints.ts new file mode 100644 index 00000000..dcb76da7 --- /dev/null +++ b/packages/ui-settings/src/defaults/endpoints.ts @@ -0,0 +1,112 @@ +// Copyright 2017-2019 @polkadot/ui-settings authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { Option } from '../types'; + +import { isPolkadot } from './type'; + +type ChainName = 'alexander' | 'edgewareTest' | 'flamingFir' | 'kusama'; + +interface ChainData { + chainDisplay: string; + logo: 'alexander' | 'edgeware' | 'kusama' | 'polkadot' | 'substrate'; + type: string; +} + +type ProviderName = 'commonwealth' | 'parity' | 'unfrastructure' | 'w3f'; + +interface PoviderData { + providerDisplay: string; + nodes: Partial>; +} + +// we use this to give an ordering to the chains available +const ORDER_CHAINS: ChainName[] = ['kusama', 'alexander', 'edgewareTest', 'flamingFir']; + +// we use this to order the providers inside the chains +const ORDER_PROVIDERS: ProviderName[] = ['parity', 'w3f', 'unfrastructure', 'commonwealth']; + +// some suplementary info on a per-chain basis +const CHAIN_INFO: Record = { + alexander: { + chainDisplay: 'Alexander', + logo: 'alexander', + type: 'Polkadot Test' + }, + edgewareTest: { + chainDisplay: 'Edgeware Testnet', + logo: 'edgeware', + type: 'Edgeware Test' + }, + flamingFir: { + chainDisplay: 'Flaming Fir', + logo: 'substrate', + type: 'Substrate Test' + }, + kusama: { + chainDisplay: 'Kusama CC1', + logo: 'kusama', + type: 'Polkadot Canary' + } +}; + +// the actual providers with all the nodes they provide +const PROVIDERS: Record = { + commonwealth: { + providerDisplay: 'Commonwealth Labs', + nodes: { + edgewareTest: 'wss://testnet2.edgewa.re' + } + }, + parity: { + providerDisplay: 'Parity', + nodes: { + alexander: 'wss://poc3-rpc.polkadot.io/', + flamingFir: 'wss://substrate-rpc.parity.io/', + kusama: 'wss://kusama-rpc.polkadot.io/' + } + }, + unfrastructure: { + providerDisplay: 'Centrality UNfrastructure', + nodes: { + alexander: 'wss://alex.unfrastructure.io/public/ws' + } + }, + w3f: { + providerDisplay: 'Web3 Foundation', + nodes: { + kusama: 'wss://canary-5.kusama.network/' + } + } +}; + +export const ENDPOINT_DEFAULT = isPolkadot + ? PROVIDERS.parity.nodes.kusama + : PROVIDERS.parity.nodes.flamingFir; + +export const ENDPOINTS: Option[] = ORDER_CHAINS.reduce((endpoints: Option[], chainName): Option[] => { + const { chainDisplay, logo, type } = CHAIN_INFO[chainName]; + + return ORDER_PROVIDERS.reduce((endpoints: Option[], providerName): Option[] => { + const { providerDisplay, nodes } = PROVIDERS[providerName]; + const wssUrl = nodes[chainName]; + + if (wssUrl) { + endpoints.push({ + info: logo, + text: `${chainDisplay} (${type}, hosted by ${providerDisplay}}`, + value: wssUrl + }); + } + + return endpoints; + }, endpoints); +}, []); + +// add a local node right at the end +ENDPOINTS.push({ + info: 'local', + text: 'Local Node (Any, 127.0.0.1:9944)', + value: 'ws://127.0.0.1:9944/' +}); diff --git a/packages/ui-settings/src/defaults/index.ts b/packages/ui-settings/src/defaults/index.ts new file mode 100644 index 00000000..c4741122 --- /dev/null +++ b/packages/ui-settings/src/defaults/index.ts @@ -0,0 +1,85 @@ +// Copyright 2017-2019 @polkadot/ui-settings authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { Option } from '../types'; + +import { CRYPTOS } from './crypto'; +import { ENDPOINTS, ENDPOINT_DEFAULT } from './endpoints'; +import { PREFIXES, PREFIX_DEFAULT } from './ss58'; +import { isPolkadot } from './type'; + +const LANGUAGE_DEFAULT = 'default'; + +const LANGUAGES: Option[] = [ + { + info: 'detect', + text: 'Default browser language (auto-detect)', + value: LANGUAGE_DEFAULT + } +]; + +const LOCKING_DEFAULT = 'session'; + +const LOCKING: Option[] = [ + { + info: 'session', + text: 'Once per session', + value: 'session' + }, + { + info: 'tx', + text: 'On each transaction', + value: 'tx' + } +]; + +const UIMODE_DEFAULT = !isPolkadot && typeof window !== 'undefined' && window.location.host.includes('ui-light') + ? 'light' + : 'full'; + +const UIMODES: Option[] = [ + { + info: 'full', + text: 'Fully featured', + value: 'full' + }, + { + info: 'light', + text: 'Basic features only', + value: 'light' + } +]; + +const UITHEME_DEFAULT = isPolkadot + ? 'polkadot' + : 'substrate'; + +const UITHEMES: Option[] = [ + { + info: 'polkadot', + text: 'Polkadot', + value: 'polkadot' + }, + { + info: 'substrate', + text: 'Substrate', + value: 'substrate' + } +]; + +export { + CRYPTOS, + ENDPOINT_DEFAULT, + ENDPOINTS, + LANGUAGE_DEFAULT, + LANGUAGES, + LOCKING_DEFAULT, + LOCKING, + PREFIX_DEFAULT, + PREFIXES, + UIMODE_DEFAULT, + UIMODES, + UITHEME_DEFAULT, + UITHEMES +}; diff --git a/packages/ui-settings/src/defaults/ss58.ts b/packages/ui-settings/src/defaults/ss58.ts new file mode 100644 index 00000000..3abf3c69 --- /dev/null +++ b/packages/ui-settings/src/defaults/ss58.ts @@ -0,0 +1,30 @@ +// Copyright 2017-2019 @polkadot/ui-settings authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { Option } from '../types'; + +export const PREFIX_DEFAULT = -1; + +export const PREFIXES: Option[] = [ + { + info: 'default', + text: 'Default for the connected node', + value: -1 + }, + { + info: 'substrate', + text: 'Substrate (development)', + value: 42 + }, + { + info: 'kusama', + text: 'Kusama (canary)', + value: 2 + }, + { + info: 'polkadot', + text: 'Polkadot (live)', + value: 0 + } +]; diff --git a/packages/ui-settings/src/defaults/type.ts b/packages/ui-settings/src/defaults/type.ts new file mode 100644 index 00000000..0c09a39e --- /dev/null +++ b/packages/ui-settings/src/defaults/type.ts @@ -0,0 +1,6 @@ +// Copyright 2017-2019 @polkadot/ui-settings authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +// matches https://polkadot.js.org & https://*.polkadot.io +export const isPolkadot = typeof window !== 'undefined' && window.location.host.includes('polkadot'); diff --git a/packages/ui-settings/src/types.ts b/packages/ui-settings/src/types.ts index a8ff357a..4d7d7dbc 100644 --- a/packages/ui-settings/src/types.ts +++ b/packages/ui-settings/src/types.ts @@ -2,12 +2,12 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -export type Options = { +export type Option = { disabled?: boolean; info: string; text: string; value: string | number; -}[] +} export interface SettingsStruct { apiUrl: string;