UNPKG

2.31 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) 2018-2020 WalletLink.org <https://www.walletlink.org/>
3// Copyright (c) 2018-2020 Coinbase, Inc. <https://www.coinbase.com/>
4// Licensed under the Apache License, version 2.0
5Object.defineProperty(exports, "__esModule", { value: true });
6const cssReset_1 = require("./lib/cssReset");
7const WalletLinkProvider_1 = require("./provider/WalletLinkProvider");
8const WalletLinkRelay_1 = require("./relay/WalletLinkRelay");
9const util_1 = require("./util");
10const WALLETLINK_URL = process.env.WALLETLINK_URL || "https://www.walletlink.org";
11const WALLETLINK_VERSION = process.env.WALLETLINK_VERSION ||
12 require("../package.json").version ||
13 "unknown";
14class WalletLink {
15 /**
16 * Constructor
17 * @param options WalletLink options object
18 */
19 constructor(options) {
20 this._appName = "";
21 this._appLogoUrl = null;
22 this._relay = new WalletLinkRelay_1.WalletLinkRelay({
23 walletLinkUrl: options.walletLinkUrl || WALLETLINK_URL,
24 version: WALLETLINK_VERSION,
25 darkMode: !!options.darkMode
26 });
27 this.setAppInfo(options.appName, options.appLogoUrl);
28 this._relay.attach(document.documentElement);
29 cssReset_1.injectCssReset();
30 }
31 /**
32 * Create a Web3 Provider object
33 * @param jsonRpcUrl Ethereum JSON RPC URL
34 * @param chainId Ethereum Chain ID (Default: 1)
35 * @returns A Web3 Provider
36 */
37 makeWeb3Provider(jsonRpcUrl, chainId = 1) {
38 return new WalletLinkProvider_1.WalletLinkProvider({
39 relay: this._relay,
40 jsonRpcUrl,
41 chainId
42 });
43 }
44 /**
45 * Set application information
46 * @param appName Application name
47 * @param appLogoUrl Application logo image URL
48 */
49 setAppInfo(appName, appLogoUrl) {
50 this._appName = appName || "DApp";
51 this._appLogoUrl = appLogoUrl || util_1.getFavicon();
52 this._relay.setAppInfo(this._appName, this._appLogoUrl);
53 }
54 /**
55 * Disconnect. After disconnecting, this will reload the web page to ensure
56 * all potential stale state is cleared.
57 */
58 disconnect() {
59 this._relay.resetAndReload();
60 }
61}
62exports.WalletLink = WalletLink;
63/**
64 * WalletLink version
65 */
66WalletLink.VERSION = WALLETLINK_VERSION;