mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-05-30 07:01:04 +00:00
Settings for icon (#206)
This commit is contained in:
@@ -8,7 +8,7 @@ import { IdentityProps as Props, Props as ComponentProps } from './types';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import settings from '@polkadot/ui-settings';
|
import settings, { ICON_DEFAULT } from '@polkadot/ui-settings';
|
||||||
import { isHex, isU8a, u8aToHex } from '@polkadot/util';
|
import { isHex, isU8a, u8aToHex } from '@polkadot/util';
|
||||||
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
|
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ const Components: Record<string, React.ComponentType<ComponentProps>> = {
|
|||||||
polkadot: Polkadot,
|
polkadot: Polkadot,
|
||||||
substrate: Jdenticon
|
substrate: Jdenticon
|
||||||
};
|
};
|
||||||
|
|
||||||
const Wrapper = styled.div`
|
const Wrapper = styled.div`
|
||||||
cursor: copy;
|
cursor: copy;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@@ -109,10 +110,10 @@ export default class IdentityIcon extends React.PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getWrapped ({ address, publicKey }: State): React.ReactNode {
|
private getWrapped ({ address, publicKey }: State): React.ReactNode {
|
||||||
const { className, isHighlight = false, size = DEFAULT_SIZE, style, theme = settings.uiTheme } = this.props;
|
const { className, isHighlight = false, size = DEFAULT_SIZE, style, theme = settings.icon } = this.props;
|
||||||
const Component = !address
|
const Component = !address
|
||||||
? Empty
|
? Empty
|
||||||
: Components[theme] || Fallback;
|
: Components[theme === 'default' ? ICON_DEFAULT : theme] || Fallback;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/keyring": "^1.4.1",
|
"@polkadot/keyring": "^1.4.1",
|
||||||
"@polkadot/types": "^0.92.1",
|
"@polkadot/types": "^0.93.0-beta.0",
|
||||||
"@polkadot/util": "^1.4.1"
|
"@polkadot/util": "^1.4.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import store from 'store';
|
import store from 'store';
|
||||||
import { isUndefined } from '@polkadot/util';
|
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';
|
import { Option, SettingsStruct } from './types';
|
||||||
|
|
||||||
export class Settings implements SettingsStruct {
|
export class Settings implements SettingsStruct {
|
||||||
@@ -13,6 +13,8 @@ export class Settings implements SettingsStruct {
|
|||||||
|
|
||||||
private _i18nLang: string;
|
private _i18nLang: string;
|
||||||
|
|
||||||
|
private _icon: string;
|
||||||
|
|
||||||
private _locking: string;
|
private _locking: string;
|
||||||
|
|
||||||
private _prefix: number;
|
private _prefix: number;
|
||||||
@@ -26,6 +28,7 @@ export class Settings implements SettingsStruct {
|
|||||||
|
|
||||||
this._apiUrl = settings.apiUrl || process.env.WS_URL || ENDPOINT_DEFAULT;
|
this._apiUrl = settings.apiUrl || process.env.WS_URL || ENDPOINT_DEFAULT;
|
||||||
this._i18nLang = settings.i18nLang || LANGUAGE_DEFAULT;
|
this._i18nLang = settings.i18nLang || LANGUAGE_DEFAULT;
|
||||||
|
this._icon = settings.icon || ICON_DEFAULT;
|
||||||
this._locking = settings.locking || LOCKING_DEFAULT;
|
this._locking = settings.locking || LOCKING_DEFAULT;
|
||||||
this._prefix = isUndefined(settings.prefix) ? PREFIX_DEFAULT : settings.prefix;
|
this._prefix = isUndefined(settings.prefix) ? PREFIX_DEFAULT : settings.prefix;
|
||||||
this._uiMode = settings.uiMode || UIMODE_DEFAULT;
|
this._uiMode = settings.uiMode || UIMODE_DEFAULT;
|
||||||
@@ -40,6 +43,10 @@ export class Settings implements SettingsStruct {
|
|||||||
return this._i18nLang;
|
return this._i18nLang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get icon (): string {
|
||||||
|
return this._icon;
|
||||||
|
}
|
||||||
|
|
||||||
public get locking (): string {
|
public get locking (): string {
|
||||||
return this._locking;
|
return this._locking;
|
||||||
}
|
}
|
||||||
@@ -56,14 +63,14 @@ export class Settings implements SettingsStruct {
|
|||||||
return this._uiTheme;
|
return this._uiTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get availableNodes (): Option[] {
|
|
||||||
return ENDPOINTS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get availableCryptos (): Option[] {
|
public get availableCryptos (): Option[] {
|
||||||
return CRYPTOS;
|
return CRYPTOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get availableIcons (): Option[] {
|
||||||
|
return ICONS;
|
||||||
|
}
|
||||||
|
|
||||||
public get availableLanguages (): Option[] {
|
public get availableLanguages (): Option[] {
|
||||||
return LANGUAGES;
|
return LANGUAGES;
|
||||||
}
|
}
|
||||||
@@ -72,6 +79,10 @@ export class Settings implements SettingsStruct {
|
|||||||
return LOCKING;
|
return LOCKING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get availableNodes (): Option[] {
|
||||||
|
return ENDPOINTS;
|
||||||
|
}
|
||||||
|
|
||||||
public get availablePrefixes (): Option[] {
|
public get availablePrefixes (): Option[] {
|
||||||
return PREFIXES;
|
return PREFIXES;
|
||||||
}
|
}
|
||||||
@@ -88,6 +99,7 @@ export class Settings implements SettingsStruct {
|
|||||||
return {
|
return {
|
||||||
apiUrl: this._apiUrl,
|
apiUrl: this._apiUrl,
|
||||||
i18nLang: this._i18nLang,
|
i18nLang: this._i18nLang,
|
||||||
|
icon: this._icon,
|
||||||
locking: this._locking,
|
locking: this._locking,
|
||||||
prefix: this._prefix,
|
prefix: this._prefix,
|
||||||
uiMode: this._uiMode,
|
uiMode: this._uiMode,
|
||||||
@@ -98,6 +110,7 @@ export class Settings implements SettingsStruct {
|
|||||||
public set (settings: Partial<SettingsStruct>): void {
|
public set (settings: Partial<SettingsStruct>): void {
|
||||||
this._apiUrl = settings.apiUrl || this._apiUrl;
|
this._apiUrl = settings.apiUrl || this._apiUrl;
|
||||||
this._i18nLang = settings.i18nLang || this._i18nLang;
|
this._i18nLang = settings.i18nLang || this._i18nLang;
|
||||||
|
this._icon = settings.icon || this._icon;
|
||||||
this._locking = settings.locking || this._locking;
|
this._locking = settings.locking || this._locking;
|
||||||
this._prefix = isUndefined(settings.prefix) ? this._prefix : settings.prefix;
|
this._prefix = isUndefined(settings.prefix) ? this._prefix : settings.prefix;
|
||||||
this._uiMode = settings.uiMode || this._uiMode;
|
this._uiMode = settings.uiMode || this._uiMode;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { Option } from '../types';
|
|||||||
import { CRYPTOS } from './crypto';
|
import { CRYPTOS } from './crypto';
|
||||||
import { ENDPOINTS, ENDPOINT_DEFAULT } from './endpoints';
|
import { ENDPOINTS, ENDPOINT_DEFAULT } from './endpoints';
|
||||||
import { PREFIXES, PREFIX_DEFAULT } from './ss58';
|
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';
|
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 {
|
export {
|
||||||
CRYPTOS,
|
CRYPTOS,
|
||||||
ENDPOINT_DEFAULT,
|
ENDPOINT_DEFAULT,
|
||||||
ENDPOINTS,
|
ENDPOINTS,
|
||||||
|
ICON_DEFAULT,
|
||||||
|
ICONS,
|
||||||
LANGUAGE_DEFAULT,
|
LANGUAGE_DEFAULT,
|
||||||
LANGUAGES,
|
LANGUAGES,
|
||||||
LOCKING_DEFAULT,
|
LOCKING_DEFAULT,
|
||||||
|
|||||||
@@ -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
|
||||||
|
};
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import settings, { Settings } from './Settings';
|
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;
|
export default settings;
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export type Option = {
|
|||||||
export interface SettingsStruct {
|
export interface SettingsStruct {
|
||||||
apiUrl: string;
|
apiUrl: string;
|
||||||
i18nLang: string;
|
i18nLang: string;
|
||||||
|
icon: string;
|
||||||
locking: string;
|
locking: string;
|
||||||
prefix: number;
|
prefix: number;
|
||||||
uiMode: string;
|
uiMode: string;
|
||||||
|
|||||||
@@ -2099,10 +2099,10 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@types/chrome" "^0.0.88"
|
"@types/chrome" "^0.0.88"
|
||||||
|
|
||||||
"@polkadot/types@^0.92.1":
|
"@polkadot/types@^0.93.0-beta.0":
|
||||||
version "0.92.1"
|
version "0.93.0-beta.0"
|
||||||
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.92.1.tgz#18de5809fc91c22c72db097d70aabe76ec9215bc"
|
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.93.0-beta.0.tgz#e778020ccd5ca211901a7893f4b6dd34a966d618"
|
||||||
integrity sha512-LLutXpwxX9PkHK2wQBWR5lh2nCceiLMwFBYG97uM/SYEpMfwRt0kjKIc/8ISwiewYtH03hXA8AmFa4NB2PyuSA==
|
integrity sha512-tj4FdIq5HwTN3KfBHTz4U0WjxdD5TrYyxH2iulcubFV5sAgBuYyZy5fGdGmY/K87oUP/viBplMl94Yn67+aBZg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/runtime" "^7.6.0"
|
"@babel/runtime" "^7.6.0"
|
||||||
"@polkadot/util" "^1.4.1"
|
"@polkadot/util" "^1.4.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user