Settings for icon (#206)

This commit is contained in:
Jaco Greeff
2019-09-13 13:58:26 +02:00
committed by GitHub
parent 209cb4d815
commit 3f253ddbe1
8 changed files with 112 additions and 48 deletions
+18 -5
View File
@@ -5,7 +5,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 { CRYPTOS, ENDPOINT_DEFAULT, ENDPOINTS, ICON_DEFAULT, ICONS, LANGUAGE_DEFAULT, LANGUAGES, LOCKING_DEFAULT, LOCKING, PREFIX_DEFAULT, PREFIXES, UIMODE_DEFAULT, UIMODES, UITHEME_DEFAULT, UITHEMES } from './defaults';
import { Option, SettingsStruct } from './types';
export class Settings implements SettingsStruct {
@@ -13,6 +13,8 @@ export class Settings implements SettingsStruct {
private _i18nLang: string;
private _icon: string;
private _locking: string;
private _prefix: number;
@@ -26,6 +28,7 @@ export class Settings implements SettingsStruct {
this._apiUrl = settings.apiUrl || process.env.WS_URL || ENDPOINT_DEFAULT;
this._i18nLang = settings.i18nLang || LANGUAGE_DEFAULT;
this._icon = settings.icon || ICON_DEFAULT;
this._locking = settings.locking || LOCKING_DEFAULT;
this._prefix = isUndefined(settings.prefix) ? PREFIX_DEFAULT : settings.prefix;
this._uiMode = settings.uiMode || UIMODE_DEFAULT;
@@ -40,6 +43,10 @@ export class Settings implements SettingsStruct {
return this._i18nLang;
}
public get icon (): string {
return this._icon;
}
public get locking (): string {
return this._locking;
}
@@ -56,14 +63,14 @@ export class Settings implements SettingsStruct {
return this._uiTheme;
}
public get availableNodes (): Option[] {
return ENDPOINTS;
}
public get availableCryptos (): Option[] {
return CRYPTOS;
}
public get availableIcons (): Option[] {
return ICONS;
}
public get availableLanguages (): Option[] {
return LANGUAGES;
}
@@ -72,6 +79,10 @@ export class Settings implements SettingsStruct {
return LOCKING;
}
public get availableNodes (): Option[] {
return ENDPOINTS;
}
public get availablePrefixes (): Option[] {
return PREFIXES;
}
@@ -88,6 +99,7 @@ export class Settings implements SettingsStruct {
return {
apiUrl: this._apiUrl,
i18nLang: this._i18nLang,
icon: this._icon,
locking: this._locking,
prefix: this._prefix,
uiMode: this._uiMode,
@@ -98,6 +110,7 @@ export class Settings implements SettingsStruct {
public set (settings: Partial<SettingsStruct>): void {
this._apiUrl = settings.apiUrl || this._apiUrl;
this._i18nLang = settings.i18nLang || this._i18nLang;
this._icon = settings.icon || this._icon;
this._locking = settings.locking || this._locking;
this._prefix = isUndefined(settings.prefix) ? this._prefix : settings.prefix;
this._uiMode = settings.uiMode || this._uiMode;
+3 -35
View File
@@ -7,7 +7,7 @@ import { Option } from '../types';
import { CRYPTOS } from './crypto';
import { ENDPOINTS, ENDPOINT_DEFAULT } from './endpoints';
import { PREFIXES, PREFIX_DEFAULT } from './ss58';
import { isPolkadot } from './type';
import { ICON_DEFAULT, ICONS, UIMODE_DEFAULT, UIMODES, UITHEME_DEFAULT, UITHEMES } from './ui';
const LANGUAGE_DEFAULT = 'default';
@@ -34,44 +34,12 @@ const LOCKING: Option[] = [
}
];
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,
ICON_DEFAULT,
ICONS,
LANGUAGE_DEFAULT,
LANGUAGES,
LOCKING_DEFAULT,
+80
View File
@@ -0,0 +1,80 @@
// 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';
const LANGUAGE_DEFAULT = 'default';
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'
}
];
const ICON_DEFAULT = isPolkadot
? 'polkadot'
: 'substrate';
const ICONS: Option[] = [
{
info: 'default',
text: 'Default for the connected node',
value: -1
},
{
info: 'polkadot',
text: 'Polkadot',
value: 'polkadot'
},
{
info: 'substrate',
text: 'Substrate',
value: 'substrate'
},
{
info: 'beachball',
text: 'Beachball',
value: 'beachball'
}
];
export {
ICON_DEFAULT,
ICONS,
LANGUAGE_DEFAULT,
UIMODE_DEFAULT,
UIMODES,
UITHEME_DEFAULT,
UITHEMES
};
+1
View File
@@ -3,6 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import settings, { Settings } from './Settings';
export { ENDPOINT_DEFAULT, ICON_DEFAULT, LANGUAGE_DEFAULT, LOCKING_DEFAULT, PREFIX_DEFAULT, UIMODE_DEFAULT, UITHEME_DEFAULT } from './defaults';
export default settings;
+1
View File
@@ -12,6 +12,7 @@ export type Option = {
export interface SettingsStruct {
apiUrl: string;
i18nLang: string;
icon: string;
locking: string;
prefix: number;
uiMode: string;