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;
};
import React, { useState } from 'react';
import { stringToEther } from '@universal-login/commons';
import { Safello } from './OnRamp/Safello';
import { Ramp } from './OnRamp/Ramp';
import { Wyre } from './OnRamp/Wyre';
import { TopUpComponentType } from '../../core/models/TopUpComponentType';
import { ChooseTopUpMethod } from './ChooseTopUpMethod';
import { ModalWrapper } from '../Modals/ModalWrapper';
import { toTopUpComponentType } from '../../core/utils/toTopUpComponentType';
import Spinner from '../commons/Spinner';
import './../styles/topUp.sass';
import './../styles/topUpDefaults.sass';
import { WaitingForOnRampProvider } from './Fiat/WaitingForOnRampProvider';
export var 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(useState(startModal || TopUpComponentType.choose), 2), modal = _b[0], setModal = _b[1];
    var _c = __read(useState(''), 2), amount = _c[0], setAmount = _c[1];
    var relayerConfig = walletService.sdk.getRelayerConfig();
    var contractAddress = walletService.getContractAddress();
    var onPayClick = function (provider, amount) {
        setModal(toTopUpComponentType(provider));
        setAmount(amount);
    };
    var getTopUpMethodChooser = function () { return (React.createElement(ChooseTopUpMethod, { walletService: walletService, onPayClick: onPayClick, topUpClassName: topUpClassName, logoColor: logoColor })); };
    if (!relayerConfig) {
        return React.createElement(Spinner, null);
    }
    else if (modal === TopUpComponentType.choose) {
        if (isModal) {
            return React.createElement(ModalWrapper, { modalClassName: "top-up-modal", hideModal: hideModal }, getTopUpMethodChooser());
        }
        return getTopUpMethodChooser();
    }
    else if (modal === TopUpComponentType.safello) {
        return (React.createElement(ModalWrapper, { modalClassName: modalClassName, hideModal: function () { return setModal(TopUpComponentType.choose); } },
            React.createElement(Safello, { localizationConfig: {}, safelloConfig: relayerConfig.onRampProviders.safello, contractAddress: contractAddress, crypto: "eth" })));
    }
    else if (modal === TopUpComponentType.ramp) {
        return (React.createElement(Ramp, { address: contractAddress, amount: stringToEther(amount), currency: 'ETH', config: relayerConfig.onRampProviders.ramp, onSuccess: function () { return setModal(TopUpComponentType.waitForRamp); }, onCancel: function () { return setModal(TopUpComponentType.choose); } }));
    }
    else if (modal === TopUpComponentType.wyre) {
        return (React.createElement(Wyre, { address: contractAddress, currency: 'ETH', config: relayerConfig.onRampProviders.wyre }));
    }
    else if (modal === TopUpComponentType.waitForRamp) {
        return (React.createElement(ModalWrapper, { modalClassName: modalClassName },
            React.createElement(WaitingForOnRampProvider, { className: modalClassName, onRampProviderName: 'ramp', logoColor: logoColor })));
    }
    else {
        throw new Error("Unsupported type: " + modal);
    }
};
//# sourceMappingURL=TopUp.js.map