Skip to content

Commit

Permalink
add node selection
Browse files Browse the repository at this point in the history
  • Loading branch information
backslash47 committed Jan 24, 2019
1 parent eec2575 commit a8454b0
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "cyano-wallet",
"version": "0.7.7",
"version": "0.7.8",
"private": true,
"scripts": {
"lint": "tslint -p .",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Expand Up @@ -4,7 +4,7 @@
"name": "Cyano wallet",
"author": "Matus Zamborsky <zamborsky@gmail.com>",
"description": "Cyano wallet - an Ontology wallet",
"version": "0.7.7",
"version": "0.7.8",

"browser_action": {
"default_title": "Open the wallet"
Expand Down
41 changes: 41 additions & 0 deletions src/api/constants.ts
@@ -0,0 +1,41 @@
export const testOptions: Array<{ text: string; value: string }> = [
{
text: 'polaris1.ont.io',
value: 'polaris1.ont.io',
},
{
text: 'polaris2.ont.io',
value: 'polaris2.ont.io',
},
{
text: 'polaris3.ont.io',
value: 'polaris3.ont.io',
},
{
text: 'polaris4.ont.io',
value: 'polaris4.ont.io',
},
{
text: 'polaris5.ont.io',
value: 'polaris5.ont.io',
},
];

export const prodOptions: Array<{ text: string; value: string }> = [
{
text: 'dappnode1.ont.io',
value: 'dappnode1.ont.io',
},
{
text: 'dappnode2.ont.io',
value: 'dappnode2.ont.io',
},
{
text: 'dappnode3.ont.io',
value: 'dappnode3.ont.io',
},
{
text: 'dappnode4.ont.io',
value: 'dappnode4.ont.io',
},
];
33 changes: 32 additions & 1 deletion src/background/network.ts
Expand Up @@ -16,6 +16,7 @@
* along with The Ontology Wallet&ID. If not, see <http://www.gnu.org/licenses/>.
*/
import { CONST, WebsocketClient } from 'ontology-ts-sdk';
import { prodOptions, testOptions } from 'src/api/constants';
import Actions from '../redux/actions';
import { compareSettings, SettingsState } from '../redux/settings';
import { GlobalStore } from '../redux/state';
Expand Down Expand Up @@ -82,6 +83,14 @@ function constructUrl(s: SettingsState) {
}

function reconnect(s: SettingsState) {
if (client !== undefined) {
try {
client.close();
} catch (e) {
// ignored
}
}

const url = constructUrl(s);
client = new WebsocketClient(url, false, false);
}
Expand All @@ -105,9 +114,19 @@ export function getExplorerAddress(): string | null {
export function getNodeAddress(): string | null {
if (settings == null) {
return null;
} else if (settings.net === 'MAIN') {
}

const address = settings.address;

if (settings.net === 'MAIN') {
if (isProdAddress(address)) {
return address;
}
return CONST.MAIN_NODE;
} else if (settings.net === 'TEST') {
if (isTestAddress(address)) {
return address;
}
return CONST.TEST_NODE;
} else if (settings.net === 'PRIVATE') {
return settings.address;
Expand All @@ -116,6 +135,18 @@ export function getNodeAddress(): string | null {
}
}

function isAddress(address: string) {
return address !== undefined && address.trim() !== '';
}

function isProdAddress(address: string) {
return isAddress(address) && prodOptions.map((o) => o.value).includes(address);
}

function isTestAddress(address: string) {
return isAddress(address) && testOptions.map((o) => o.value).includes(address);
}

export function getNeoNodeAddress(): string {
return 'http://neonode1.ont.network:10332';
}
3 changes: 3 additions & 0 deletions src/popup/pages/settings/settings.tsx
Expand Up @@ -23,6 +23,7 @@ import { RouterProps } from 'react-router';
import { bindActionCreators, Dispatch } from 'redux';
import { getAddress } from 'src/api/accountApi';
import { getWallet } from '../../../api/authApi';
import { prodOptions, testOptions } from '../../../api/constants';
import { getIdentity } from '../../../api/identityApi';
import Actions from '../../../redux/actions';
import { NetValue } from '../../../redux/settings';
Expand Down Expand Up @@ -127,6 +128,8 @@ const enhancer = (Component: React.ComponentType<Props>) => (props: RouterProps)
routerProps.history.push('/settings/trusted');
},
importError: state.importError,
prodOptions,
testOptions,
},
(injectedProps) => <Component {...injectedProps} settings={reduxProps.settings} />,
),
Expand Down
29 changes: 26 additions & 3 deletions src/popup/pages/settings/settingsView.tsx
Expand Up @@ -41,6 +41,8 @@ export interface Props {
enableClear: boolean;
enableClearIdentity: boolean;
importError: boolean;
testOptions: Array<{ text: string; value: string }>;
prodOptions: Array<{ text: string; value: string }>;
}

const netOptions: Array<{ text: string; value: NetValue }> = [
Expand Down Expand Up @@ -84,16 +86,19 @@ export const SettingsView: React.SFC<Props> = (props) => (
fluid={true}
selection={true}
options={netOptions}
onChange={(e, data) => t.input.onChange(data.value)}
onChange={(e, data) => {
formProps.form.change('address', undefined);
return t.input.onChange(data.value);
}}
value={t.input.value}
error={t.meta.touched && t.meta.invalid}
/>
)}
/>
</View>
<Spacer />
{get(formProps.values, 'net') === 'PRIVATE' ? (
<>
<Spacer />
<View orientation="column">
<label>Private node ip/address</label>
<Field
Expand Down Expand Up @@ -124,7 +129,25 @@ export const SettingsView: React.SFC<Props> = (props) => (
/>
</View>
</>
) : null}
) : (
<View orientation="column">
<label>Node address</label>
<Field
name="address"
validate={required}
render={(t) => (
<SemanticForm.Dropdown
fluid={true}
selection={true}
options={get(formProps.values, 'net') === 'TEST' ? props.testOptions : props.prodOptions}
onChange={(e, data) => t.input.onChange(data.value)}
value={t.input.value}
error={t.meta.touched && t.meta.invalid}
/>
)}
/>
</View>
)}
<Spacer />
<Button
disabled={!props.enableClear}
Expand Down

0 comments on commit a8454b0

Please sign in to comment.