"use strict";

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

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

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

  return data;
}

function _bytebuffer() {
  const data = _interopRequireDefault(require("bytebuffer"));

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

  return data;
}

var _constants = _interopRequireDefault(require("../../constants"));

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); }); }; }

var _default = {
  dapp: function () {
    var _dapp2 = _asyncToGenerator(function* (_dapp) {
      let buf = Buffer.from([]);
      const nameBuf = Buffer.from(_dapp.name, 'utf8');
      buf = Buffer.concat([buf, nameBuf]);

      if (_dapp.description) {
        const descriptionBuf = Buffer.from(_dapp.description, 'utf8');
        buf = Buffer.concat([buf, descriptionBuf]);
      }

      if (_dapp.tags) {
        const tagsBuf = Buffer.from(_dapp.tags, 'utf8');
        buf = Buffer.concat([buf, tagsBuf]);
      }

      if (_dapp.link) {
        buf = Buffer.concat([buf, Buffer.from(_dapp.link, 'utf8')]);
      }

      if (_dapp.icon) {
        buf = Buffer.concat([buf, Buffer.from(_dapp.icon, 'utf8')]);
      }

      const bb = new (_bytebuffer().default)(1, true);
      bb.writeInt(_dapp.type);
      bb.writeInt(_dapp.category);

      if (_dapp.delegates) {
        if (_dapp.delegates instanceof Array) {
          _dapp.delegates = _dapp.delegates.join(',');
        }

        bb.writeString(_dapp.delegates);
      }

      if (_dapp.unlock_delegates || _dapp.unlock_delegates === 0) {
        bb.writeInt(_dapp.unlock_delegates);
      }

      bb.flip();
      buf = Buffer.concat([buf, bb.toBuffer()]);
      return buf;
    });

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

    return dapp;
  }(),
  dappIn: function () {
    var _dappIn = _asyncToGenerator(function* (transfer) {
      let buf = Buffer.from([]);
      const dappId = Buffer.from(transfer.dapp_id, 'utf8');

      if (transfer.currency !== _constants.default.tokenName) {
        const currency = Buffer.from(transfer.currency, 'utf8');
        const amount = Buffer.from(transfer.amount, 'utf8');
        buf = Buffer.concat([buf, dappId, currency, amount]);
      } else {
        const currency = Buffer.from(transfer.currency, 'utf8');
        buf = Buffer.concat([buf, dappId, currency]);
      }

      return buf;
    });

    function dappIn(_x2) {
      return _dappIn.apply(this, arguments);
    }

    return dappIn;
  }(),
  dappOut: function () {
    var _dappOut = _asyncToGenerator(function* (transfer) {
      let buf = Buffer.from([]);
      const dappId = Buffer.from(transfer.dapp_id, 'utf8');

      if (transfer.currency !== _constants.default.tokenName) {
        const currency = Buffer.from(transfer.currency, 'utf8');
        const amount = Buffer.from(transfer.amount, 'utf8');
        buf = Buffer.concat([buf, dappId, currency, amount]);
      } else {
        const currency = Buffer.from(transfer.currency, 'utf8');
        buf = Buffer.concat([buf, dappId, currency]);
      }

      return buf;
    });

    function dappOut(_x3) {
      return _dappOut.apply(this, arguments);
    }

    return dappOut;
  }()
};
exports.default = _default;