'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;}; // 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 _reduxActions = require('redux-actions');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;}

var initialState = {
  wallets: {},
  walletsAddresses: [],
  filterSubId: null,
  contract: null };exports.default =


(0, _reduxActions.handleActions)({
  updateWallets: function updateWallets(state, action) {var
    wallets = action.wallets,walletsAddresses = action.walletsAddresses,filterSubId = action.filterSubId;

    return _extends({},
    state, {
      wallets: wallets, walletsAddresses: walletsAddresses, filterSubId: filterSubId });

  },

  updateWalletsDetails: function updateWalletsDetails(state, action) {var
    wallets = action.wallets;
    var prevWallets = state.wallets;

    var nextWallets = _extends({}, prevWallets);

    Object.values(wallets).forEach(function (wallet) {
      var prevWallet = prevWallets[wallet.address] || {};

      nextWallets[wallet.address] = _extends({
        instance: state.contract && state.contract.instance || null },
      prevWallet,
      wallet);

    });

    return _extends({},
    state, {
      wallets: nextWallets });

  },

  setWalletContract: function setWalletContract(state, action) {var
    contract = action.contract;

    return _extends({},
    state, {
      contract: contract });

  },

  setOperationPendingState: function setOperationPendingState(state, action) {var
    address = action.address,operation = action.operation,isPending = action.isPending;var
    wallets = state.wallets;

    var wallet = _extends({}, wallets[address]);

    wallet.confirmations = wallet.confirmations.map(function (conf) {
      if (conf.operation === operation) {
        conf.pending = isPending;
      }

      return conf;
    });

    return _extends({},
    state, {
      wallets: _extends({},
      wallets, _defineProperty({},
      address, wallet)) });


  } },
initialState);