Set UI defaults based on environment (#86)

* Bump deps

* Set defaults based on hosted environment

* Update tests (package bumps)

* Do location detection on 'polkadot'
This commit is contained in:
Jaco Greeff
2019-02-28 14:40:59 +01:00
committed by GitHub
parent b74f8de6ff
commit 0dbdc7e0b7
11 changed files with 546 additions and 904 deletions
+5 -5
View File
@@ -4,7 +4,7 @@
import store from 'store';
import { ENDPOINTS, LANGUAGES, UIMODES, UITHEMES } from './defaults';
import { ENDPOINT_DEFAULT, ENDPOINTS, LANGUAGE_DEFAULT, LANGUAGES, UIMODE_DEFAULT, UIMODES, UITHEME_DEFAULT, UITHEMES } from './defaults';
import { Options, SettingsStruct } from './types';
export class Settings implements SettingsStruct {
@@ -16,10 +16,10 @@ export class Settings implements SettingsStruct {
constructor () {
const settings = store.get('settings') || {};
this._apiUrl = settings.apiUrl || process.env.WS_URL || ENDPOINTS[0].value;
this._i18nLang = settings.i18nLang || LANGUAGES[0].value;
this._uiMode = settings.uiMode || process.env.UI_MODE || UIMODES[0].value;
this._uiTheme = settings.uiTheme || process.env.UI_THEME || UITHEMES[0].value;
this._apiUrl = settings.apiUrl || process.env.WS_URL || ENDPOINT_DEFAULT;
this._i18nLang = settings.i18nLang || LANGUAGE_DEFAULT;
this._uiMode = settings.uiMode || process.env.UI_MODE || UIMODE_DEFAULT;
this._uiTheme = settings.uiTheme || process.env.UI_THEME || UITHEME_DEFAULT;
}
get apiUrl (): string {
+26 -3
View File
@@ -4,14 +4,21 @@
import { Options } from './types';
// matches https://polkadot.js.org & https://poc-3.polkadot.io
const isPolkadot = window.location.host.indexOf('polkadot') !== -1;
const WSS_POLKADOT = 'wss://poc3-rpc.polkadot.io/';
const WSS_SUBSTRATE = 'wss://substrate-rpc.parity.io/';
const LANGUAGE_DEFAULT = 'default';
const ENDPOINTS: Options = [
{ text: 'Alexander (Polkadot, hosted by Parity)', value: 'wss://poc3-rpc.polkadot.io/' },
{ text: 'Dried Danta (Substrate, hosted by Parity)', value: 'wss://substrate-rpc.parity.io/' },
{ text: 'Alexander (Polkadot, hosted by Parity)', value: WSS_POLKADOT },
{ text: 'Dried Danta (Substrate, hosted by Parity)', value: WSS_SUBSTRATE },
{ text: 'Local Node (127.0.0.1:9944)', value: 'ws://127.0.0.1:9944/' }
];
const LANGUAGES: Options = [
{ value: 'default', text: 'Default browser language (auto-detect)' }
{ value: LANGUAGE_DEFAULT, text: 'Default browser language (auto-detect)' }
];
const UIMODES: Options = [
@@ -24,9 +31,25 @@ const UITHEMES: Options = [
{ value: 'substrate', text: 'Substrate' }
];
const ENDPOINT_DEFAULT = isPolkadot
? WSS_POLKADOT
: WSS_SUBSTRATE;
const UITHEME_DEFAULT = isPolkadot
? 'polkadot'
: 'substrate';
const UIMODE_DEFAULT = !isPolkadot && window.location.host.indexOf('ui-light') !== -1
? 'light'
: 'full';
export {
ENDPOINT_DEFAULT,
ENDPOINTS,
LANGUAGE_DEFAULT,
LANGUAGES,
UIMODE_DEFAULT,
UIMODES,
UITHEME_DEFAULT,
UITHEMES
};