-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (124 loc) · 5.13 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Svalin</title>
<meta property="og:title" content="Svalin">
<meta property="og:site_name" content="Svalin">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<link rel="stylesheet" href="css/main.css">
<link rel="icon" type="image/png" href="images/favicon.png">
<script src="web3.min.js"></script>
<script language="javascript" type="text/javascript" src="svalin_abi.js"></script>
<script async src="https://checkout.stripe.com/checkout.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script type="module">
import "./main.js"
</script>
</head>
<body>
<div class="container">
<h1>Svalin</h1>
<img id="loader" class="hide" src="https://loading.io/spinners/double-ring/lg.double-ring-spinner.gif">
<div id="web3Status">
Du skal åbne denne side med en browser der understøtter Web3 og aktivere din wallet i browseren. Derefter skal du genindlæse siden.
</div>
<h4 id="userBalance"></h4>
<span>Køb vores lokale valuta Svalin her, der veksles 1:1 med Dkk:</span>
<br><br>
<select class="buy-amount-dkk" type="number" id="recAmount">
<option type="number" value="0">Vælg beløb</option>
<option type="number" value="5000">50 Svalin</option>
<option type="number" value="10000">100 Svalin</option>
<option type="number" value="15000">150 Svalin</option>
<option type="number" value="20000">200 Svalin</option>
<option type="number" value="25000">250 Svalin</option>
</select>
<button class="token-button" id="depositButton">Gå til betaling</button>
<br><br>
<h4>Bilopladning</h4>
<span>Bilopladningen startes ved at overføre 50 Svalin til laderen. Efter endt opladning returneres det resterende beløb inden for få minutter.</span>
<br><br>
<button id="button">Overfør 50 Svalin til lader</button>
<div id="transactionStatus">
<span id="insTrans"></span>
</div>
<input id="userAccount" class="hide"></input>
</div>
<script>
//Detecting if web3 is enabled
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
}
web3.eth.defaultAccount = web3.eth.accounts[0];
var SvalinContract = web3.eth.contract(SvalinABI);
var Svalin = SvalinContract.at('0x6c041fb1e17aa0e95af5b078c45c7397fe3caa0b'); //Chiemgauer token
//var Svalin = SvalinContract.at('0xea75658e5ccc1fb939335a86d6eba759cfd8ec13'); Svalin token
var SvalinCharger = '0x05aa15d93e10953f985c4362711ac342c2817a76';
var UserBalance = 0;
var TransferEventTo = Svalin.Transfer({to: web3.eth.accounts[0]},'latest');
TransferEventTo.watch(function (err, result) {
if (!err) {
if (result.blockHash != $("#instrans").html()) {
$("#loader").hide();
$("#transactionStatus").show();
}
$("#insTrans").html('Transaktions id: ' +result.blockHash);
Svalin.balanceOf(web3.eth.accounts[0], (err, res) => {
if (res) {
UserBalance = Number(res.c/100).toFixed(2);
$("#userBalance").html('Du har : ' + UserBalance + ' Svalin');
}
});
} else {
$("#loader").hide();
}
});
var TransferEventFrom = Svalin.Transfer({from: web3.eth.accounts[0]},'latest');
TransferEventFrom.watch(function (err, result) {
if (!err) {
if (result.blockHash != $("#instrans").html()) {
$("#loader").hide();
$("#transactionStatus").show();
}
$("#insTrans").html('Transaktions id: ' +result.blockHash);
Svalin.balanceOf(web3.eth.accounts[0], (err, res) => {
if (res) {
UserBalance = Number(res.c/100).toFixed(2);
$("#userBalance").html('Du har : ' + UserBalance + ' Svalin');
}
});
} else {
$("#loader").hide();
}
});
$("#button").click(function() {
if (UserBalance >= 50) {
$("#loader").show();
Svalin.transfer(SvalinCharger, 5000, (err, res) => {
if (err)
$("#loader").hide();
});
}
else alert ("Du skal have mindst 50 svalin før du kan lade");
});
Svalin.balanceOf(web3.eth.accounts[0], (err, res) => {
if (res) {
UserBalance = Number(res.c/100).toFixed(2);
$("#userBalance").html('Du har : ' + UserBalance + ' Svalin');
}
});
if (web3.eth.defaultAccount.length >= 40) {
$("#web3Status").hide();
document.getElementById("userAccount").value=web3.eth.defaultAccount;
} else {
$("#web3Status").show();
}
</script>
</body>
</html>