-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsona1.html
183 lines (137 loc) · 3.73 KB
/
sona1.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<html>
<head>
<title>Sona</Title>
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
<script type="text/javascript" src="./abi.json"></script>
<link rel="stylesheet" type="text/css" href="./style.css">
<script>
var contractABI = abi;
</script>
</head>
<body>
<header>
<h1>SONA</h1>
</header>
<nav class="navigation">
<a href="#balance">balance</a>
<a href="#">current rating</a>
<a href="#">my QR code</a>
<a href="#">scan QR code</a>
</nav>
<div id="balance">
<hr>
<h2>balance</h2>
<label>SNA:</label>
<p id="snabalance">SNA: </p>
</div>
<div>
<h2>
Transfer Sona
</h2>
<label>address:</label>
<input id="transID" type="text">
<label>amount:</label>
<input id="transfer-amount" type="number">
<button onclick="transferSona()">Send Sona</button>
</div>
<div>
<hr>
<h2>current rating</h2>
<p id="current-rating">Sona rating: </p>
</div>
<div id="show-my-qr-code">
<hr>
<h2>My Sona Code</h2>
<img id="qrCode">
<h3>share my QR code</h3>
</div>
<div class="rateUser">
<h2>rate user</h2>
<label>enter user address: </label>
<input id="rateID" type="text">
<br>
<label>comment:</label>
<input id="comment" type="text">
<br>
<br>
</div>
<div id="collect-tokens">
<hr>
<p> collect the coins you earned!</p>
<h2>collect tokens</h2>
<button onclick="collect()">Collect Your Sona!</button>
<h3>your deadline</h3>
</div>
<div>
<h2>Create a Personal Post</h2>
<input id="postText" type="text">
<button onclick="newPost()">Submit Post</button>
</div>
<hr>
<div>
<h2>become a user</h2>
<button onclick="becomeSonaUser()">I want to be a user</button>
<p id="becomeUser"></p>
</div>
<div id="buySONA">
<hr>
<h2>Buy Sona Tokens</h2>
<input id="buyAmount"type="text">
<button onclick="buySona()">Buy Sona</button>
<script>
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof Web3 !== 'undefined') {
// Use Mist/MetaMask's provider
web3 = new Web3(web3.currentProvider);
} else {
console.log('No web3? You should consider trying MetaMask!')
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
var sonaContract = web3.eth.contract(abi);
var sona = sonaContract.at('0x2183900ebc0a060c0971cb8379faae73bd90f250');
console.log(sona);
web3.eth.defaultAccount = web3.eth.accounts[0];
sona.getSonaBalance(function(error, result){
if(!error)
{
result = result /1000000000000000000;
document.getElementById('snabalance').innerHTML = result;
}
else
console.error(error);
});
sona.getMyRating(function (result, error){
if(!error){
console.log(result);
document.getElementById('current-rating').innerHTML = result;
}
});
function becomeSonaUser() {
sona.becomeUser( function (result, error){
if (!error){
console.log(result);
} else {
console.error(error);
}
});
}
function transferSona () {
var toAddress = document.getElementById('transID').innerText;
var amount = document.getElementById('transfer-amount').innerText;
sona.transfer(toAddress, amount, function (result, error){
if (!error){
console.log(result);
}
});
}
function collect() {
sona.collectReward(function (result, error){
if (!error){
console.log(result);
}
})
}
</script>
</body>
</html>