-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
66 lines (57 loc) · 2.21 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Webpack App</title>
<script src="./dist/main.js" ></script>
</head>
<body>
<h1>Hello world!</h1>
<h2>Tip: Check your console</h2>
</body>
<script type="text/javascript" defer>
// We start by initializing the controller
let walletConnected = false;
function connectedFallback(){
let state = window.terraWallet.getConnectState();
if(state?.state?.status == window.terraWallet.WalletStatus.WALLET_CONNECTED){
console.log("connected")
console.log(state.state.wallets[0].terraAddress)
}else{
console.log("not connected yet")
setTimeout(connectedFallback, 500)
}
}
let maxRetry = 0;
function load_extension(){
let controller;
window.terraWallet.initController().then(
()=> {
controller = window.terraWallet.getController();
window.terraWallet.mount()
}
);
async function tryConnectWallet(){
let state = window.terraWallet.getConnectState()
if((!state.state || state.state.status == window.terraWallet.WalletStatus.INITIALIZING) && maxRetry<5){
maxRetry++;
setTimeout(tryConnectWallet, 1000)
}else if(state.state.status == window.terraWallet.WalletStatus.WALLET_NOT_CONNECTED){
let connectTypes = state.availableConnectTypes;
let installTypes = state.availableInstallTypes;
let types = state.availableConnections;
if(!connectTypes.includes("EXTENSION")){
await controller.install("EXTENSION");
}else {
await controller.connect("EXTENSION");
}
console.log("Mounted tried");
}
}
setTimeout(tryConnectWallet, 500);
setTimeout(connectedFallback, 500);
return
}
load_extension();
</script>
</html>