"use strict";
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
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_1 = __importStar(require("react"));
var commons_1 = require("@universal-login/commons");
var Safello_1 = require("./OnRamp/Safello");
var Ramp_1 = require("./OnRamp/Ramp");
var Wyre_1 = require("./OnRamp/Wyre");
var TopUpComponentType_1 = require("../../core/models/TopUpComponentType");
var ChooseTopUpMethod_1 = require("./ChooseTopUpMethod");
var ModalWrapper_1 = require("../Modals/ModalWrapper");
var toTopUpComponentType_1 = require("../../core/utils/toTopUpComponentType");
var Spinner_1 = __importDefault(require("../commons/Spinner"));
require("./../styles/topUp.sass");
require("./../styles/topUpDefaults.sass");
var WaitingForOnRampProvider_1 = require("./Fiat/WaitingForOnRampProvider");
exports.TopUp = function (_a) {
    var walletService = _a.walletService, startModal = _a.startModal, modalClassName = _a.modalClassName, hideModal = _a.hideModal, isModal = _a.isModal, topUpClassName = _a.topUpClassName, logoColor = _a.logoColor;
    var _b = __read(react_1.useState(startModal || TopUpComponentType_1.TopUpComponentType.choose), 2), modal = _b[0], setModal = _b[1];
    var _c = __read(react_1.useState(''), 2), amount = _c[0], setAmount = _c[1];
    var relayerConfig = walletService.sdk.getRelayerConfig();
    var contractAddress = walletService.getContractAddress();
    var onPayClick = function (provider, amount) {
        setModal(toTopUpComponentType_1.toTopUpComponentType(provider));
        setAmount(amount);
    };
    var getTopUpMethodChooser = function () { return (react_1.default.createElement(ChooseTopUpMethod_1.ChooseTopUpMethod, { walletService: walletService, onPayClick: onPayClick, topUpClassName: topUpClassName, logoColor: logoColor })); };
    if (!relayerConfig) {
        return react_1.default.createElement(Spinner_1.default, null);
    }
    else if (modal === TopUpComponentType_1.TopUpComponentType.choose) {
        if (isModal) {
            return react_1.default.createElement(ModalWrapper_1.ModalWrapper, { modalClassName: "top-up-modal", hideModal: hideModal }, getTopUpMethodChooser());
        }
        return getTopUpMethodChooser();
    }
    else if (modal === TopUpComponentType_1.TopUpComponentType.safello) {
        return (react_1.default.createElement(ModalWrapper_1.ModalWrapper, { modalClassName: modalClassName, hideModal: function () { return setModal(TopUpComponentType_1.TopUpComponentType.choose); } },
            react_1.default.createElement(Safello_1.Safello, { localizationConfig: {}, safelloConfig: relayerConfig.onRampProviders.safello, contractAddress: contractAddress, crypto: "eth" })));
    }
    else if (modal === TopUpComponentType_1.TopUpComponentType.ramp) {
        return (react_1.default.createElement(Ramp_1.Ramp, { address: contractAddress, amount: commons_1.stringToEther(amount), currency: 'ETH', config: relayerConfig.onRampProviders.ramp, onSuccess: function () { return setModal(TopUpComponentType_1.TopUpComponentType.waitForRamp); }, onCancel: function () { return setModal(TopUpComponentType_1.TopUpComponentType.choose); } }));
    }
    else if (modal === TopUpComponentType_1.TopUpComponentType.wyre) {
        return (react_1.default.createElement(Wyre_1.Wyre, { address: contractAddress, currency: 'ETH', config: relayerConfig.onRampProviders.wyre }));
    }
    else if (modal === TopUpComponentType_1.TopUpComponentType.waitForRamp) {
        return (react_1.default.createElement(ModalWrapper_1.ModalWrapper, { modalClassName: modalClassName },
            react_1.default.createElement(WaitingForOnRampProvider_1.WaitingForOnRampProvider, { className: modalClassName, onRampProviderName: 'ramp', logoColor: logoColor })));
    }
    else {
        throw new Error("Unsupported type: " + modal);
    }
};
//# sourceMappingURL=TopUp.js.map