walletlink-e
Version:
WalletLink JavaScript SDK
63 lines (62 loc) • 2.21 kB
JavaScript
"use strict";
// Copyright (c) 2018-2020 WalletLink.org <https://www.walletlink.org/>
// Copyright (c) 2018-2020 Coinbase, Inc. <https://www.coinbase.com/>
// Licensed under the Apache License, version 2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkFlow = void 0;
const preact_1 = require("preact");
const rxjs_1 = require("rxjs");
const LinkDialog_1 = require("./LinkDialog");
class LinkFlow {
constructor(options) {
this.subscriptions = new rxjs_1.Subscription();
this.isConnected = false;
this.isOpen = false;
this.onCancel = null;
this.root = null;
this.darkMode = options.darkMode;
this.version = options.version;
this.sessionId = options.sessionId;
this.sessionSecret = options.sessionSecret;
this.walletLinkUrl = options.walletLinkUrl;
this.connected$ = options.connected$;
}
attach(el) {
this.root = document.createElement("div");
this.root.className = "-walletlink-link-flow-root";
el.appendChild(this.root);
this.render();
this.subscriptions.add(this.connected$.subscribe(v => {
if (this.isConnected !== v) {
this.isConnected = v;
this.render();
}
}));
}
detach() {
var _a;
if (!this.root) {
return;
}
this.subscriptions.unsubscribe();
preact_1.render(null, this.root);
(_a = this.root.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(this.root);
}
open(options) {
this.isOpen = true;
this.onCancel = options.onCancel;
this.render();
}
close() {
this.isOpen = false;
this.onCancel = null;
this.render();
}
render() {
if (!this.root) {
return;
}
preact_1.render(preact_1.h(LinkDialog_1.LinkDialog, { darkMode: this.darkMode, version: this.version, sessionId: this.sessionId, sessionSecret: this.sessionSecret, walletLinkUrl: this.walletLinkUrl, isOpen: this.isOpen, isConnected: this.isConnected, onCancel: this.onCancel }), this.root);
}
}
exports.LinkFlow = LinkFlow;