From d3b9dbc2330be0706cb8c2800aa4c6dd39fa80ea Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 3 Jul 2018 14:00:34 +0200 Subject: [PATCH 1/4] Show debug logs in production too --- packages/fether-react/src/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/fether-react/src/index.js b/packages/fether-react/src/index.js index 93722815..64693a9a 100644 --- a/packages/fether-react/src/index.js +++ b/packages/fether-react/src/index.js @@ -11,10 +11,8 @@ import App from './App'; import rootStore from './stores'; import './index.css'; -// Show debug logs in dev environment -if (process.env.NODE_ENV === 'development') { - window.localStorage.debug = 'fether*'; // https://github.com/visionmedia/debug#browser-support -} +// Show debug logs +window.localStorage.debug = 'fether*'; // https://github.com/visionmedia/debug#browser-support ReactDOM.render( -- GitLab From 9263ec47be3eea8e16596a3a7f61734fd2106d12 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 3 Jul 2018 14:12:31 +0200 Subject: [PATCH 2/4] Add more debug messages --- .../fether-react/src/stores/createAccountStore.js | 5 +++++ packages/fether-react/src/stores/parityStore.js | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/fether-react/src/stores/createAccountStore.js b/packages/fether-react/src/stores/createAccountStore.js index c8bc77fb..4c39fdd6 100644 --- a/packages/fether-react/src/stores/createAccountStore.js +++ b/packages/fether-react/src/stores/createAccountStore.js @@ -5,8 +5,11 @@ import { action, observable } from 'mobx'; +import Debug from '../utils/debug'; import parityStore from './parityStore'; +const debug = Debug('createAccountStore'); + export class CreateAccountStore { @observable address = null; @observable isImport = false; // Are we creating a new account, or importing via phrase? @@ -22,10 +25,12 @@ export class CreateAccountStore { } generateNewAccount = () => { + debug('Generating new account.'); return parityStore.api.parity.generateSecretPhrase().then(this.setPhrase); }; saveAccountToParity = password => { + debug('Saving account to Parity.'); return parityStore.api.parity .newAccountFromPhrase(this.phrase, password) .then(() => diff --git a/packages/fether-react/src/stores/parityStore.js b/packages/fether-react/src/stores/parityStore.js index dd0adbb3..365267ab 100644 --- a/packages/fether-react/src/stores/parityStore.js +++ b/packages/fether-react/src/stores/parityStore.js @@ -12,7 +12,7 @@ import store from 'store'; import Debug from '../utils/debug'; import LS_PREFIX from './utils/lsPrefix'; -const debug = Debug('sendStore'); +const debug = Debug('parityStore'); const electron = isElectron() ? window.require('electron') : null; const LS_KEY = `${LS_PREFIX}::secureToken`; @@ -64,6 +64,7 @@ export class ParityStore { defaultPort}`; } + debug(`Connecting to ${provider}.`); const api = new Api( new Api.Provider.Ws( provider, @@ -78,8 +79,8 @@ export class ParityStore { this.api = api; // TODO This is not working - // api.on('connected', () => ...); - // api.on('disconnected', () => ...); + // api.on('connected', () => this.setIsApiConnected(true)); + // api.on('disconnected', () => this.setIsApiConnected(false)); // So instead, we poll every 1s setInterval(() => { this.setIsApiConnected(api.isConnected); @@ -90,6 +91,7 @@ export class ParityStore { const { ipcRenderer } = electron; // Request new token from Electron + debug('Requesting new token.'); ipcRenderer.send('asynchronous-message', 'signer-new-token'); ipcRenderer.once('asynchronous-reply', (_, token) => { if (!token) { @@ -111,7 +113,7 @@ export class ParityStore { if (isApiConnected === this.isApiConnected) { return; } - + debug(`Api is now ${isApiConnected ? 'connected' : 'disconnected'}.`); this.isApiConnected = isApiConnected; }; @@ -135,6 +137,7 @@ export class ParityStore { return; } + debug(`Setting token in localStorage.`); this.token = token; // If we receive a new token, then we try to connect to the Api with this -- GitLab From 71f1bb5e84fbc94a0a12a4097b75ce2cf85bf90e Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 3 Jul 2018 14:42:29 +0200 Subject: [PATCH 3/4] Add additional flags in runParity --- packages/parity-electron/README.md | 9 +++++---- packages/parity-electron/src/runParity.js | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/parity-electron/README.md b/packages/parity-electron/README.md index 3f6e24e9..f88909a6 100644 --- a/packages/parity-electron/README.md +++ b/packages/parity-electron/README.md @@ -57,13 +57,14 @@ Returns the path to the Parity path inside Electron's `userData` folder, even if Resolves to `true` if Parity is currently running, or to `false` if not. -#### `runParity(onParityError: Function): Promise` +#### `runParity(additionalFlags: Array, onParityError: Function): Promise` Spawns a child process to run Parity. If some `cli` flags are passed into the options in `parityElectron`, then those flags will be passed down to Parity itself. -| Option | Type | Description | -| --------------- | ---------- | ------------------------------------------------------------------ | -| `onParityError` | `Function` | Callback with `error` as argument when Parity encounters an error. | +| Option | Type | Description | +| ----------------- | --------------- | --------------------------------------------------------------------------------------------- | +| `additionalFlasg` | `Array` | Addtional flags to pass to Parity, listed as an array, to be passed to `child_process.spawn`. | +| `onParityError` | `Function` | Callback with `error` as argument when Parity encounters an error. | #### `killParity(): Promise` diff --git a/packages/parity-electron/src/runParity.js b/packages/parity-electron/src/runParity.js index 38c2528c..cd2f277a 100644 --- a/packages/parity-electron/src/runParity.js +++ b/packages/parity-electron/src/runParity.js @@ -26,7 +26,7 @@ const catchableErrors = [ 'IO error: While lock file:' ]; -export const runParity = async onParityError => { +export const runParity = async (additionalFlags, onParityError) => { // Do not run parity with --no-run-parity if (cli.runParity === false) { return; @@ -50,7 +50,7 @@ export const runParity = async onParityError => { let logLastLine; // Always contains last line of the Parity logs // Run an instance of parity with the correct args - const args = [...parityArgv(), '--light']; + const args = [...parityArgv(), ...additionalFlags]; parity = spawn(parityPath, args); logger()('@parity/electron:main')(logCommand(parityPath, args)); -- GitLab From 1997434f4aeb28857c2c5d10aa54f73d97ea8eff Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 3 Jul 2018 14:46:38 +0200 Subject: [PATCH 4/4] Run kovan by default (fix #119) --- packages/fether-electron/src/main/cli/index.js | 4 ++++ packages/fether-electron/src/main/index.js | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/fether-electron/src/main/cli/index.js b/packages/fether-electron/src/main/cli/index.js index 87098297..928f06c4 100644 --- a/packages/fether-electron/src/main/cli/index.js +++ b/packages/fether-electron/src/main/cli/index.js @@ -22,6 +22,10 @@ if (process.defaultApp !== true) { cli .version(version) .allowUnknownOption() + .option( + '--chain', + 'The network to connect to, can be one of "foundation", "kovan" or "ropsten". (default: "kovan")' + ) .option( '--no-run-parity', `${productName} will not attempt to run the locally installed parity.` diff --git a/packages/fether-electron/src/main/index.js b/packages/fether-electron/src/main/index.js index 5cf7436e..732e7743 100644 --- a/packages/fether-electron/src/main/index.js +++ b/packages/fether-electron/src/main/index.js @@ -59,7 +59,9 @@ function createWindow () { ) .then(() => // Run parity when installed - runParity(err => handleError(err, 'An error occured with Parity.')) + runParity(['--light', '--chain', cli.chain || 'kovan'], err => + handleError(err, 'An error occured with Parity.') + ) ) .then(() => { // Notify the renderers -- GitLab