'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _KlerosPOC = require('kleros/build/contracts/KlerosPOC');

var _KlerosPOC2 = _interopRequireDefault(_KlerosPOC);

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _eth = require('../../../constants/eth');

var ethConstants = _interopRequireWildcard(_eth);

var _error = require('../../../constants/error');

var errorConstants = _interopRequireWildcard(_error);

var _arbitrator = require('../../../constants/arbitrator');

var arbitratorConstants = _interopRequireWildcard(_arbitrator);

var _ContractImplementation = require('../../ContractImplementation');

var _ContractImplementation2 = _interopRequireDefault(_ContractImplementation);

var _deployContractAsync = require('../../../utils/deployContractAsync');

var _deployContractAsync2 = _interopRequireDefault(_deployContractAsync);

var _EventListener = require('../../../utils/EventListener');

var _EventListener2 = _interopRequireDefault(_EventListener);

var _Kleros2 = require('./Kleros');

var _Kleros3 = _interopRequireDefault(_Kleros2);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Provides interaction with a KlerosPOC contract on the blockchain.
 */
var KlerosPOC = function (_Kleros) {
  (0, _inherits3.default)(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;

    (0, _classCallCheck3.default)(this, KlerosPOC);

    var _this = (0, _possibleConstructorReturn3.default)(this, (KlerosPOC.__proto__ || (0, _getPrototypeOf2.default)(KlerosPOC)).call(this, web3Provider, contractAddress, _KlerosPOC2.default));

    _this.buyPNK = function () {
      var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(amount) {
        var account = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this._Web3Wrapper.getAccount(0);
        return _regenerator2.default.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;
}(_Kleros3.default);

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