From 350ad7c1a2b9b2a116bc0ce6dfdfb4991711e5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Thu, 22 Feb 2018 11:22:33 +0100 Subject: [PATCH] Improved OnProgress for ImportAccounts --- package.json | 22 +- .../modals/AddAccount/ImportAccounts.js | 14 +- src/components/modals/AddAccount/index.js | 55 +- src/components/modals/Receive.js | 26 +- src/helpers/btc.js | 23 +- src/helpers/db.js | 42 +- src/internals/usb/wallet/accounts.js | 63 +- src/internals/usb/wallet/index.js | 14 +- src/main/bridge.js | 7 + yarn.lock | 656 ++++++++++++++---- 10 files changed, 721 insertions(+), 201 deletions(-) diff --git a/package.json b/package.json index 70670759..e55d5131 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@fortawesome/react-fontawesome": "^0.0.17", "@ledgerhq/common": "^4.2.0", "@ledgerhq/currencies": "^4.2.0", - "@ledgerhq/hw-app-btc": "^4.2.0", + "@ledgerhq/hw-app-btc": "^4.2.1", "@ledgerhq/hw-app-eth": "^4.2.0", "@ledgerhq/hw-transport": "^4.2.0", "@ledgerhq/hw-transport-node-hid": "^4.2.0", @@ -97,12 +97,12 @@ "tippy.js": "^2.2.3" }, "devDependencies": { - "@storybook/addon-actions": "^3.3.13", - "@storybook/addon-knobs": "^3.3.13", - "@storybook/addon-links": "^3.3.13", - "@storybook/addon-options": "^3.3.13", - "@storybook/addons": "^3.3.13", - "@storybook/react": "^3.3.13", + "@storybook/addon-actions": "^3.3.14", + "@storybook/addon-knobs": "^3.3.14", + "@storybook/addon-links": "^3.3.14", + "@storybook/addon-options": "^3.3.14", + "@storybook/addons": "^3.3.14", + "@storybook/react": "^3.3.14", "babel-core": "^6.26.0", "babel-eslint": "^8.2.1", "babel-loader": "^7.1.2", @@ -118,15 +118,15 @@ "concurrently": "^3.5.1", "dotenv": "^5.0.0", "electron": "1.8.2", - "electron-builder": "^20.0.7", + "electron-builder": "^20.0.8", "electron-devtools-installer": "^2.2.3", "electron-webpack": "1.13.0", "eslint": "^4.18.1", "eslint-config-airbnb": "^16.1.0", "eslint-config-prettier": "^2.9.0", "eslint-import-resolver-babel-module": "^4.0.0", - "eslint-plugin-flowtype": "^2.45.0", - "eslint-plugin-import": "^2.8.0", + "eslint-plugin-flowtype": "^2.46.0", + "eslint-plugin-import": "^2.9.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.7.0", "flow-bin": "^0.66.0", @@ -134,7 +134,7 @@ "hard-source-webpack-plugin": "^0.5.18", "husky": "^0.14.3", "js-yaml": "^3.10.0", - "lint-staged": "^6.1.1", + "lint-staged": "^7.0.0", "node-loader": "^0.6.0", "prettier": "^1.10.2", "react-hot-loader": "^4.0.0-beta.21", diff --git a/src/components/modals/AddAccount/ImportAccounts.js b/src/components/modals/AddAccount/ImportAccounts.js index 071fa023..ccc893c1 100644 --- a/src/components/modals/AddAccount/ImportAccounts.js +++ b/src/components/modals/AddAccount/ImportAccounts.js @@ -5,11 +5,10 @@ import { translate } from 'react-i18next' import type { T } from 'types/common' -import { formatBTC } from 'helpers/format' - import Box from 'components/base/Box' import Button from 'components/base/Button' import CheckBox from 'components/base/CheckBox' +import FormattedVal from 'components/base/FormattedVal' import Input from 'components/base/Input' type Props = { @@ -101,7 +100,16 @@ class ImportAccounts extends PureComponent { onChange={this.handleChangeInput(account.id)} /> - Balance: {formatBTC(account.balance)} + + Balance:{' '} + + Transactions: {account.transactions.length} diff --git a/src/components/modals/AddAccount/index.js b/src/components/modals/AddAccount/index.js index 4e99f363..9c263f2c 100644 --- a/src/components/modals/AddAccount/index.js +++ b/src/components/modals/AddAccount/index.js @@ -23,11 +23,12 @@ import { sendEvent } from 'renderer/events' import { addAccount, updateAccount } from 'actions/accounts' import Box from 'components/base/Box' -import Text from 'components/base/Text' import Button from 'components/base/Button' +import FormattedVal from 'components/base/FormattedVal' import Label from 'components/base/Label' import Modal, { ModalBody } from 'components/base/Modal' import Select from 'components/base/Select' +import Text from 'components/base/Text' import CreateAccount from './CreateAccount' import ImportAccounts from './ImportAccounts' @@ -67,12 +68,24 @@ const Steps = { Start {props.currency.name} App on your Ledger: ko ), - inProgress: (props: Object) => ( + inProgress: ({ progress, unit }: Object) => ( In progress. - {props.progress !== null && ( + {progress !== null && ( - Account: {props.progress.account} / Transactions: {props.progress.transactions} + Account: {progress.account} + + Balance:{' '} + + + Transactions: {progress.transactions || 0} + {progress.success && Finish ! Next account in progress...} )} @@ -143,7 +156,7 @@ class AddAccountModal extends PureComponent { } componentDidMount() { - ipcRenderer.on('msg', this.handleWalletRequest) + ipcRenderer.on('msg', this.handleMsgEvent) } componentWillReceiveProps(nextProps) { @@ -166,7 +179,7 @@ class AddAccountModal extends PureComponent { } componentWillUnmount() { - ipcRenderer.removeListener('msg', this.handleWalletRequest) + ipcRenderer.removeListener('msg', this.handleMsgEvent) clearTimeout(this._timeout) } @@ -206,6 +219,7 @@ class AddAccountModal extends PureComponent { ...props(step === 'inProgress', { t, progress, + unit: currency !== null && getDefaultUnitByCoinType(currency.coinType), }), ...props(step === 'listAccounts', { t, @@ -219,12 +233,24 @@ class AddAccountModal extends PureComponent { } } - handleWalletRequest = (e, { data, type }) => { + handleMsgEvent = (e, { data, type }) => { + if (type === 'wallet.getAccounts.start') { + this._pid = data.pid + } + if (type === 'wallet.getAccounts.progress') { - this.setState({ + this.setState(prev => ({ step: 'inProgress', - progress: data, - }) + progress: + prev.progress === null + ? data + : prev.progress.success + ? data + : { + ...prev.progress, + ...data, + }, + })) } if (type === 'wallet.getAccounts.fail') { @@ -253,7 +279,12 @@ class AddAccountModal extends PureComponent { }) } - handleClose = () => clearTimeout(this._timeout) + handleClose = () => { + sendEvent('msg', 'kill.process', { + pid: this._pid, + }) + clearTimeout(this._timeout) + } handleHide = () => this.setState({ @@ -277,6 +308,7 @@ class AddAccountModal extends PureComponent { } _timeout = undefined + _pid = null render() { const { step } = this.state @@ -286,6 +318,7 @@ class AddAccountModal extends PureComponent { { const Step = Steps[step] diff --git a/src/components/modals/Receive.js b/src/components/modals/Receive.js index 1b1e281b..e00faee2 100644 --- a/src/components/modals/Receive.js +++ b/src/components/modals/Receive.js @@ -1,6 +1,6 @@ // @flow -import React, { PureComponent } from 'react' +import React, { PureComponent, Fragment } from 'react' import { translate } from 'react-i18next' import get from 'lodash/get' @@ -72,16 +72,20 @@ class ReceiveModal extends PureComponent { - - - - - + {account && ( + + + + + + + + )}