-
Notifications
You must be signed in to change notification settings - Fork 3
/
settings.html
153 lines (131 loc) · 5.08 KB
/
settings.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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script language="javascript" type="text/javascript" src="./web3/dist/web3.min.js"></script>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="header">
<div class="header-right">
<a href="index.html">CREATE</a>
<a class="active" href="settings.html">SETTINGS</a>
<a href="token.html">TOKEN</a>
</div>
</div>
<div class="container">
<h1>Admin Panel</h1>
<div class="column">
<div class="row">
<div class="col-25">
<label>Token Address</label>
</div>
<div class="col-75">
<input type="text" id="tokenAddress" placeholder="Token Address">
</div>
</div>
<div class="row">
<div class="col-25">
<label>Minimum Bounty</label>
</div>
<div class="col-75">
<input type="number" id="minBounty" placeholder="Minimum Bounty">
<button id="setMinBounty">Set Min</button>
<button id="getMinBounty">Get Min</button>
</div>
</div>
<div class="row">
<div class="col-25">
<label>Bounty Fee</label>
</div>
<div class="col-75">
<input type="number" id="bountyFee" placeholder="Bounty Fee">
<button id="setBountyFee">Set Fee</button>
<button id="getBountyFee">Get Fee</button>
</div>
</div>
</div>
</div>
<script>
var bountyABI;
var bountyAddress;
var bountyOwner;
var tokenABI;
var tokenAddress;
var tokenOwner;
var bountyBG;
var token;
var el = function (id) { return document.querySelector(id); };
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
el("#setMinBounty").addEventListener("click", async function() {
await setMinBounty(el('#tokenAddress').value, el('#minBounty').value)
})
el("#getMinBounty").addEventListener("click", async function() {
const minBounty = await getMinBounty(el('#tokenAddress').value)
console.log(minBounty)
})
el("#setBountyFee").addEventListener("click", async function() {
await setBountyFee(el('#tokenAddress').value, el('#bountyFee').value)
})
el("#getBountyFee").addEventListener("click", async function() {
bountyFee = await getBountyFee(el('#tokenAddress').value)
console.log(bountyFee)
})
function readContract() {
return new Promise((resolve, reject) => {
$.getJSON('./deploy/contracts.json', function(data) {
resolve(data)
})
})
}
function setMinBounty(_tokenAddress, _minBounty) {
return new Promise((resolve, reject) => {
bountyBG.methods
.setMinBountyToken(_tokenAddress, _minBounty)
.send({from: bountyOwner, gas: 3000000})
.then()
})
}
function getMinBounty(tokenAddress) {
return new Promise((resolve, reject) => {
bountyBG.methods
.getMinBountyToken(tokenAddress)
.call()
.then(resolve)
})
}
function setBountyFee(_tokenAddress, _bountyFee) {
return new Promise((resolve, reject) => {
bountyBG.methods
.setBountyFeeToken(_tokenAddress, _bountyFee)
.send({from: bountyOwner, gas: 3000000})
.on('error', reject)
.then(resolve)
})
}
function getBountyFee(tokenAddress) {
return new Promise((resolve, reject) => {
bountyBG.methods
.getBountyFeeToken(tokenAddress)
.call()
.then(resolve)
})
}
async function main() {
const data = await readContract();
bountyABI = data['bounty abi'];
bountyAddress = data['bounty address']
bountyOwner = data['bounty owner']
tokenABI = data['token abi']
tokenAddress = data['token address']
tokenOwner = data['token owner']
bountyBG = new web3.eth.Contract(bountyABI, bountyAddress);
token = new web3.eth.Contract(tokenABI, tokenAddress);
$('#tokenAddress').val(tokenAddress)
}
main();
</script>
</body>