-
Notifications
You must be signed in to change notification settings - Fork 7
/
otherOperations.html
164 lines (144 loc) · 4.15 KB
/
otherOperations.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="notInstalledBanner">Typhon Extension not installed</div>
<div>
<button onclick="readName()">Get Name</button>
<span>Name:</span>
<span id="walletName"></span>
</div>
<div>
<button onclick="readVersion()">Get Version</button>
<span>Version:</span>
<span id="walletVersion"></span>
</div>
<div>
<button onclick="readIcon()">Show Wallet Icon</button>
<span>Wallet Icon:</span>
<img id="logo" src="" height="20" />
</div>
<div>
<button onclick="getNetworkId()">Get Network</button>
<span>NetworkId:</span>
<span id="networkId"></span>
</div>
<div>
<button onclick="getAddress()">Read Receiving Address</button>
<span>address:</span>
<span id="address"></span>
</div>
<div>
<button onclick="getBalance()">Read Balance</button>
</div>
</body>
<script>
var typhon;
window.onload = () => {
if (window.cardano) {
typhon = window.cardano.typhon;
}
if (!typhon) {
document.getElementById("notInstalledBanner").style.display = "block";
}
};
async function _enable() {
// check if site is whitelisted
const isEnabledResponse = await typhon.isEnabled();
if (isEnabledResponse.data) return true;
// Site not white listed, Request user to whitelist
const enableResponse = await typhon.enable();
if (enableResponse.status) {
return true;
}
return false;
}
async function readName() {
if (!typhon) {
console.log("Typhon Extension not installed !");
return;
}
document.getElementById("walletName").innerHTML =
window.cardano.typhon.name;
}
async function readVersion() {
if (!typhon) {
console.log("Typhon Extension not installed !");
return;
}
document.getElementById("walletVersion").innerHTML =
window.cardano.typhon.version;
}
async function readIcon() {
if (!typhon) {
console.log("Typhon Extension not installed !");
return;
}
document
.getElementById("logo")
.setAttribute("src", window.cardano.typhon.icon);
}
async function getNetworkId() {
if (!typhon) {
console.log("Typhon Extension not installed !");
return;
}
// enable
const accessEnabled = await _enable();
if (!accessEnabled) {
console.log("Site not whitelisted !");
return;
}
const networkIdResponse = await window.cardano.typhon.getNetworkId();
if (networkIdResponse.status) {
document.getElementById("networkId").innerHTML = networkIdResponse.data;
} else {
console.log("networkIdResponse: ", networkIdResponse);
}
}
async function getAddress() {
if (!typhon) {
console.log("Typhon Extension not installed !");
return;
}
// enable
const accessEnabled = await _enable();
if (!accessEnabled) {
console.log("Site not whitelisted !");
return;
}
const addressResponse = await window.cardano.typhon.getAddress();
if (addressResponse.status) {
document.getElementById("address").innerHTML = addressResponse.data;
} else {
console.log("addressResponse: ", addressResponse);
}
}
async function getBalance() {
if (!typhon) {
console.log("Typhon Extension not installed !");
return;
}
// enable
const accessEnabled = await _enable();
if (!accessEnabled) {
console.log("Site not whitelisted !");
return;
}
const balanceResponse = await window.cardano.typhon.getBalance();
console.log("balanceResponse: ", balanceResponse);
}
</script>
<style>
#notInstalledBanner {
display: none;
background-color: lightcoral;
padding: 30px;
}
</style>
</html>