"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var react_async_script_1 = __importDefault(require("react-async-script"));
var utils_1 = require("@joincivil/utils");
var Button_1 = require("../../Button");
var BuyCVLBase = /** @class */ (function (_super) {
    __extends(BuyCVLBase, _super);
    function BuyCVLBase() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    BuyCVLBase.prototype.render = function () {
        var _this = this;
        return React.createElement(Button_1.Button, { onClick: function () { return _this.displayAirswap(); } }, this.props.buyCVLBtnText || "Buy CVL");
    };
    BuyCVLBase.prototype.displayAirswap = function () {
        var _this = this;
        var environment = utils_1.getAirswapEnv(this.props.network);
        var tokenAddress = utils_1.getAirswapCvlAddress(this.props.network);
        var buyFromAddress = this.props.buyFromAddress || "";
        var amount = this.props.amount || 0;
        // this is pretty hacky, would probably be better off making this a bignumber and converting to wei
        // however, this doesn't display properly in Airswap if its more than 3 digits
        var amountString = Math.ceil(amount).toString() + "000000000000000000";
        console.log("amountString", amountString);
        // @ts-ignore
        window.AirSwap.Trader.render({
            mode: "buy",
            env: environment,
            token: tokenAddress,
            address: buyFromAddress,
            // amount: amountString,
            onComplete: function () {
                _this.props.onComplete();
            },
            onCancel: function () {
                console.info("Trade cancelled");
            },
        }, "body");
    };
    return BuyCVLBase;
}(React.Component));
exports.AirswapBuyCVL = react_async_script_1.default(utils_1.airswapScript)(BuyCVLBase);
//# sourceMappingURL=AirswapBuyCVL.js.map