import _regeneratorRuntime from 'babel-runtime/regenerator';
import _asyncToGenerator from 'babel-runtime/helpers/asyncToGenerator';
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
import klerosPOCArtifact from 'kleros/build/contracts/KlerosPOC';
import _ from 'lodash';

import * as ethConstants from '../../../constants/eth';
import * as errorConstants from '../../../constants/error';
import * as arbitratorConstants from '../../../constants/arbitrator';
import ContractImplementation from '../../ContractImplementation';
import deployContractAsync from '../../../utils/deployContractAsync';
import EventListener from '../../../utils/EventListener';

import Kleros from './Kleros';

/**
 * Provides interaction with a KlerosPOC contract on the blockchain.
 */

var KlerosPOC = function (_Kleros) {
  _inherits(KlerosPOC, _Kleros);

  /**
   * Create new KlerosPOC Implementation.
   * @param {object} web3Provider - web3 instance.
   * @param {string} contractAddress - Address of the KlerosPOC contract.
   */
  function KlerosPOC(web3Provider, contractAddress) {
    var _this2 = this;

    _classCallCheck(this, KlerosPOC);

    var _this = _possibleConstructorReturn(this, (KlerosPOC.__proto__ || _Object$getPrototypeOf(KlerosPOC)).call(this, web3Provider, contractAddress, klerosPOCArtifact));

    _this.buyPNK = function () {
      var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(amount) {
        var account = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this._Web3Wrapper.getAccount(0);
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return _this.loadContract();

              case 2:
                _context.prev = 2;
                return _context.abrupt('return', _this.contractInstance.buyPinakion({
                  from: account,
                  gas: ethConstants.TRANSACTION.GAS,
                  value: _this._Web3Wrapper.toWei(amount, 'ether')
                }));

              case 6:
                _context.prev = 6;
                _context.t0 = _context['catch'](2);

                console.error(_context.t0);
                throw new Error(errorConstants.UNABLE_TO_BUY_PNK);

              case 10:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, _this2, [[2, 6]]);
      }));

      return function (_x) {
        return _ref.apply(this, arguments);
      };
    }();

    return _this;
  }

  /**
   * Purchase PNK.
   * @param {string} amount - The number of pinakion to buy.
   * @param {string} account - The address of the user.
   * @returns {object} - The result transaction object.
   */


  return KlerosPOC;
}(Kleros);

export default KlerosPOC;
//# sourceMappingURL=KlerosPOC.js.map