forked from MattyIce/bottracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelegation.html
414 lines (354 loc) · 17.8 KB
/
delegation.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-107512713-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'UA-107512713-1');
</script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="img/favicon_no_smile_32px-high.ico" type="image/x-icon">
<meta property="og:title" content="Steem Power Delegation Manager">
<meta property="og:description" content="Manage and update your Steem Power delegations!">
<meta property="og:image" content="https://i.imgur.com/t0Gk94V.jpg">
<meta property="og:url" content="http://www.steembottracker.com">
<title>Steem Power Delegation Manager</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Import google fonts - Heading first/ text second -->
<link href='https://fonts.googleapis.com/css?family=Quattrocento+Sans:400,700' rel='stylesheet' type='text/css'>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="scripts/bootstrap-slider.min.js"></script>
<script src="https://cdn.steemjs.com/lib/latest/steem.min.js"></script>
<script src="scripts/sc2.min.js"></script>
<script src="scripts/utils.js?v=5"></script>
<script type="text/javascript">
steem.api.setOptions({ url: 'https://api.steemit.com' });
updateSteemVariables();
</script>
<!-- Dynamic admin theme -->
<link rel="stylesheet" href="css/icons.css">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/plugins.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/custom.css">
</head>
<body>
<div id="header" class="page-navbar header-fixed">
<nav class="navbar navbar-default" style="margin-bottom: 0;">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="bottracker.html" class="navbar-brand">
<img alt="Steem Post Promoter" src="img/header_logo.png" height="44" style="margin-top: -10px;">
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-android mr10"></i>
Voting Bots <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="bottracker.html#bid"><i class="l-basic-hammer mr10"></i> Bid-Based Voting Bots</a></li>
<li><a href="bottracker.html#paid"><i class="l-banknote mr10"></i> Promotion Services</a></li>
<li><a href="bottracker.html#free"><i class="fa fa-android mr10"></i> Other Bots</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-wrench mr10"></i>
Tools <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="config.html"><i class="fa fa-code mr10"></i> Bot Owner Config</a></li>
<li><a href="curation_calculator.html"><i class="fa fa-calculator mr10"></i> Curation Estimator</a></li>
<li><a href="delegation.html"><i class="fa fa-retweet mr10"></i> Delegation Manager</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown" id="user_info">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span id="login_info"></span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#" id="btn_logout"><i class="fa fa-calculator mr10"></i> Log Out</a></li>
</ul>
</li>
<li id="btn_login">
<button type="button" class="btn btn-default navbar-btn" onclick="window.location.href=sc2.getLoginURL();">Log in</button>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Steem Power Delegation Manager</h4>
</div>
<div class="panel-body">
<h4>Enter your Steem account name to view and manage your Steem Power delegations!</h4>
<div class="form-horizontal">
<div class="form-group">
<label class="col-lg-2 col-md-3 control-label" for="delegator">Delegator</label>
<div class="col-lg-9 col-md-8">
<div class="input-group">
<span class="input-group-addon">@</span>
<input type="text" class="form-control" id="delegator" placeholder="Delegator Account Name">
<span id="delegator_ok" class="fa fa-check validation-icon-ok color-green" aria-hidden="true" style="display: none;"></span>
<span id="delegator_bad" class="fa fa-times validation-icon-error color-red" aria-hidden="true" style="display: none;"></span>
</div>
</div>
<div class="col-lg-1 col-md-1">
<button id="btn_load" class="btn btn-success" onclick="">Load</button>
</div>
</div>
<div id="details" style="display: none;">
<div class="panel panel-primary plain">
<div class="table-responsive">
<table id="delegations_table" class="table table-striped table-responsive">
<thead>
<tr>
<th>Delegatee</th>
<th style="text-align: right;">Steem Power</th>
<th style="text-align: right;">VESTS</th>
<th style="text-align: center;">Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>Loading...</td>
<td>Loading...</td>
<td>Loading...</td>
<td>Loading...</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="panel panel-primary plain">
<div class="panel-heading">
<a name="update"></a><h4 class="panel-title">Add / Update Delegation</h4>
</div>
<div class="panel-body">
<div class="form-group">
<label class="col-lg-2 col-md-3 control-label" for="delegatee" >Delegatee</label>
<div class="col-lg-10 col-md-9">
<div class="input-group">
<span class="input-group-addon">@</span>
<input type="text" class="form-control" id="delegatee" placeholder="Delegatee Account Name">
<span id="delegatee_ok" class="fa fa-check validation-icon-ok color-green" aria-hidden="true" style="display: none;"></span>
<span id="delegatee_bad" class="fa fa-times validation-icon-error color-red" aria-hidden="true" style="display: none;"></span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 col-md-3 control-label" for="delegatee" >Amount (Steem Power)</label>
<div class="col-lg-2 col-md-3">
<input type="text" class="form-control" id="amount" placeholder="1000">
</div>
<div class="col-lg-8 col-md-6">
(<span id="max_delegation_amount"></span> SP Available)
<button class="btn btn-info" onclick="return delegateMax();">Delegate Max</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div id="warning" style="color: red; display: none;">ERROR: You have chosen to delegate more than the maximum available. If you do not have enough SP in the account it will become unusable.</div>
<button id="btn_submit" class="btn btn-success" onclick="delegate($('#delegator').val(), $('#delegatee').val(), $('#amount').val()); return false;">Delegate!</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="bs-callout bs-callout-info fade in">
<h4>Vote for Witness!</h4>
<p>Help support me and the bot tracker by voting for @yabapmatt for Steem witness! To vote, click the button below or go to <a href="https://steemit.com/~witnesses" target="_blank">https://steemit.com/~witnesses</a> and find @yabapmatt in the list and click the upvote icon. Thank you!</p>
<button class="btn btn-success btn-lg" onclick="window.open('https://v2.steemconnect.com/sign/account-witness-vote?witness=yabapmatt&approve=1');">Vote for @yabapmatt!</button>
</div>
</div>
<div id="footer" class="clearfix white-bg"><!-- Start #footer -->
<p class="pull-left">
Copyrights © 2017 <a href="http://www.steemit.com/@yabapmatt" class="color-blue strong" target="_blank">Yabapmatt</a>. All rights reserved.
</p>
<p class="pull-right">
Logo by <a href="http://www.steemit.com/@creativista" class="color-blue strong" target="_blank">Creativista</a> |
Bootstrap theme by <a href="http://www.steemit.com/@suggeelson" class="color-blue strong" target="_blank">SuggeElson</a>
</p>
</div><!-- End #footer -->
<script type="text/javascript">
var delegator = null;
var existing_delegation = null;
var delegations = [];
function delegate(delegator_name, delegatee, amount) {
if (typeof amount === 'string' || amount instanceof String)
amount = parseFloat(amount.replace(/,/g, ''));
$('#warning').hide();
var existing_sp = (existing_delegation ? parseFloat(existing_delegation.vesting_shares) / 1000000 * steem_per_mvests : 0);
if ((amount - existing_sp) > (delegator.available_sp + 1)) {
$('#warning').show();
return;
}
var vests = (parseFloat(amount) / steem_per_mvests * 1000000).formatMoney(6, '.', '');
var url = 'https://v2.steemconnect.com/sign/delegate-vesting-shares?delegator=' + delegator_name + '&delegatee=' + delegatee + '&vesting_shares=' + vests + ' VESTS';
window.open(url);
}
function loadAccount(account, cb) {
steem.api.getAccounts([account], function(err, result) {
cb(result[0]);
});
}
function checkAccount(id, callback) {
loadAccount($('#' + id).val(), function (account) {
var ok = $('#' + id + '_ok');
var bad = $('#' + id + '_bad');
ok.hide();
bad.hide();
if (account && account.name) {
ok.show();
if(id == 'delegator') {
delegator = account;
loadDelegations($('#delegator').val(), callback);
$('#details').show();
var power_down = (parseFloat(account.to_withdraw) - parseFloat(account.withdrawn)) / 1000000;
delegator.available_sp = Math.max((parseFloat(account.vesting_shares) - parseFloat(account.delegated_vesting_shares) - power_down) / 1000000 * steem_per_mvests - 6, 0);
$('#max_delegation_amount').text(delegator.available_sp.formatMoney(3));
} else if(id == 'delegatee') {
existing_delegation = delegations.find(function(d) { return d.delegatee == account.name; });
if(existing_delegation) {
$('#amount').val((parseFloat(existing_delegation.vesting_shares) / 1000000 * steem_per_mvests).formatMoney(3));
}
if(callback) {
callback();
}
}
} else
bad.show();
});
}
function loadDelegations(account, callback) {
steem.api.getVestingDelegations(account, -1, 100, function(err, result) {
delegations = result;
result.sort(function(a, b) { return parseFloat(b.vesting_shares) - parseFloat(a.vesting_shares); });
populateDelegations(result);
if(callback)
callback();
});
}
function delegateMax() {
var existing_sp = (existing_delegation ? parseFloat(existing_delegation.vesting_shares) / 1000000 * steem_per_mvests : 0);
$('#amount').val((delegator.available_sp + existing_sp).formatMoney(3));
return false;
}
$('#delegator').focusout(function (e) { checkAccount('delegator'); });
$('#delegatee').focusout(function (e) { checkAccount('delegatee'); });
$(function () { $('[data-toggle="tooltip"]').tooltip() });
function populateDelegations(delegations) {
var table = $('#delegations_table tbody');
table.empty();
delegations.forEach(function (delegation) {
var row = $(document.createElement('tr'));
var td = $(document.createElement('td'));
var link = $(document.createElement('a'));
link.attr('href', 'https://steemit.com/@' + delegation.delegatee);
link.attr('target', '_blank');
link.text('@' + delegation.delegatee);
td.append(link);
row.append(td);
var td = $(document.createElement('td'));
td.text((parseFloat(delegation.vesting_shares) / 1000000 * steem_per_mvests).formatMoney(3) + ' SP');
td.css('text-align', 'right');
row.append(td);
var td = $(document.createElement('td'));
td.text(parseFloat(delegation.vesting_shares).formatMoney(6) + ' VESTS');
td.css('text-align', 'right');
row.append(td);
var td = $(document.createElement('td'));
var link = $('<button type="button" class="btn btn-danger btn-xs"><i class="fa fa-trash mr5"></i>Remove</button>');
link.click(function (e) { delegate(delegator.name, delegation.delegatee, 0); });
td.append(link);
link = $('<button type="button" style="margin-left: 10px;" class="btn btn-primary btn-xs"><i class="fa fa-edit mr5"></i>Update</button>');
link.click(function (e) {
$('#delegatee').val(delegation.delegatee); checkAccount('delegatee');
document.location.href = '#update';
});
td.append(link);
td.css('text-align', 'center');
row.append(td);
table.append(row);
});
}
$(function() {
// Initialize and try to log in with SteemConnect V2
var token = getURLParameter('access_token') ? getURLParameter('access_token') : localStorage.getItem('access_token');
sc2.init({
baseURL: 'https://v2.steemconnect.com',
app: 'bottracker.app',
accessToken: token,
callbackURL: 'https://steembottracker.com/delegation.html',
scope: ['login', 'vote']
});
var user = null;
sc2.me(function (err, result) {
if (result && !err) {
console.log(result);
user = result.account;
$('#btn_login').hide();
$('#user_info').show();
$('#login_info').text('@' + user.name);
localStorage.setItem('access_token', token);
$('#delegator').val(user.name);
checkAccount('delegator');
} else {
$('#btn_login').show();
$('#user_info').hide();
}
});
$('#btn_logout').click(function () {
localStorage.removeItem('access_token');
window.location.href = window.location.pathname;
});
if(getURLParameter('delegator')){
$('#delegator').val(getURLParameter('delegator'));
checkAccount('delegator', function() {
if(getURLParameter('delegatee')){
$('#delegatee').val(getURLParameter('delegatee'));
checkAccount('delegatee', function() {
if(getURLParameter('amount')){
var existing_sp = (existing_delegation ? parseFloat(existing_delegation.vesting_shares) / 1000000 * steem_per_mvests : 0);
$('#amount').val((parseFloat(getURLParameter('amount')) + existing_sp).formatMoney(3));
}
});
}
});
} else if(getURLParameter('delegatee')) {
$('#delegatee').val(getURLParameter('delegatee'));
checkAccount('delegatee', function() {
if(getURLParameter('amount')){
var existing_sp = (existing_delegation ? parseFloat(existing_delegation.vesting_shares) / 1000000 * steem_per_mvests : 0);
$('#amount').val((parseFloat(getURLParameter('amount')) + existing_sp).formatMoney(3));
}
});
}
});
</script>
</body>
</html>