-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
203 lines (172 loc) · 7.42 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Jobs</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container" style="width: 650px;">
<div class="row">
<div class="col-lg-12 text-center" >
<h1 >Jobs</h1>
<hr/>
<br/>
<div id="content">
<h3 id="seekStatus">Seeking</h3>
<div id="jobs" style="display:none">
<table class="table">
<thead>
<tr>
<th>Job</th>
<th>Buyer</th>
<th>Price</th>
<th>Created</th>
<th>Expires</th>
</tr>
</thead>
</table>
</div>
<hr/>
<form role="form">
<div class="form-group" style="display:inline;">
<div class="input-group">
<input class="form-control" placeholder="Job Name" name="jobName" required>
<input class="form-control" placeholder="Developer Name" name="devName" required>
<input class="form-control" placeholder="Buyer Name" name="buyerName" required>
<input class="form-control" placeholder="Price in $" name="price" required>
<input class="form-control" placeholder="Duration in days" name="duration" required>
<input class="form-control" placeholder="Address to send the transaction from" name="fromAddress" required>
<span class="input-group-btn col-sm-10" style="padding:0;margin:0">
<button type="submit" class="btn btn-primary btn-lg" style="">Add Job</button>
</span>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.34/dist/web3.min.js"></script>
<script src="js/abi.js"></script>
<script>
// Contract Address
var contractAddress = prompt("Enter contract address"); // Add Your Contract address here!!!
//var contractAddress = '0x922e96c31f69315Dec5aF37cB3eEcca483dd1356'; // Add Your Contract address here!!!
//var sendAddress = '0xa445D544e748536cE8d5B959e2B9cB152b08a384'; //Address used to modify contract state
//let addressKey = '0x5b2b8559aa48faccaee53c3a66e335e4636941260390f90b14dd016401faade8';
// Initialize Web3
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider('https://rrwxt.sse.codesandbox.io'));
}
// Set Account
web3.eth.defaultAccount = web3.eth.accounts[0];
// Set Contract Abi
// REMOVED AND INCLUDED ABOVE
// Contract ABI
//Unlocking account
//web3.eth.personal.unlockAccount(sendAddress, "SomeKEY", 1).then((response) => {console.log(response);})
// Set the Contract
var contract = new web3.eth.Contract(contractAbi, contractAddress);
console.log(contract);
let jobTable = $('#jobs');
updateJobs();
async function updateJobs() {
try {
let jobCount = await contract.methods.jobCount().call();
console.log(jobCount);
$(".titem").remove();
//let seeking = 1;
for (let i = 0; i <= jobCount; i++) {
await contract.methods.jobs(i).call(function(e, job) {
//console.log(job["jobName"]);
jobTable.children("table").append("<tr class='titem'><td>" + job["jobName"] +
"</td><td>" + job["buyerName"] +
"</td><td>Cost: " + job["price"] + "$" +
"</td><td>Created on " + getDate(job["created"]) +
"</td><td>Expires on " + getDate(job["expires"]) +
"</td></tr>");
i == jobCount ? jobTable.css("display", "") : '';
i == jobCount ? $("#seekStatus").css("display", "none") : $("#seekStatus").html(`Found ${i+1} items`);
});
}
} catch (err) {
//
}
};
function getDate(timestamp) {
var date = new Date(timestamp * 1000);
var hours = date.getHours();
var minutes = "0" + date.getMinutes();
var seconds = "0" + date.getSeconds();
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var day = date.getDate();
var month = months[date.getMonth()];
var year = date.getFullYear();
return `${hours}:${minutes.substr(-2)} ${day} ${month} ${year}`;
}
function addJob(name, dev, buyer, price, duration, sendAddress) {
let addressKey = prompt("Enter your private key in order to sign the transaction");
if (!addressKey) {
alert("No private key entered");
return;
}
if(!name || !dev || !buyer || !price || !duration) {
alert("Fill all fields with proper information");
}
let addJobABI = contract.methods.addJob(name, dev, buyer, parseInt(price), parseInt(duration)).encodeABI();
let tx = {
from: sendAddress,
to: contractAddress,
gas: 3000000,
data: addJobABI
};
web3.eth.accounts.signTransaction(tx, addressKey).then(signed => {
var tran = web3.eth.sendSignedTransaction(signed.rawTransaction);
<!-- tran.on('confirmation', (confirmationNumber, receipt) => { -->
<!-- console.log('confirmation: ' + confirmationNumber); -->
<!-- }); -->
<!-- tran.on('transactionHash', hash => { -->
<!-- console.log('hash'); -->
<!-- console.log(hash); -->
<!-- }); -->
tran.on('receipt', receipt => {
alert("Receipt Available\nCheck console");
console.log(receipt);
updateJobs();
});
tran.on('error', console.error);
});
}
//contract.methods.jobs(0).call().then((val) => {console.log(val["devName"])})
//contract.methods.addJob("www.klajdi.net", "RW", "clyde", 300, 3).send({from: sendAddress, gas:3000000}) //Add new job
// NOTE to self -> The below line returns the receipt of the transaction once it is available, mostly used when mining is not instant (production???)
//contract.methods.addJob("www.klajdi.ga", "RW", "clyde", 300, 3).send({from: sendAddress, gas:3000000}).on('confirmation', (confirmationNumber, receipt) => {console.log(receipt)});
// Change the Job Name
$('form').on('submit', function(event) {
event.preventDefault();
let jobName = $('input[name ="jobName"]').val();
let dev = $('input[name ="devName"]').val();
let buyer = $('input[name ="buyerName"]').val();
let price = $('input[name ="price"]').val();
let duration = $('input[name ="duration"]').val();
let fromAddress = $('input[name ="fromAddress"]').val();
addJob(jobName, dev, buyer, price, duration);
})
</script>
</body>
</html>