From a8f428ccca44c25687d80c5f4f6815372214edc5 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 14 Dec 2016 14:37:25 +0100 Subject: [PATCH] Display capability status on statusbar --- .../UpgradeParity/{modalStore.js => store.js} | 65 +++++++++---- js/src/modals/UpgradeParity/upgradeParity.js | 51 +++++----- js/src/modals/UpgradeParity/upgradeStore.js | 67 ------------- .../views/Application/Container/container.js | 11 ++- js/src/views/Application/Status/status.css | 65 ++++++------- js/src/views/Application/Status/status.js | 94 +++++++++++++------ js/src/views/Application/application.css | 2 +- js/src/views/Application/application.js | 30 +++--- 8 files changed, 202 insertions(+), 183 deletions(-) rename js/src/modals/UpgradeParity/{modalStore.js => store.js} (56%) delete mode 100644 js/src/modals/UpgradeParity/upgradeStore.js diff --git a/js/src/modals/UpgradeParity/modalStore.js b/js/src/modals/UpgradeParity/store.js similarity index 56% rename from js/src/modals/UpgradeParity/modalStore.js rename to js/src/modals/UpgradeParity/store.js index 994e42003..461231fd7 100644 --- a/js/src/modals/UpgradeParity/modalStore.js +++ b/js/src/modals/UpgradeParity/store.js @@ -14,41 +14,70 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -import { action, computed, observable, transaction } from 'mobx'; +import { action, observable, transaction } from 'mobx'; import store from 'store'; const LS_UPDATE = '_parity::update'; -const A_DAY = 24 * 60 * 60 * 1000; +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; -export default class ModalStore { - @observable closed = false; +const CHECK_INTERVAL = 1 * A_MINUTE; + +export default class Store { + @observable available = null; + @observable consensusCapability = null; + @observable closed = true; @observable error = null; @observable step = 0; - @observable upgrade = null; + @observable upgrading = null; + @observable version = null; - constructor (upgradeStore) { - this.upgrade = upgradeStore; + constructor (api) { + this._api = api; this.loadStorage(); + this.checkUpgrade(); + + setInterval(this.checkUpgrade, CHECK_INTERVAL); } - @computed get showUpgrade () { - return !this.closed && Date.now() >= this.remindAt; - } - - @action closeModal = () => { + @action setUpgrading () { transaction(() => { - this.closed = true; - this.setStep(STEP_INFO); + this.upgrading = this.available; + this.setStep(STEP_UPDATING); }); } + @action setVersions (available, version, consensusCapability) { + transaction(() => { + this.available = available; + this.consensusCapability = consensusCapability; + this.version = version; + }); + } + + 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) || {}; @@ -57,6 +86,10 @@ export default class ModalStore { return values; } + @action openModal = () => { + this.closed = false; + } + @action setStep = (step, error = null) => { transaction(() => { this.error = error; @@ -70,9 +103,9 @@ export default class ModalStore { } @action upgradeNow = () => { - this.setStep(STEP_UPDATING); + this.setUpgrading(); - this.upgrade + return this._api.parity .executeUpgrade() .then((result) => { if (!result) { diff --git a/js/src/modals/UpgradeParity/upgradeParity.js b/js/src/modals/UpgradeParity/upgradeParity.js index c1ba9d395..7f13d87ea 100644 --- a/js/src/modals/UpgradeParity/upgradeParity.js +++ b/js/src/modals/UpgradeParity/upgradeParity.js @@ -22,8 +22,7 @@ import { Button } from '~/ui'; import { CancelIcon, DoneIcon, NextIcon, SnoozeIcon } from '~/ui/Icons'; import Modal, { Busy, Completed } from '~/ui/Modal'; -import ModalStore, { STEP_COMPLETED, STEP_ERROR, STEP_INFO, STEP_UPDATING } from './modalStore'; -import UpgradeStore from './upgradeStore'; +import { STEP_COMPLETED, STEP_ERROR, STEP_INFO, STEP_UPDATING } from './store'; import styles from './upgradeParity.css'; @observer @@ -32,17 +31,21 @@ export default class UpgradeParity extends Component { api: PropTypes.object.isRequired }; - store = new ModalStore(new UpgradeStore(this.context.api)); + static propTypes = { + store: PropTypes.object.isRequired + } render () { - if (!this.store.upgrade.available || !this.store.showUpgrade) { + const { store } = this.props; + + if (!store.showUpgrade) { return null; } return ( , - this.store.step === STEP_ERROR + store.step === STEP_ERROR ? @@ -65,6 +68,8 @@ export default class UpgradeParity extends Component { } renderActions () { + const { store } = this.props; + const closeButton =