From 3f253ddbe178df5657f619e479895a837990288f Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 13 Sep 2019 13:58:26 +0200 Subject: [PATCH] Settings for icon (#206) --- packages/react-identicon/src/Identicon.tsx | 7 +- packages/ui-keyring/package.json | 2 +- packages/ui-settings/src/Settings.ts | 23 +++++-- packages/ui-settings/src/defaults/index.ts | 38 +--------- packages/ui-settings/src/defaults/ui.ts | 80 ++++++++++++++++++++++ packages/ui-settings/src/index.ts | 1 + packages/ui-settings/src/types.ts | 1 + yarn.lock | 8 +-- 8 files changed, 112 insertions(+), 48 deletions(-) create mode 100644 packages/ui-settings/src/defaults/ui.ts diff --git a/packages/react-identicon/src/Identicon.tsx b/packages/react-identicon/src/Identicon.tsx index 65782296..57ad9a92 100644 --- a/packages/react-identicon/src/Identicon.tsx +++ b/packages/react-identicon/src/Identicon.tsx @@ -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> = { polkadot: Polkadot, substrate: Jdenticon }; + const Wrapper = styled.div` cursor: copy; display: inline-block; @@ -109,10 +110,10 @@ export default class IdentityIcon extends React.PureComponent { } 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 ( ): 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; diff --git a/packages/ui-settings/src/defaults/index.ts b/packages/ui-settings/src/defaults/index.ts index c4741122..18119814 100644 --- a/packages/ui-settings/src/defaults/index.ts +++ b/packages/ui-settings/src/defaults/index.ts @@ -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, diff --git a/packages/ui-settings/src/defaults/ui.ts b/packages/ui-settings/src/defaults/ui.ts new file mode 100644 index 00000000..2d93efc1 --- /dev/null +++ b/packages/ui-settings/src/defaults/ui.ts @@ -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 +}; diff --git a/packages/ui-settings/src/index.ts b/packages/ui-settings/src/index.ts index 45a92c52..f4bbd024 100644 --- a/packages/ui-settings/src/index.ts +++ b/packages/ui-settings/src/index.ts @@ -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; diff --git a/packages/ui-settings/src/types.ts b/packages/ui-settings/src/types.ts index 4d7d7dbc..2dfa19ba 100644 --- a/packages/ui-settings/src/types.ts +++ b/packages/ui-settings/src/types.ts @@ -12,6 +12,7 @@ export type Option = { export interface SettingsStruct { apiUrl: string; i18nLang: string; + icon: string; locking: string; prefix: number; uiMode: string; diff --git a/yarn.lock b/yarn.lock index 15d5d1ed..86f445e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"