mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-05-30 05:51: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 CopyToClipboard from 'react-copy-to-clipboard';
|
||||
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 { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
@@ -29,6 +29,7 @@ const Components: Record<string, React.ComponentType<ComponentProps>> = {
|
||||
polkadot: Polkadot,
|
||||
substrate: Jdenticon
|
||||
};
|
||||
|
||||
const Wrapper = styled.div`
|
||||
cursor: copy;
|
||||
display: inline-block;
|
||||
@@ -109,10 +110,10 @@ export default class IdentityIcon extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
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
|
||||
? Empty
|
||||
: Components[theme] || Fallback;
|
||||
: Components[theme === 'default' ? ICON_DEFAULT : theme] || Fallback;
|
||||
|
||||
return (
|
||||
<Wrapper
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^1.4.1",
|
||||
"@polkadot/types": "^0.92.1",
|
||||
"@polkadot/types": "^0.93.0-beta.0",
|
||||
"@polkadot/util": "^1.4.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ export type Option = {
|
||||
export interface SettingsStruct {
|
||||
apiUrl: string;
|
||||
i18nLang: string;
|
||||
icon: string;
|
||||
locking: string;
|
||||
prefix: number;
|
||||
uiMode: string;
|
||||
|
||||
@@ -2099,10 +2099,10 @@
|
||||
dependencies:
|
||||
"@types/chrome" "^0.0.88"
|
||||
|
||||
"@polkadot/types@^0.92.1":
|
||||
version "0.92.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.92.1.tgz#18de5809fc91c22c72db097d70aabe76ec9215bc"
|
||||
integrity sha512-LLutXpwxX9PkHK2wQBWR5lh2nCceiLMwFBYG97uM/SYEpMfwRt0kjKIc/8ISwiewYtH03hXA8AmFa4NB2PyuSA==
|
||||
"@polkadot/types@^0.93.0-beta.0":
|
||||
version "0.93.0-beta.0"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.93.0-beta.0.tgz#e778020ccd5ca211901a7893f4b6dd34a966d618"
|
||||
integrity sha512-tj4FdIq5HwTN3KfBHTz4U0WjxdD5TrYyxH2iulcubFV5sAgBuYyZy5fGdGmY/K87oUP/viBplMl94Yn67+aBZg==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.6.0"
|
||||
"@polkadot/util" "^1.4.1"
|
||||
|
||||
Reference in New Issue
Block a user