"use strict";

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

function _react() {
  const data = _interopRequireDefault(require("react"));

  _react = function _react() {
    return data;
  };

  return data;
}

function _utils() {
  const data = require("@ddn/utils");

  _utils = function _utils() {
    return data;
  };

  return data;
}

var _config = require("../config");

var _assets = _interopRequireDefault(require("./assets"));

var _assetUtil = require("../utils/asset-util");

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

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

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

function _getFee() {
  _getFee = _asyncToGenerator(function* (transaction) {
    switch (transaction.type) {
      case _utils().assetTypes.TRANSFER:
        // Normal
        return _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

      case _utils().assetTypes.SIGNATURE:
        // Signature
        return _utils().bignum.multiply(_config.constants.net.fees.signature, _config.constants.fixedPoint);

      case _utils().assetTypes.DELEGATE:
        // Delegate
        return _utils().bignum.multiply(_config.constants.net.fees.delegate, _config.constants.fixedPoint);

      case _utils().assetTypes.VOTE:
        // Vote
        return _utils().bignum.multiply(_config.constants.net.fees.vote, _config.constants.fixedPoint);

      case _utils().assetTypes.AOB_TRANSFER:
        // Vote
        return _utils().bignum.multiply(_config.constants.net.fees.aob_transfer, _config.constants.fixedPoint);

      default:
        {
          const fee = yield getAssetFee(transaction); // console.log('getFee: ', fee)

          return fee;
        }
    }
  });
  return _getFee.apply(this, arguments);
}

function getAssetFee(_x2) {
  return _getAssetFee.apply(this, arguments);
}

function _getAssetFee() {
  _getAssetFee = _asyncToGenerator(function* (transaction) {
    let fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const _yield$getAsset = yield (0, _assetUtil.getAsset)(transaction),
          trsName = _yield$getAsset.trsName,
          asset = _yield$getAsset.asset;

    if (asset && typeof _assets.default[trsName] === 'function') {
      fee = yield _assets.default[trsName](asset);
    }

    return fee;
  });
  return _getAssetFee.apply(this, arguments);
}