"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var react_router_dom_1 = require("react-router-dom");
var NavigationColumn_1 = require("./ui/commons/NavigationColumn");
var WalletSelector_1 = require("./ui/WalletSelector/WalletSelector");
var EmojiForm_1 = require("./ui/Notifications/EmojiForm");
var commons_1 = require("@universal-login/commons");
var EmojiPanel_1 = require("./ui/WalletSelector/EmojiPanel");
var Settings_1 = require("./ui/Settings/Settings");
var Onboarding_1 = require("./ui/Onboarding/Onboarding");
var useServices_1 = require("./core/services/useServices");
var LogoButton_1 = require("./ui/UFlow/LogoButton");
var CreateRandomInstance_1 = require("./ui/commons/CreateRandomInstance");
require("./ui/styles/playground.css");
var sdk_1 = require("@universal-login/sdk");
var Spinner_1 = require("./ui/commons/Spinner");
var useAsync_1 = require("./ui/hooks/useAsync");
var sdk_2 = require("@universal-login/sdk");
var mockNotifications_1 = require("./ui/PlaygroundUtils/mockNotifications");
var ModalWrapper_1 = require("./ui/Modals/ModalWrapper");
var WaitingForOnRampProvider_1 = require("./ui/TopUp/Fiat/WaitingForOnRampProvider");
var TopUp_1 = require("./ui/TopUp/TopUp");
var WaitingForTransaction_1 = require("./ui/commons/WaitingForTransaction");
var ThemesPlayground_1 = require("./ui/Playground/ThemesPlayground");
var Theme_1 = require("./ui/themes/Theme");
exports.App = function () {
    var sdk = useServices_1.useServices().sdk;
    var _a = __read(useAsync_1.useAsync(function () { return __awaiter(void 0, void 0, void 0, function () {
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, sdk.fetchRelayerConfig()];
                case 1:
                    _a.sent();
                    return [2 /*return*/, sdk.getRelayerConfig()];
            }
        });
    }); }, []), 1), relayerConfig = _a[0];
    sdk_1.setBetaNotice(sdk);
    var _b = __read(react_1.useState(function () { return new sdk_2.WalletService(sdk); }), 1), walletService = _b[0];
    var name = 'test.mylogin.eth';
    var deployingWallet = new sdk_1.DeployingWallet({
        contractAddress: commons_1.TEST_ACCOUNT_ADDRESS,
        name: name,
        privateKey: commons_1.TEST_PRIVATE_KEY,
        deploymentHash: commons_1.TEST_MESSAGE_HASH,
    }, sdk);
    var futureWallet = {
        contractAddress: commons_1.TEST_ACCOUNT_ADDRESS,
        privateKey: commons_1.TEST_PRIVATE_KEY,
        deploy: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
            return [2 /*return*/, deployingWallet];
        }); }); },
        waitForBalance: (function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
            return [2 /*return*/];
        }); }); }),
        setSupportedToken: (function () { }),
    };
    function tryEnablingMetamask() {
        return __awaiter(this, void 0, void 0, function () {
            var ethereum, error_1;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        ethereum = window.ethereum;
                        if (!ethereum) return [3 /*break*/, 4];
                        _a.label = 1;
                    case 1:
                        _a.trys.push([1, 3, , 4]);
                        return [4 /*yield*/, ethereum.enable()];
                    case 2:
                        _a.sent();
                        return [2 /*return*/, ethereum.selectedAddress];
                    case 3:
                        error_1 = _a.sent();
                        return [3 /*break*/, 4];
                    case 4: return [2 /*return*/];
                }
            });
        });
    }
    return (react_1.default.createElement(react_router_dom_1.BrowserRouter, null,
        react_1.default.createElement(Theme_1.ThemeProvider, null,
            react_1.default.createElement("div", { className: "playground" },
                react_1.default.createElement(NavigationColumn_1.NavigationColumn, null),
                react_1.default.createElement("div", { className: "playground-content" },
                    react_1.default.createElement(react_router_dom_1.Switch, null,
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/", render: function () { return (react_1.default.createElement("p", null, "Welcome to Universal Login")); } }),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/themes", render: function () { return react_1.default.createElement(ThemesPlayground_1.ThemesPlayground, null); } }),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/logoButton" },
                            react_1.default.createElement("div", null,
                                react_1.default.createElement("button", { onClick: function () { return mockNotifications_1.mockNotifications(sdk); } }, "Create mock notifications"),
                                react_1.default.createElement("hr", null),
                                react_1.default.createElement(CreateRandomInstance_1.CreateRandomInstance, { walletService: walletService }),
                                react_1.default.createElement("hr", null),
                                react_1.default.createElement(LogoButton_1.LogoButton, { walletService: walletService }))),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/onboarding/success", render: function (_a) {
                                var history = _a.history;
                                return react_1.default.createElement(react_1.default.Fragment, null,
                                    react_1.default.createElement("div", null, " Success!!! "),
                                    react_1.default.createElement("br", null),
                                    react_1.default.createElement("button", { onClick: function () {
                                            walletService.disconnect();
                                            history.push('/onboarding');
                                        } }, "Disconnect"));
                            } }),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/onboarding", render: function (_a) {
                                var history = _a.history;
                                return react_1.default.createElement(Onboarding_1.Onboarding, { sdk: sdk, walletService: walletService, domains: ['mylogin.eth', 'universal-id.eth', 'poppularapp.eth'], tryEnablingMetamask: tryEnablingMetamask, onConnect: function () { return console.log('connected'); }, onCreate: function () { return history.push('/onboarding/success'); }, hideModal: function () { return history.push('/'); } });
                            } }),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/walletSelector" },
                            react_1.default.createElement(WalletSelector_1.WalletSelector, { onCreateClick: function () { console.log('create'); }, onConnectClick: function () { console.log('connect'); }, sdk: sdk, domains: ['mylogin.eth', 'myapp.eth'] })),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/keyboard", render: function () {
                                return relayerConfig ? (react_1.default.createElement("div", null,
                                    react_1.default.createElement(EmojiPanel_1.EmojiPanel, { code: commons_1.generateCode(mockNotifications_1.CONNECTION_REAL_ADDRESS) }),
                                    react_1.default.createElement("hr", null),
                                    react_1.default.createElement(EmojiForm_1.EmojiForm, { notifications: [], onDenyClick: function () { }, setPublicKey: function () { } }))) : react_1.default.createElement(Spinner_1.Spinner, null);
                            } }),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/topUp", render: function () {
                                return react_1.default.createElement("div", null,
                                    react_1.default.createElement(react_router_dom_1.Link, { to: "/topUpRegular" }, "Regular"),
                                    react_1.default.createElement("br", null),
                                    react_1.default.createElement(react_router_dom_1.Link, { to: "/topUpDeployment" }, "Deployment"));
                            } }),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/topUpRegular", render: function () {
                                var topUpWalletService = new sdk_2.WalletService(sdk);
                                var topUpDeployedWallet = new sdk_1.DeployedWallet(commons_1.TEST_CONTRACT_ADDRESS, 'bob.mylogin.eth', commons_1.TEST_PRIVATE_KEY, sdk);
                                topUpWalletService.setWallet(topUpDeployedWallet.asApplicationWallet);
                                if (!relayerConfig) {
                                    return react_1.default.createElement(Spinner_1.Spinner, null);
                                }
                                return react_1.default.createElement(TopUp_1.TopUp, { walletService: topUpWalletService, hideModal: function () { return history.back(); }, isModal: true });
                            } }),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/topUpDeployment", render: function () {
                                var topUpWalletService = new sdk_2.WalletService(sdk);
                                topUpWalletService.setFutureWallet(futureWallet, name);
                                if (!relayerConfig) {
                                    return react_1.default.createElement(Spinner_1.Spinner, null);
                                }
                                return react_1.default.createElement(TopUp_1.TopUp, { walletService: topUpWalletService, hideModal: function () { return history.back(); }, isModal: true });
                            } }),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/settings", render: function () { return react_1.default.createElement(Settings_1.Settings, { deployedWallet: new sdk_1.DeployedWallet(commons_1.TEST_CONTRACT_ADDRESS, 'bob.mylogin.eth', commons_1.TEST_PRIVATE_KEY, sdk) }); } }),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/recover", render: function () { return (react_1.default.createElement("div", null,
                                react_1.default.createElement("p", null, "Recover"))); } }),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/waiting" },
                            react_1.default.createElement(ModalWrapper_1.ModalWrapper, null,
                                react_1.default.createElement(WaitingForOnRampProvider_1.WaitingForOnRampProvider, { onRampProviderName: 'ramp' }))),
                        react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/waitForTransaction" },
                            react_1.default.createElement("div", null,
                                react_1.default.createElement(ThemesPlayground_1.ThemesPlayground, null),
                                react_1.default.createElement(react_router_dom_1.Link, { to: "/waitForTransactionWithHash" }, "With hash"),
                                react_1.default.createElement("br", null),
                                react_1.default.createElement(react_router_dom_1.Link, { to: "/waitForTransactionWithoutHash" }, "Without hash"))),
                        react_1.default.createElement(react_router_dom_1.Route, { path: "/waitForTransactionWithHash", render: function (_a) {
                                var location = _a.location;
                                if (!relayerConfig) {
                                    return react_1.default.createElement(Spinner_1.Spinner, null);
                                }
                                else {
                                    return (react_1.default.createElement(ModalWrapper_1.ModalWrapper, { hideModal: function () { return console.log('hide modal'); }, message: "This is a test environment running on Ropsten network" },
                                        react_1.default.createElement(WaitingForTransaction_1.WaitingForTransaction, { action: "Waiting for transfer", relayerConfig: relayerConfig, transactionHash: commons_1.TEST_TRANSACTION_HASH })));
                                }
                            } }),
                        react_1.default.createElement(react_router_dom_1.Route, { path: "/waitForTransactionWithoutHash", render: function (_a) {
                                var location = _a.location;
                                if (!relayerConfig) {
                                    return react_1.default.createElement(Spinner_1.Spinner, null);
                                }
                                else {
                                    return (react_1.default.createElement(ModalWrapper_1.ModalWrapper, { hideModal: function () { return console.log('hide modal'); }, message: "This is a test environment running on Ropsten network" },
                                        react_1.default.createElement(WaitingForTransaction_1.WaitingForTransaction, { action: "Waiting for transfer", relayerConfig: relayerConfig, transactionHash: undefined })));
                                }
                            } }),
                        react_1.default.createElement(react_router_dom_1.Route, { component: function () { return (react_1.default.createElement("p", null, "not found")); } })))))));
};
exports.default = exports.App;
//# sourceMappingURL=App.js.map