From 85a7d82640690f3db76de0d596eaf88f9cb704ae Mon Sep 17 00:00:00 2001 From: pbca26 Date: Thu, 16 Nov 2017 23:59:35 +0300 Subject: [PATCH] toaster duplicates handling fix; zcparams check refactor --- react/src/components/addcoin/addcoin.js | 76 +++++++++++++++---- .../components/dashboard/main/dashboard.js | 45 +++++++++++ .../zcparamsFetchModal/zcparamsFetchModal.js | 8 +- react/src/components/login/login.js | 4 +- react/src/components/login/login.render.js | 4 + react/src/components/main/main.js | 38 ---------- react/src/reducers/toaster.js | 11 ++- react/src/util/zcashParams.js | 29 +++++++ 8 files changed, 156 insertions(+), 59 deletions(-) create mode 100644 react/src/util/zcashParams.js diff --git a/react/src/components/addcoin/addcoin.js b/react/src/components/addcoin/addcoin.js index 43237f6..1d42963 100644 --- a/react/src/components/addcoin/addcoin.js +++ b/react/src/components/addcoin/addcoin.js @@ -7,9 +7,11 @@ import { toggleAddcoinModal, triggerToaster, shepherdGetCoinList, - shepherdPostCoinList + shepherdPostCoinList, + toggleZcparamsFetchModal, } from '../../actions/actionCreators'; import Store from '../../store'; +import { zcashParamsCheckErrors } from '../../util/zcashParams'; import CoinSelectorsRender from './coin-selectors.render'; import AddCoinRender from './addcoin.render'; @@ -46,6 +48,43 @@ class AddCoin extends React.Component { this.toggleActionsMenu = this.toggleActionsMenu.bind(this); this.saveCoinSelection = this.saveCoinSelection.bind(this); this.loadCoinSelection = this.loadCoinSelection.bind(this); + this.verifyZcashParamsExist = this.verifyZcashParamsExist.bind(this); + } + + verifyZcashParamsExist(mode) { + return new Promise((resolve, reject) => { + if (Number(mode) === -1) { + const _res = window.require('electron').remote.getCurrentWindow().zcashParamsExist; + const __errors = zcashParamsCheckErrors(_res); + + if (__errors) { + window.require('electron').remote.getCurrentWindow().zcashParamsExistPromise() + .then((res) => { + const _errors = zcashParamsCheckErrors(res); + window.require('electron').remote.getCurrentWindow().zcashParamsExist = res; + + if (_errors) { + Store.dispatch( + triggerToaster( + _errors, + 'Komodod', + 'error', + false + ) + ); + Store.dispatch(toggleZcparamsFetchModal(true)); + resolve(false); + } else { + resolve(true); + } + }); + } else { + resolve(true); + } + } else { + resolve(true); + } + }); } saveCoinSelection() { @@ -206,23 +245,28 @@ class AddCoin extends React.Component { return; } - if (!_coin.daemonParam) { - Store.dispatch(addCoin( - coin, - _coin.mode, - )); - } else { - Store.dispatch(addCoin( - coin, - _coin.mode, - { type: _coin.daemonParam } - )); - } + this.verifyZcashParamsExist(_coin.mode) + .then((res) => { + if (res) { + if (!_coin.daemonParam) { + Store.dispatch(addCoin( + coin, + _coin.mode, + )); + } else { + Store.dispatch(addCoin( + coin, + _coin.mode, + { type: _coin.daemonParam } + )); + } - this.removeCoin(); - this.addNewItem(); + this.removeCoin(); + this.addNewItem(); - Store.dispatch(toggleAddcoinModal(false, false)); + Store.dispatch(toggleAddcoinModal(false, false)); + } + }); } dismiss() { diff --git a/react/src/components/dashboard/main/dashboard.js b/react/src/components/dashboard/main/dashboard.js index fda315b..6645be7 100755 --- a/react/src/components/dashboard/main/dashboard.js +++ b/react/src/components/dashboard/main/dashboard.js @@ -1,13 +1,58 @@ import React from 'react'; import { connect } from 'react-redux'; import DashboardRender from './dashboard.render'; +import { + toggleZcparamsFetchModal, + triggerToaster, +} from '../../../actions/actionCreators'; +import { zcashParamsCheckErrors } from '../../../util/zcashParams'; +import Store from '../../../store'; class Dashboard extends React.Component { constructor() { super(); this.state = { + zcashParamsVerifyTriggered: false, }; this.renderDashboard = this.renderDashboard.bind(this); + this.verifyZcashParams = this.verifyZcashParams.bind(this); + } + + verifyZcashParams() { + if (!this.state.zcashParamsVerifyTriggered) { + const _res = window.require('electron').remote.getCurrentWindow().zcashParamsExist; + const _errors = zcashParamsCheckErrors(_res); + + if (_errors) { + Store.dispatch( + triggerToaster( + _errors, + 'Komodo', + 'error', + false + ) + ); + + Store.dispatch(toggleZcparamsFetchModal(true)); + } + } else { + this.setState({ + zcashParamsVerifyTriggered: false, + }); + } + } + + componentWillReceiveProps() { + if (this.props.Main && + this.props.Main.coins && + this.props.Main.coins.native && + this.props.Main.coins.native.length && + !this.props.Dashboard.displayZcparamsModal) { + this.setState({ + zcashParamsVerifyTriggered: true, + }); + this.verifyZcashParams(); + } } isSectionActive(section) { diff --git a/react/src/components/dashboard/zcparamsFetchModal/zcparamsFetchModal.js b/react/src/components/dashboard/zcparamsFetchModal/zcparamsFetchModal.js index 7a28f79..9c77e31 100644 --- a/react/src/components/dashboard/zcparamsFetchModal/zcparamsFetchModal.js +++ b/react/src/components/dashboard/zcparamsFetchModal/zcparamsFetchModal.js @@ -108,11 +108,17 @@ class ZcparamsFetchModal extends React.Component { if (data.msg.file === 'proving') { _updateLog = []; _updateLog.push(translate('ZCPARAMS_FETCH.BOTH_KEYS_VERIFIED')); - _updateLog.push(translate('ZCPARAMS_FETCH.PLEASE_RESTART')); + // _updateLog.push(translate('ZCPARAMS_FETCH.PLEASE_RESTART')); this.setState(Object.assign({}, this.state, { updateLog: _updateLog, done: true, })); + + window.require('electron').remote.getCurrentWindow().zcashParamsExistPromise() + .then((res) => { + const _errors = zcashParamsCheckErrors(res); + window.require('electron').remote.getCurrentWindow().zcashParamsExist = res; + }); } else { this.setState(Object.assign({}, this.state, { updateLog: _updateLog, diff --git a/react/src/components/login/login.js b/react/src/components/login/login.js index 8b655f8..1f991a8 100644 --- a/react/src/components/login/login.js +++ b/react/src/components/login/login.js @@ -499,9 +499,7 @@ class Login extends React.Component { const mapStateToProps = (state) => { return { Main: state.Main, - Dashboard: { - activeHandle: state.Dashboard.activeHandle, - }, + Dashboard: state.Dashboard, Interval: { interval: state.Interval.interval, }, diff --git a/react/src/components/login/login.render.js b/react/src/components/login/login.render.js index 3442a9e..10b2d04 100644 --- a/react/src/components/login/login.render.js +++ b/react/src/components/login/login.render.js @@ -1,10 +1,14 @@ import React from 'react'; import { translate } from '../../translate/translate'; import LoginSettingsModal from '../dashboard/loginSettingsModal/loginSettingsModal'; +import ZcparamsFetchModal from '../dashboard/zcparamsFetchModal/zcparamsFetchModal'; const LoginRender = function () { return (
+ { this.props.Dashboard.displayZcparamsModal && + + } { this.renderSwallModal() }
diff --git a/react/src/components/main/main.js b/react/src/components/main/main.js index 4ca80d7..7126b67 100644 --- a/react/src/components/main/main.js +++ b/react/src/components/main/main.js @@ -1,13 +1,10 @@ import React from 'react'; import WalletMain from './walletMain'; import Store from '../../store'; -import { translate } from '../../translate/translate'; import { getDexCoins, activeHandle, - triggerToaster, shepherdElectrumCoins, - toggleZcparamsFetchModal, } from '../../actions/actionCreators'; class Main extends React.Component { @@ -20,51 +17,16 @@ class Main extends React.Component { componentDidMount() { let appVersion; - let zcashParamsExist; let appConfig; try { appVersion = window.require('electron').remote.getCurrentWindow().appBasicInfo; appConfig = window.require('electron').remote.getCurrentWindow().appConfig; - zcashParamsExist = window.require('electron').remote.getCurrentWindow().zcashParamsExist; } catch (e) {} if (appVersion) { document.title = `${appVersion.name} (v${appVersion.version.replace('version=', '')}-beta)`; } - - // TODO: isolate check only when komodod is detected - if (zcashParamsExist.errors) { - let _errors = [translate('KMD_NATIVE.ZCASH_PARAMS_MISSING'), '']; - - if (!zcashParamsExist.rootDir) { - _errors.push(translate('KMD_NATIVE.ZCASH_PARAMS_MISSING_ROOT_DIR')); - } - if (!zcashParamsExist.provingKey) { - _errors.push(translate('KMD_NATIVE.ZCASH_PARAMS_MISSING_PROVING_KEY')); - } - if (!zcashParamsExist.verifyingKey) { - _errors.push(translate('KMD_NATIVE.ZCASH_PARAMS_MISSING_VERIFYING_KEY')); - } - if (!zcashParamsExist.provingKeySize && - zcashParamsExist.provingKey) { - _errors.push(translate('KMD_NATIVE.ZCASH_PARAMS_MISSING_PROVING_KEY_SIZE')); - } - if (!zcashParamsExist.verifyingKeySize && - zcashParamsExist.verifyingKey) { - _errors.push(translate('KMD_NATIVE.ZCASH_PARAMS_MISSING_VERIFYING_KEY_SIZE')); - } - - Store.dispatch( - triggerToaster( - _errors, - 'Komodo', - 'error', - false - ) - ); - Store.dispatch(toggleZcparamsFetchModal(true)); - } } componentWillMount() { diff --git a/react/src/reducers/toaster.js b/react/src/reducers/toaster.js index 0abc6c1..35a05b8 100644 --- a/react/src/reducers/toaster.js +++ b/react/src/reducers/toaster.js @@ -12,9 +12,18 @@ export function toaster(state = { case ADD_TOASTER_MESSAGE: let _isSameToastTwice = false; + function arrayToString(arr) { + if (typeof arr === 'object') { + return arr.join().toString(); + } else { + return arr; + } + } + for (let i = 0; i < state.toasts.length; i++) { if (state.toasts[i].title === action.title && - state.toasts[i].message === action.message && + (arrayToString(action.message) === arrayToString(state.toasts[i].message) || + state.toasts[i].message === action.message) && state.toasts[i]['_type'] === action['_type']) { _isSameToastTwice = true; break; diff --git a/react/src/util/zcashParams.js b/react/src/util/zcashParams.js new file mode 100644 index 0000000..7f41f86 --- /dev/null +++ b/react/src/util/zcashParams.js @@ -0,0 +1,29 @@ +import { translate } from '../translate/translate'; + +export function zcashParamsCheckErrors(zcashParamsExist) { + let _errors; + + if (zcashParamsExist.errors) { + _errors = [translate('KMD_NATIVE.ZCASH_PARAMS_MISSING'), '']; + + if (!zcashParamsExist.rootDir) { + _errors.push(translate('KMD_NATIVE.ZCASH_PARAMS_MISSING_ROOT_DIR')); + } + if (!zcashParamsExist.provingKey) { + _errors.push(translate('KMD_NATIVE.ZCASH_PARAMS_MISSING_PROVING_KEY')); + } + if (!zcashParamsExist.verifyingKey) { + _errors.push(translate('KMD_NATIVE.ZCASH_PARAMS_MISSING_VERIFYING_KEY')); + } + if (!zcashParamsExist.provingKeySize && + zcashParamsExist.provingKey) { + _errors.push(translate('KMD_NATIVE.ZCASH_PARAMS_MISSING_PROVING_KEY_SIZE')); + } + if (!zcashParamsExist.verifyingKeySize && + zcashParamsExist.verifyingKey) { + _errors.push(translate('KMD_NATIVE.ZCASH_PARAMS_MISSING_VERIFYING_KEY_SIZE')); + } + } + + return _errors; +} \ No newline at end of file