From a2a89f7e59fa6ef7d5a73ac9c32e62ed9fa22de6 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 12 Dec 2016 18:30:41 +0100 Subject: [PATCH] Basic UI structure in-place --- .../{Upgrade => Updating}/index.js | 2 +- .../upgrade.js => Updating/updating.js} | 6 +- js/src/modals/UpgradeParity/index.js | 17 ++++ js/src/modals/UpgradeParity/modalStore.js | 97 +++++++++++++++++++ js/src/modals/UpgradeParity/store.js | 86 ---------------- js/src/modals/UpgradeParity/upgradeParity.js | 83 ++++++++++++++-- js/src/modals/UpgradeParity/upgradeStore.js | 57 +++++++++++ js/src/ui/Modal/modal.js | 6 +- 8 files changed, 253 insertions(+), 101 deletions(-) rename js/src/modals/UpgradeParity/{Upgrade => Updating}/index.js (95%) rename js/src/modals/UpgradeParity/{Upgrade/upgrade.js => Updating/updating.js} (87%) create mode 100644 js/src/modals/UpgradeParity/index.js create mode 100644 js/src/modals/UpgradeParity/modalStore.js delete mode 100644 js/src/modals/UpgradeParity/store.js create mode 100644 js/src/modals/UpgradeParity/upgradeStore.js diff --git a/js/src/modals/UpgradeParity/Upgrade/index.js b/js/src/modals/UpgradeParity/Updating/index.js similarity index 95% rename from js/src/modals/UpgradeParity/Upgrade/index.js rename to js/src/modals/UpgradeParity/Updating/index.js index ff2da57b5..59e363f11 100644 --- a/js/src/modals/UpgradeParity/Upgrade/index.js +++ b/js/src/modals/UpgradeParity/Updating/index.js @@ -14,4 +14,4 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -export default from './upgrade'; +export default from './updating'; diff --git a/js/src/modals/UpgradeParity/Upgrade/upgrade.js b/js/src/modals/UpgradeParity/Updating/updating.js similarity index 87% rename from js/src/modals/UpgradeParity/Upgrade/upgrade.js rename to js/src/modals/UpgradeParity/Updating/updating.js index 75637058c..f1bbc722a 100644 --- a/js/src/modals/UpgradeParity/Upgrade/upgrade.js +++ b/js/src/modals/UpgradeParity/Updating/updating.js @@ -17,17 +17,15 @@ import { observer } from 'mobx-react'; import React, { Component, PropTypes } from 'react'; -import styles from './.css'; - @observer -export default class Upgrade extends Component { +export default class Updating extends Component { static propTypes = { store: PropTypes.object.isRequired } render () { return ( -
hello
+
hello
); } } diff --git a/js/src/modals/UpgradeParity/index.js b/js/src/modals/UpgradeParity/index.js new file mode 100644 index 000000000..523e372fa --- /dev/null +++ b/js/src/modals/UpgradeParity/index.js @@ -0,0 +1,17 @@ +// 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 . + +export default from './upgradeParity'; diff --git a/js/src/modals/UpgradeParity/modalStore.js b/js/src/modals/UpgradeParity/modalStore.js new file mode 100644 index 000000000..d677aa01d --- /dev/null +++ b/js/src/modals/UpgradeParity/modalStore.js @@ -0,0 +1,97 @@ +// 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 { action, computed, observable, transaction } from 'mobx'; +import store from 'store'; + +const LS_UPDATE = '_parity::update'; + +const A_DAY = 24 * 60 * 60 * 1000; + +const STEP_INFO = 1; +const STEP_UPDATING = 2; +const STEP_COMPLETED = 3; +const STEP_ERROR = 4; + +export default class ModalStore { + @observable closed = false; + @observable error = null; + @observable step = 0; + @observable upgrade = null; + + constructor (upgradeStore) { + this.upgrade = upgradeStore; + + this.loadStorage(); + } + + @computed get showUpgrade () { + return !closed && Date.now() >= this.remindAt; + } + + @action closeModal = () => { + transaction(() => { + this.closed = true; + this.setStep(STEP_INFO); + }); + } + + @action loadStorage = () => { + const values = store.get(LS_UPDATE) || {}; + + this.remindAt = values.remindAt ? values.remindAt : 0; + + return values; + } + + @action setStep = (step, error = null) => { + transaction(() => { + this.error = error; + this.setp = step; + }); + } + + @action snoozeTillTomorrow = () => { + this.remindAt = Date.now() + A_DAY; + store.set(LS_UPDATE, Object.assign(this.loadStorage(), { remindAt: this.remindAt })); + } + + @action upgradeNow = () => { + this.setStep(STEP_UPDATING); + + this.upgrade + .executeUpgrade() + .then((result) => { + if (!result) { + throw new Error('Unable to complete update'); + } + + this.setStep(STEP_COMPLETED); + }) + .catch((error) => { + console.error('upgradeNow', error); + + this.setStep(STEP_ERROR, error); + }); + } +} + +export { + STEP_COMPLETED, + STEP_ERROR, + STEP_INFO, + STEP_UPDATING +}; diff --git a/js/src/modals/UpgradeParity/store.js b/js/src/modals/UpgradeParity/store.js deleted file mode 100644 index 57446ead8..000000000 --- a/js/src/modals/UpgradeParity/store.js +++ /dev/null @@ -1,86 +0,0 @@ -// 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 { action, observable, transaction } from 'mobx'; -import store from 'store'; - -const AN_HOUR = 60 * 60 * 1000; -const A_DAY = 24 * AN_HOUR; -const CHECK_INTERVAL = AN_HOUR; -const LS_UPDATE = '_parity::update'; - -export default class Store { - @observable availableUpgrade = null; - @observable remindAt = 0; - @observable showUpgrade = false; - - constructor (api) { - this._api = api; - - this.checkUpgrade(); - setInterval(this.pollUpgrade, CHECK_INTERVAL); - } - - @action loadStorage () { - const values = store.get(LS_UPDATE) || {}; - - this.remindAt = values.remindAt ? values.remindAt : 0; - - return values; - } - - @action setAvailableUpgrade (availableUpgrade, consensusCapability) { - transaction(() => { - this.setConsensusCapability(consensusCapability); - this.availableUpgrade = availableUpgrade; - - if (availableUpgrade && Date.now() >= this.remindAt) { - this.showUpgrade = true; - } - }); - } - - @action setConsensusCapability (consensusCapability) { - this.consensusCapability = consensusCapability; - } - - @action snoozeTillTomorrow () { - store.set(LS_UPDATE, Object.assign(this.loadStorage(), { - remindAt: Date.now() + A_DAY - })); - } - - checkUpgrade = () => { - this.loadStorage(); - - return Promise - .all([ - this._api.parity.upgradeReady(), - this._api.parity.consensusCapability() - ]) - .then(([availableUpgrade, consensusCapability]) => { - this.setAvailableUpgrade(availableUpgrade, consensusCapability); - }) - .catch((error) => { - console.warn('checkUpgrade', error); - }); - } - - executeUpgrade = () => { - return this._api.parity - .executeUpgrade(); - } -} diff --git a/js/src/modals/UpgradeParity/upgradeParity.js b/js/src/modals/UpgradeParity/upgradeParity.js index 41a28d666..4c4d9f1ef 100644 --- a/js/src/modals/UpgradeParity/upgradeParity.js +++ b/js/src/modals/UpgradeParity/upgradeParity.js @@ -16,10 +16,16 @@ import { observer } from 'mobx-react'; import React, { Component, PropTypes } from 'react'; +import { FormattedMessage } from 'react-intl'; import { Button, Modal } from '~/ui'; +import { CancelIcon, DoneIcon, NextIcon, SnoozeIcon } from '~/ui/Icons'; -import Store from './store'; +import Info from './Info'; +import Updating from './Updating'; + +import ModalStore, { STEP_COMPLETED, STEP_ERROR, STEP_INFO, STEP_UPDATING } from './modalStore'; +import UpgradeStore from './upgradeStore'; @observer export default class UpgradeParity extends Component { @@ -27,21 +33,84 @@ export default class UpgradeParity extends Component { api: PropTypes.object.isRequired }; - store = new Store(this.context.api); + store = new ModalStore(new UpgradeStore(this.context.api)); render () { - if (!this.store.showUpgrade) { + if (!this.store.upgrade.available || !this.store.showUpgrade) { return null; } return ( - ] } + actions={ this.renderActions() } visible> -
+ { this.renderStep() } ); } + + renderActions () { + const closeButton = +