diff --git a/packages/app-settings/src/index.css b/packages/app-settings/src/index.css index e9a45aff0b..fa0670c8b8 100644 --- a/packages/app-settings/src/index.css +++ b/packages/app-settings/src/index.css @@ -1,3 +1,11 @@ /* Copyright 2017-2019 @polkadot/app-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. */ + +.sub-label { + padding: 0em .5833em; + font-size: .85714286rem; + position: absolute; + right: .5833em; + +} \ No newline at end of file diff --git a/packages/app-settings/src/index.tsx b/packages/app-settings/src/index.tsx index ebdecacd54..b5b5aa0157 100644 --- a/packages/app-settings/src/index.tsx +++ b/packages/app-settings/src/index.tsx @@ -8,7 +8,7 @@ import { SettingsStruct } from '@polkadot/ui-settings/types'; import React from 'react'; import store from 'store'; import typeRegistry from '@polkadot/types/codec/typeRegistry'; -import { Button, Dropdown, InputFile } from '@polkadot/ui-app/index'; +import { Button, Dropdown, Input, InputFile } from '@polkadot/ui-app/index'; import settings from '@polkadot/ui-settings'; import { u8aToString } from '@polkadot/util'; @@ -22,7 +22,8 @@ type State = { settings: SettingsStruct & { types?: { [index: string]: any } | null, typesError?: boolean, - typesPlaceholder?: string + typesPlaceholder?: string, + customNode: boolean } }; @@ -34,33 +35,63 @@ class App extends React.PureComponent { const names = Object.keys(types); const presets = settings.get(); + // check to see if user has saved a custom node by seeing if their URL is equal to any preset + let customNode = true; + for (let i = 0; i < settings.availableNodes.length; i++) { + if (settings.availableNodes[i].value === presets.apiUrl) { + customNode = false; + } + } + this.state = { settings: { ...presets, typesPlaceholder: names.length ? names.join(', ') - : undefined + : undefined, + customNode: customNode } }; } render () { const { t } = this.props; - const { settings: { apiUrl, i18nLang, typesPlaceholder, typesError, uiMode, uiTheme } } = this.state; + const { settings: { apiUrl, i18nLang, typesPlaceholder, typesError, uiMode, uiTheme, customNode } } = this.state; return (

{t('general')}

-
- -
+ { + customNode + ? +
+
+ pre-set +   | custom +
+ +
+ : +
+
+ pre-set +  | custom +
+ +
+ } +
@@ -91,6 +122,7 @@ class App extends React.PureComponent { />
+

{t('developer')}

@@ -178,9 +210,40 @@ class App extends React.PureComponent { })); } + private toggleCustomNode = (): void => { + this.setState(({ settings }: State) => ({ + settings: { + ...settings, + /*flip the value of customNode*/ + customNode: settings.customNode ? + false + : + true + } + })); + } + private save = (): void => { + const { onStatusChange } = this.props; const { settings: { types, typesError } } = this.state; + // validate custom node url + const apiUrl = this.state.settings.apiUrl; + + if (this.state.settings.customNode) { + if (!(apiUrl.startsWith('ws://localhost') || + apiUrl.startsWith('ws://127.0.0.1') || + apiUrl.startsWith('wss://'))) { + onStatusChange({ + action: '', + status: 'error', + message: 'Custom node URL is not valid (must start with wss://, ' + + 'or ws:// if node is hosted on localhost)' + }); + return; + } + } + settings.set(this.state.settings); if (types && !typesError) {