Browse Source

toaster duplicates handling fix; zcparams check refactor

v0.25
pbca26 7 years ago
parent
commit
85a7d82640
  1. 76
      react/src/components/addcoin/addcoin.js
  2. 45
      react/src/components/dashboard/main/dashboard.js
  3. 8
      react/src/components/dashboard/zcparamsFetchModal/zcparamsFetchModal.js
  4. 4
      react/src/components/login/login.js
  5. 4
      react/src/components/login/login.render.js
  6. 38
      react/src/components/main/main.js
  7. 11
      react/src/reducers/toaster.js
  8. 29
      react/src/util/zcashParams.js

76
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() {

45
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) {

8
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,

4
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,
},

4
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 (
<div>
{ this.props.Dashboard.displayZcparamsModal &&
<ZcparamsFetchModal />
}
<LoginSettingsModal section={ this.state.displayLoginSettingsDropdownSection } />
{ this.renderSwallModal() }
<div className="page animsition vertical-align text-center fade-in">

38
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() {

11
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;

29
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;
}
Loading…
Cancel
Save