-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
38 lines (34 loc) · 946 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { enableMetamask } from "./src/example";
const btnEnableMetamask = document.getElementById("btnEnableMetamask");
const console = document.getElementById("console");
btnEnableMetamask.addEventListener("click", async () => {
printMessage("Enabling metamask.");
let error = null;
try {
await enableMetamask();
} catch (e) {
error = e;
}
if (error) {
printError(error);
} else {
printMessage("Metamask enabled.");
}
});
function printMessage(message: any) {
if (typeof message !== "string") {
message = JSON.stringify(message, null, 2);
}
const div = document.createElement("div");
div.innerText = message;
console.prepend(div);
}
function printError(message: any) {
if (typeof message !== "string") {
message = JSON.stringify(message, null, 2);
}
const div = document.createElement("div");
div.innerText = "Error: " + message;
div.className = "error";
console.prepend(div);
}