-
Notifications
You must be signed in to change notification settings - Fork 4
/
examples.html
132 lines (121 loc) · 5.03 KB
/
examples.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
<html lang="en">
<head>
<title>Bitgreen Browser Wallet Examples</title>
</head>
<body>
<h1>Bitgreen Browser Wallet Examples</h1>
<h4>Wallet Status: <span class="wallet-status"></span></h4>
<a href="https://bitgreen.org" title="Bitgreen">Bitgreen</a>
<hr>
<button id="portfolio">Portfolio</button>
<button id="sign_in">Sign In</button>
<button id="send">Send 1 BBB</button>
<button id="create_asset">Create Asset</button>
<button id="batch_call">Batch Call</button>
<button id="query_balance">Query Balance</button>
<button id="sell_order">Create Sell Order</button>
<script>
window.addEventListener('load', async() => {
const bitgreen_wallet = window.injectedWeb3?.['bitgreen-wallet-js']
// check if wallet code is injected
if(!bitgreen_wallet) {
document.querySelector('.wallet-status').innerHTML = 'not installed'
document.querySelector('.wallet-status').classList.add('red-text')
} else {
document.querySelector('.wallet-status').innerHTML = 'installed'
document.querySelector('.wallet-status').classList.add('green-text')
}
document.querySelector('#portfolio').addEventListener('click', () => {
bitgreen_wallet.open()
})
document.querySelector('#sign_in').addEventListener('click', () => {
bitgreen_wallet.signIn().then((response) => {
if(response.success) {
alert(`Successful sign in from address ${response.data.address}`)
} else {
alert(`Sign in failed. Status: ${response.status}. Error: ${response.error}`)
}
})
})
document.querySelector('#send').addEventListener('click', () => {
bitgreen_wallet.send(1, '5EUBUgvGccFJrcqxkrifU9GbDvtvzVC6iftXZNPSZwdUJNnn').then((response) => {
if(response.success) {
alert(`Successfully sent transaction at block: ${response.data.block_hash}`)
} else {
alert(`Transaction failed. Status: ${response.status}. Error: ${response.error}`)
}
})
})
document.querySelector('#query_balance').addEventListener('click', () => {
bitgreen_wallet.query('balances', 'account', ['5GqFxK56NW4gTsuLC6xhHVSLp5xURYuQJHoJA6NGVy259fSJ']).then((response) => {
if(response.data.free !== undefined) {
alert('Balance for this address is: ' + response.data.free)
}
})
})
document.querySelector('#create_asset').addEventListener('click', () => {
bitgreen_wallet.extrinsic('assets', 'create', [
100000,
'5GGoUgUtw7tvQyJ7tknapdXkmZnduJbk2RJQNPMKqe7ufRCj',
1
]).then((response) => {
if(response.success) {
alert(`Successfully sent transaction at block: ${response.data.block_hash}`)
} else {
alert(`Transaction failed. Status: ${response.status}. Error: ${response.error}`)
}
})
})
document.querySelector('#batch_call').addEventListener('click', () => {
bitgreen_wallet.extrinsic('utility', 'batch', [
['balances', 'transfer', [
'5GqFxK56NW4gTsuLC6xhHVSLp5xURYuQJHoJA6NGVy259fSJ',
10
]],
['assets', 'create', [
100003,
'5GqFxK56NW4gTsuLC6xhHVSLp5xURYuQJHoJA6NGVy259fSJ',
1
]],
['balances', 'transfer', [
'5GqFxK56NW4gTsuLC6xhHVSLp5xURYuQJHoJA6NGVy259fSJ',
20
]]
]).then((response) => {
if(response.success) {
alert(`Successfully sent transaction at block: ${response.data.block_hash}`)
} else {
alert(`Transaction failed. Status: ${response.status}. Error: ${response.error}`)
}
})
})
document.querySelector('#sell_order').addEventListener('click', () => {
bitgreen_wallet.extrinsic('dex', 'createSellOrder', [
7,
100,
Math.pow(10, 18).toString()
]).then((response) => {
if(response.success) {
alert(`Successfully sent transaction at block: ${response.data.block_hash}`)
} else {
alert(`Transaction failed. Status: ${response.status}. Error: ${response.error}`)
}
})
})
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
if(params.deposit_habbits) {
bitgreen_wallet.send(256, '5EUBUgvGccFJrcqxkrifU9GbDvtvzVC6iftXZNPSZwdUJNnn', false)
}
})
</script>
<style>
.green-text {
color: #2dc72d;
}
.red-text {
color: #e11e1e;
}
</style>
</body>
</html>