Initial add from apps

This commit is contained in:
Jaco Greeff
2018-12-05 11:35:28 +01:00
commit 21c47a7d3a
79 changed files with 15785 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
// Copyright 2017-2018 @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 { ChainsInfo, Options } from './types';
const CHAINS: ChainsInfo = [
{
name: 'Development',
chainId: 0,
decimals: 0,
unit: 'Unit'
},
{
name: 'Local Testnet',
chainId: 0,
decimals: 0,
unit: 'Unit'
},
{
name: 'BBQ Birch',
chainId: 68,
decimals: 15,
unit: 'BBQ'
}
];
const ENDPOINTS: Options = [
{ text: 'BBQ Birch (hosted by Parity)', value: 'wss://substrate-rpc.parity.io/' },
{ disabled: true, text: 'Polkadot PoC-3 (hosted by Parity)', value: 'wss://polkadot-rpc.polkadot.io/' },
{ 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)' }
];
const UIMODES: Options = [
{ value: 'full', text: 'Fully featured' },
{ value: 'light', text: 'Basic features only' }
];
const UITHEMES: Options = [
{ value: 'substrate', text: 'Substrate' },
{ value: 'polkadot', text: 'Polkadot' }
];
export {
CHAINS,
ENDPOINTS,
LANGUAGES,
UIMODES,
UITHEMES
};
+84
View File
@@ -0,0 +1,84 @@
// Copyright 2017-2018 @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 store from 'store';
import { CHAINS, ENDPOINTS, LANGUAGES, UIMODES, UITHEMES } from './defaults';
import { ChainsInfo, Options, SettingsStruct } from './types';
class Settings implements SettingsStruct {
private _apiUrl: string;
private _i18nLang: string;
private _uiMode: string;
private _uiTheme: string;
constructor () {
const settings = store.get('settings') || {};
// FIXME Here we have the defaults for BBQ, swap to Polkadot as soon as poc-3 is there
// FIXME WS_URL first, then substrate-rpc
this._apiUrl = settings.apiUrl || ENDPOINTS[0].value || process.env.WS_URL;
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;
}
get apiUrl (): string {
return this._apiUrl;
}
get i18nLang (): string {
return this._i18nLang;
}
get uiMode (): string {
return this._uiMode;
}
get uiTheme (): string {
return this._uiTheme;
}
get availableChains (): ChainsInfo {
return CHAINS;
}
get availableNodes (): Options {
return ENDPOINTS;
}
get availableLanguages (): Options {
return LANGUAGES;
}
get availableUIModes (): Options {
return UIMODES;
}
get availableUIThemes (): Options {
return UITHEMES;
}
get (): SettingsStruct {
return {
apiUrl: this._apiUrl,
i18nLang: this._i18nLang,
uiMode: this._uiMode,
uiTheme: this._uiTheme
};
}
set (settings: Partial<SettingsStruct>): void {
this._apiUrl = settings.apiUrl || this._apiUrl;
this._i18nLang = settings.i18nLang || this._i18nLang;
this._uiMode = settings.uiMode || this._uiMode;
this._uiTheme = settings.uiTheme || this._uiTheme;
store.set('settings', this.get());
}
}
const settings = new Settings();
export default settings;
+23
View File
@@ -0,0 +1,23 @@
// Copyright 2017-2018 @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.
export type ChainsInfo = Array<{
name: string,
chainId: number,
decimals: number,
unit: string
}>;
export type Options = Array<{
disabled?: boolean,
text: string,
value: string
}>;
export interface SettingsStruct {
apiUrl: string;
i18nLang: string;
uiMode: string;
uiTheme: string;
}