'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.default = undefined;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; // 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 _lodash = require('lodash');
var _mobx = require('mobx');function _defineProperty(obj, key, value) {if (key in obj) {Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });} else {obj[key] = value;}return 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

SignerStore = (_class = function () {





  function SignerStore(api) {var _this = this;var withLocalTransactions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;var externalLink = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';_classCallCheck(this, SignerStore);_initDefineProp(this, 'balances', _descriptor, this);_initDefineProp(this, 'localHashes', _descriptor2, this);this.externalLink = '';_initDefineProp(this, 'setBalance', _descriptor3, this);_initDefineProp(this, 'setBalances', _descriptor4, this);_initDefineProp(this, 'setLocalHashes', _descriptor5, this);this.































































    fetchLocalTransactions = function () {
      var nextTimeout = function nextTimeout() {
        _this._timeoutId = setTimeout(_this.fetchLocalTransactions, 1500);
      };

      _this._api.parity.
      localTransactions().
      then(function (localTransactions) {
        var keys = Object.
        keys(localTransactions).
        filter(function (key) {return localTransactions[key].status !== 'canceled';});

        _this.setLocalHashes(keys);
      }).
      then(function () {return nextTimeout();}).
      catch(function () {return nextTimeout();});
    };this._api = api;this._timeoutId = 0;this.externalLink = externalLink;if (withLocalTransactions) {this.fetchLocalTransactions();}}_createClass(SignerStore, [{ key: 'unsubscribe', value: function unsubscribe() {if (this._timeoutId) {clearTimeout(this._timeoutId);}} }, { key: 'fetchBalance', value: function fetchBalance(address) {var _this2 = this;this._api.eth.getBalance(address).then(function (balance) {_this2.setBalance(address, balance);}).catch(function (error) {console.warn('Store:fetchBalance', error);});} }, { key: 'fetchBalances', value: function fetchBalances(_addresses) {var _this3 = this;var addresses = _addresses.filter(function (address) {return address;}) || [];if (!addresses.length) {return;}Promise.all(addresses.map(function (address) {return _this3._api.eth.getBalance(address);})).then(function (_balances) {_this3.setBalances(addresses.reduce(function (balances, address, index) {balances[address] = _balances[index];return balances;}, {}));}).catch(function (error) {console.warn('Store:fetchBalances', error);});} }]);return SignerStore;}(), (_descriptor = _applyDecoratedDescriptor(_class.prototype, 'balances', [_mobx.observable], { enumerable: true, initializer: function initializer() {return {};} }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, 'localHashes', [_mobx.observable], { enumerable: true, initializer: function initializer() {return [];} }), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, 'setBalance', [_mobx.action], { enumerable: true, initializer: function initializer() {var _this4 = this;return function (address, balance) {_this4.setBalances(_defineProperty({}, address, balance));};} }), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, 'setBalances', [_mobx.action], { enumerable: true, initializer: function initializer() {var _this5 = this;return function (balances) {_this5.balances = Object.assign({}, _this5.balances, balances);};} }), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, 'setLocalHashes', [_mobx.action], { enumerable: true, initializer: function initializer() {var _this6 = this;return function () {var localHashes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; // Use slice to make sure they are both Arrays (MobX uses Objects for Observable Arrays)
      if (!(0, _lodash.isEqual)(localHashes.slice(), _this6.localHashes.slice())) {_this6.localHashes = localHashes;}};} }), _applyDecoratedDescriptor(_class.prototype, 'unsubscribe', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'unsubscribe'), _class.prototype)), _class);exports.default = SignerStore;