From 7330612bfbccd2880dc41503d17807587d2040b3 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 14 Dec 2016 15:56:01 +0100 Subject: [PATCH] Toggle upgrade modal via upgrade link --- js/src/modals/UpgradeParity/store.js | 80 ++++++----- js/src/modals/UpgradeParity/store.spec.js | 58 ++++++++ js/src/modals/UpgradeParity/upgradeParity.css | 10 +- js/src/modals/UpgradeParity/upgradeParity.js | 131 ++++++++++-------- js/src/ui/Modal/Title/title.js | 12 +- js/src/ui/Modal/modal.js | 4 +- 6 files changed, 199 insertions(+), 96 deletions(-) create mode 100644 js/src/modals/UpgradeParity/store.spec.js diff --git a/js/src/modals/UpgradeParity/store.js b/js/src/modals/UpgradeParity/store.js index 461231fd7..466a588e6 100644 --- a/js/src/modals/UpgradeParity/store.js +++ b/js/src/modals/UpgradeParity/store.js @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -import { action, observable, transaction } from 'mobx'; +import { action, computed, observable, transaction } from 'mobx'; import store from 'store'; const LS_UPDATE = '_parity::update'; @@ -22,10 +22,10 @@ const LS_UPDATE = '_parity::update'; const A_MINUTE = 60 * 1000; const A_DAY = 24 * 60 * A_MINUTE; -const STEP_INFO = 1; -const STEP_UPDATING = 2; -const STEP_COMPLETED = 3; -const STEP_ERROR = 4; +const STEP_INFO = 0; +const STEP_UPDATING = 1; +const STEP_COMPLETED = 2; +const STEP_ERROR = 3; const CHECK_INTERVAL = 1 * A_MINUTE; @@ -34,6 +34,7 @@ export default class Store { @observable consensusCapability = null; @observable closed = true; @observable error = null; + @observable remindAt = 0; @observable step = 0; @observable upgrading = null; @observable version = null; @@ -47,37 +48,17 @@ export default class Store { setInterval(this.checkUpgrade, CHECK_INTERVAL); } - @action setUpgrading () { - transaction(() => { - this.upgrading = this.available; - this.setStep(STEP_UPDATING); - }); + @computed get isVisible () { + return !this.closed && Date.now() >= this.remindAt; } - @action setVersions (available, version, consensusCapability) { + @action closeModal = () => { transaction(() => { - this.available = available; - this.consensusCapability = consensusCapability; - this.version = version; + this.closed = true; + this.setStep(0, null); }); } - checkUpgrade = () => { - Promise - .all([ - this._api.parity.upgradeReady(), - this._api.parity.consensusCapability(), - this._api.parity.versionInfo() - ]) - .then(([available, consensusCapability, version]) => { - console.log('[checkUpgrade]', 'available:', available, 'version:', version, 'consensusCapability:', consensusCapability); - this.setVersions(available, version, consensusCapability); - }) - .catch((error) => { - console.warn('checkUpgrade', error); - }); - } - @action loadStorage = () => { const values = store.get(LS_UPDATE) || {}; @@ -93,7 +74,22 @@ export default class Store { @action setStep = (step, error = null) => { transaction(() => { this.error = error; - this.setp = step; + this.step = step; + }); + } + + @action setUpgrading () { + transaction(() => { + this.upgrading = this.available; + this.setStep(STEP_UPDATING, null); + }); + } + + @action setVersions (available, version, consensusCapability) { + transaction(() => { + this.available = available; + this.consensusCapability = consensusCapability; + this.version = version; }); } @@ -112,7 +108,7 @@ export default class Store { throw new Error('Unable to complete update'); } - this.setStep(STEP_COMPLETED); + this.setStep(STEP_COMPLETED, null); }) .catch((error) => { console.error('upgradeNow', error); @@ -120,6 +116,26 @@ export default class Store { this.setStep(STEP_ERROR, error); }); } + + checkUpgrade = () => { + if (!this._api) { + return; + } + + Promise + .all([ + this._api.parity.upgradeReady(), + this._api.parity.consensusCapability(), + this._api.parity.versionInfo() + ]) + .then(([available, consensusCapability, version]) => { + console.log('[checkUpgrade]', 'available:', available, 'version:', version, 'consensusCapability:', consensusCapability); + this.setVersions(available, version, consensusCapability); + }) + .catch((error) => { + console.warn('checkUpgrade', error); + }); + } } export { diff --git a/js/src/modals/UpgradeParity/store.spec.js b/js/src/modals/UpgradeParity/store.spec.js new file mode 100644 index 000000000..1e0111284 --- /dev/null +++ b/js/src/modals/UpgradeParity/store.spec.js @@ -0,0 +1,58 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +import Store from './store'; + +let store; + +describe('modals/UpgradeParity/store', () => { + describe('@actions', () => { + beforeEach(() => { + store = new Store(); + }); + + describe('openModal & closeModal', () => { + it('toggles between the closed states', () => { + expect(store.closed).to.be.true; + store.openModal(); + expect(store.closed).to.be.false; + store.closeModal(); + expect(store.closed).to.be.true; + }); + + it('resets the step state upon closing', () => { + store.setStep(5, 'soem error'); + store.closeModal(); + expect(store.step).to.equal(0); + expect(store.error).to.be.null; + }); + }); + + describe('setStep', () => { + it('sets the step as provided', () => { + expect(store.step).to.equal(0); + store.setStep(3); + expect(store.step).to.equal(3); + }); + + it('sets the error when provided', () => { + expect(store.error).to.be.null; + store.setStep(3, new Error('some error')); + expect(store.error).to.match(/some error/); + }); + }); + }); +}); diff --git a/js/src/modals/UpgradeParity/upgradeParity.css b/js/src/modals/UpgradeParity/upgradeParity.css index 962bbc58c..bca0fe47d 100644 --- a/js/src/modals/UpgradeParity/upgradeParity.css +++ b/js/src/modals/UpgradeParity/upgradeParity.css @@ -16,11 +16,17 @@ */ .error { - padding-top: 1.5em; + padding-top: 1.25em; } .infoStep { div+div { - padding-top: 1.5em; + padding-top: 1.25em; } } + +.version { + display: inline; + opacity: 0.5; + white-space: normal; +} diff --git a/js/src/modals/UpgradeParity/upgradeParity.js b/js/src/modals/UpgradeParity/upgradeParity.js index 7f13d87ea..3e67c42f2 100644 --- a/js/src/modals/UpgradeParity/upgradeParity.js +++ b/js/src/modals/UpgradeParity/upgradeParity.js @@ -19,7 +19,7 @@ import React, { Component, PropTypes } from 'react'; import { FormattedMessage } from 'react-intl'; import { Button } from '~/ui'; -import { CancelIcon, DoneIcon, NextIcon, SnoozeIcon } from '~/ui/Icons'; +import { CancelIcon, DoneIcon, NextIcon } from '~/ui/Icons'; import Modal, { Busy, Completed } from '~/ui/Modal'; import { STEP_COMPLETED, STEP_ERROR, STEP_INFO, STEP_UPDATING } from './store'; @@ -38,7 +38,7 @@ export default class UpgradeParity extends Component { render () { const { store } = this.props; - if (!store.showUpgrade) { + if (!store.isVisible) { return null; } @@ -55,11 +55,11 @@ export default class UpgradeParity extends Component { defaultMessage='upgrading parity' />, store.step === STEP_ERROR ? - : + : ] } visible> { this.renderStep() } @@ -73,6 +73,7 @@ export default class UpgradeParity extends Component { const closeButton =