UNPKG

walletlink-e

Version:
69 lines (68 loc) 2.39 kB
"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.WalletLink = void 0; const cssReset_1 = require("./lib/cssReset"); const WalletLinkProvider_1 = require("./provider/WalletLinkProvider"); const WalletLinkRelay_1 = require("./relay/WalletLinkRelay"); const util_1 = require("./util"); const WALLETLINK_URL = process.env.WALLETLINK_URL || "https://www.walletlink.org"; const WALLETLINK_VERSION = process.env.WALLETLINK_VERSION || require("../package.json").version || "unknown"; class WalletLink { /** * Constructor * @param options WalletLink options object */ constructor(options) { this._appName = ""; this._appLogoUrl = null; this._relay = new WalletLinkRelay_1.WalletLinkRelay({ walletLinkUrl: options.walletLinkUrl || WALLETLINK_URL, version: WALLETLINK_VERSION, darkMode: !!options.darkMode, onDisconnected: options.onDisconnected }); this.setAppInfo(options.appName, options.appLogoUrl); this._relay.attach(document.documentElement); cssReset_1.injectCssReset(); } /** * Create a Web3 Provider object * @param jsonRpcUrl Ethereum JSON RPC URL * @param chainId Ethereum Chain ID (Default: 1) * @returns A Web3 Provider */ makeWeb3Provider(jsonRpcUrl, chainId = 1) { return new WalletLinkProvider_1.WalletLinkProvider({ relay: this._relay, jsonRpcUrl, chainId }); } /** * Set application information * @param appName Application name * @param appLogoUrl Application logo image URL */ setAppInfo(appName, appLogoUrl) { this._appName = appName || "DApp"; this._appLogoUrl = appLogoUrl || util_1.getFavicon(); this._relay.setAppInfo(this._appName, this._appLogoUrl); } /** * Disconnect. After disconnecting, this will reload the web page to ensure * all potential stale state is cleared. */ disconnect() { this._relay.resetAndReload(); } } exports.WalletLink = WalletLink; /** * WalletLink version */ WalletLink.VERSION = WALLETLINK_VERSION;