'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.STEP_UPDATING = exports.STEP_INFO = exports.STEP_ERROR = exports.STEP_COMPLETED = exports.default = undefined;var _slicedToArray = function () {function sliceIterator(arr, i) {var _arr = [];var _n = true;var _d = false;var _e = undefined;try {for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"]) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}return function (arr, i) {if (Array.isArray(arr)) {return arr;} else if (Symbol.iterator in Object(arr)) {return sliceIterator(arr, i);} else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _desc, _value, _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14; // Copyright 2015-2017 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 <http://www.gnu.org/licenses/>.

var _mobx = require('mobx');
var _store = require('store');var _store2 = _interopRequireDefault(_store);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _initDefineProp(target, property, descriptor, context) {if (!descriptor) return;Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 });}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {var desc = {};Object['ke' + 'ys'](descriptor).forEach(function (key) {desc[key] = descriptor[key];});desc.enumerable = !!desc.enumerable;desc.configurable = !!desc.configurable;if ('value' in desc || desc.initializer) {desc.writable = true;}desc = decorators.slice().reverse().reduce(function (desc, decorator) {return decorator(target, property, desc) || desc;}, desc);if (context && desc.initializer !== void 0) {desc.value = desc.initializer ? desc.initializer.call(context) : void 0;desc.initializer = undefined;}if (desc.initializer === void 0) {Object['define' + 'Property'](target, property, desc);desc = null;}return desc;}function _initializerWarningHelper(descriptor, context) {throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');}

var LS_UPDATE = '_parity::update';

var A_MINUTE = 60 * 1000;
var A_DAY = 24 * 60 * A_MINUTE;

var STEP_INFO = 0;
var STEP_UPDATING = 1;
var STEP_COMPLETED = 2;
var STEP_ERROR = 2;

var instance = null;var

Store = (_class = function () {









  function Store(api) {var _this = this;_classCallCheck(this, Store);_initDefineProp(this, 'available', _descriptor, this);_initDefineProp(this, 'consensusCapability', _descriptor2, this);_initDefineProp(this, 'closed', _descriptor3, this);_initDefineProp(this, 'error', _descriptor4, this);_initDefineProp(this, 'remindAt', _descriptor5, this);_initDefineProp(this, 'step', _descriptor6, this);_initDefineProp(this, 'upgrading', _descriptor7, this);_initDefineProp(this, 'version', _descriptor8, this);_initDefineProp(this, 'closeModal', _descriptor9, this);_initDefineProp(this, 'loadStorage', _descriptor10, this);_initDefineProp(this, 'openModal', _descriptor11, this);_initDefineProp(this, 'setStep', _descriptor12, this);_initDefineProp(this, 'snoozeTillTomorrow', _descriptor13, this);_initDefineProp(this, 'upgradeNow', _descriptor14, this);this.











































































    checkUpgrade = function () {
      if (!_this._api) {
        return Promise.resolve(false);
      }

      return Promise.
      all([
      _this._api.parity.upgradeReady(),
      _this._api.parity.consensusCapability(),
      _this._api.parity.versionInfo()]).

      then(function (_ref) {var _ref2 = _slicedToArray(_ref, 3),available = _ref2[0],consensusCapability = _ref2[1],version = _ref2[2];
        if (!_this.version || version.hash !== _this.version.hash) {
          console.log('[checkUpgrade]', 'available:', available, 'version:', (0, _mobx.toJS)(version.version), 'consensusCapability:', consensusCapability);
        }

        _this.setVersions(available, version, consensusCapability);

        return true;
      }).
      catch(function (error) {
        console.warn('checkUpgrade', error);

        return false;
      });
    };this._api = api;this.loadStorage();this.checkUpgrade();}_createClass(Store, [{ key: 'setUpgrading', value: function setUpgrading() {var _this2 = this;(0, _mobx.transaction)(function () {_this2.upgrading = _this2.available;_this2.setStep(STEP_UPDATING, null);});} }, { key: 'setVersions', value: function setVersions(available, version, consensusCapability) {var _this3 = this;(0, _mobx.transaction)(function () {_this3.available = available;_this3.consensusCapability = consensusCapability;_this3.version = version;});} }, { key: 'isVisible', get: function get() {return !this.closed && Date.now() >= this.remindAt;} }], [{ key: 'get', value: function get(

    api) {
      if (!instance) {
        instance = new Store(api);
      }

      return instance;
    } }]);return Store;}(), (_descriptor = _applyDecoratedDescriptor(_class.prototype, 'available', [_mobx.observable], { enumerable: true, initializer: function initializer() {return null;} }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, 'consensusCapability', [_mobx.observable], { enumerable: true, initializer: function initializer() {return null;} }), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, 'closed', [_mobx.observable], { enumerable: true, initializer: function initializer() {return true;} }), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, 'error', [_mobx.observable], { enumerable: true, initializer: function initializer() {return null;} }), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, 'remindAt', [_mobx.observable], { enumerable: true, initializer: function initializer() {return 0;} }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, 'step', [_mobx.observable], { enumerable: true, initializer: function initializer() {return 0;} }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, 'upgrading', [_mobx.observable], { enumerable: true, initializer: function initializer() {return null;} }), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, 'version', [_mobx.observable], { enumerable: true, initializer: function initializer() {return null;} }), _applyDecoratedDescriptor(_class.prototype, 'isVisible', [_mobx.computed], Object.getOwnPropertyDescriptor(_class.prototype, 'isVisible'), _class.prototype), _descriptor9 = _applyDecoratedDescriptor(_class.prototype, 'closeModal', [_mobx.action], { enumerable: true, initializer: function initializer() {var _this4 = this;return function () {(0, _mobx.transaction)(function () {_this4.closed = true;_this4.setStep(0, null);});};} }), _descriptor10 = _applyDecoratedDescriptor(_class.prototype, 'loadStorage', [_mobx.action], { enumerable: true, initializer: function initializer() {var _this5 = this;return function () {var values = _store2.default.get(LS_UPDATE) || {};_this5.remindAt = values.remindAt ? values.remindAt : 0;return values;};} }), _descriptor11 = _applyDecoratedDescriptor(_class.prototype, 'openModal', [_mobx.action], { enumerable: true, initializer: function initializer() {var _this6 = this;return function () {_this6.closed = false;};} }), _descriptor12 = _applyDecoratedDescriptor(_class.prototype, 'setStep', [_mobx.action], { enumerable: true, initializer: function initializer() {var _this7 = this;return function (step) {var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;(0, _mobx.transaction)(function () {_this7.error = error;_this7.step = step;});};} }), _applyDecoratedDescriptor(_class.prototype, 'setUpgrading', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'setUpgrading'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'setVersions', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'setVersions'), _class.prototype), _descriptor13 = _applyDecoratedDescriptor(_class.prototype, 'snoozeTillTomorrow', [_mobx.action], { enumerable: true, initializer: function initializer() {var _this8 = this;return function () {_this8.remindAt = Date.now() + A_DAY;_store2.default.set(LS_UPDATE, Object.assign(_this8.loadStorage(), { remindAt: _this8.remindAt }));};} }), _descriptor14 = _applyDecoratedDescriptor(_class.prototype, 'upgradeNow', [_mobx.action], { enumerable: true, initializer: function initializer() {var _this9 = this;return function () {_this9.setUpgrading();return _this9._api.parity.executeUpgrade().then(function (result) {if (!result) {throw new Error('Unable to complete update');}_this9.setStep(STEP_COMPLETED, null);}).catch(function (error) {console.error('upgradeNow', error);_this9.setStep(STEP_ERROR, error);});};} })), _class);exports.default = Store;exports.



STEP_COMPLETED = STEP_COMPLETED;exports.
STEP_ERROR = STEP_ERROR;exports.
STEP_INFO = STEP_INFO;exports.
STEP_UPDATING = STEP_UPDATING;