forked from DeltaBalances/DeltaBalances.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtx.js
More file actions
1360 lines (1150 loc) · 40.6 KB
/
tx.js
File metadata and controls
1360 lines (1150 loc) · 40.6 KB
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var isAddressPage = false;
{
// shorthands
var _delta = bundle.DeltaBalances;
var _util = bundle.utility;
// initiation
var initiated = false;
var autoStart = false;
// loading states
var running = false;
var etherscanFallback = false;
// settings
var decimals = false;
var fixedDecimals = 3;
var blockDates = {};
// user input & data
var transactionHash = '';
var lastTxData = undefined;
var lastTxLog = undefined;
var txDate = "??";
var blocknum = -1;
var publicAddr = '';
var unknownToken = false;
var wideOutput = false;
init();
$(document).ready(function () {
readyInit();
});
function init() {
getBlockStorage();
// borrow some ED code for compatibility
_delta.startDeltaBalances(false, () => {
_delta.initTokens(false);
initiated = true;
if (autoStart)
myClick();
});
}
function readyInit() {
hideLoading();
//get metamask address as possbile input (if available)
metamaskAddr = _util.getMetamaskAddress();
if (metamaskAddr) {
setMetamaskImage(metamaskAddr);
$('#metamaskAddress').html(metamaskAddr.slice(0, 16));
}
checkStorage();
if (!publicAddr && !savedAddr && !metamaskAddr) {
document.getElementById('currentAddr').innerHTML = '0x......'; // side menu
document.getElementById('currentAddr2').innerHTML = '0x......'; //top bar
document.getElementById('currentAddrDescr').innerHTML = 'Input address';
setAddrImage('');
$('#userToggle').addClass('hidden');
} else if (publicAddr) {
document.getElementById('currentAddr').innerHTML = publicAddr.slice(0, 16); // side menu
document.getElementById('currentAddr2').innerHTML = publicAddr.slice(0, 8); //top bar
if (publicAddr !== metamaskAddr && publicAddr !== savedAddr) {
document.getElementById('currentAddrDescr').innerHTML = 'Input address';
} else if (publicAddr === savedAddr) {
if (savedAddr === metamaskAddr)
document.getElementById('currentAddrDescr').innerHTML = 'Metamask address (Saved)';
else
document.getElementById('currentAddrDescr').innerHTML = 'Saved address';
} else {
document.getElementById('currentAddrDescr').innerHTML = 'Metamask address';
}
setAddrImage(publicAddr);
$('#etherscan').attr("href", _util.addressLink(publicAddr, false, false));
$('#walletInfo').removeClass('hidden');
if (savedAddr === publicAddr) {
$('#save').addClass('hidden');
$('#forget').removeClass('hidden');
$('#savedSection').addClass('hidden');
} else {
$('#forget').addClass('hidden');
$('#save').removeClass('hidden');
if (savedAddr)
$('#savedSection').removeClass('hidden');
}
if (metamaskAddr && metamaskAddr !== publicAddr) {
$('#metamaskSection').removeClass('hidden');
} else {
$('#metamaskSection').addClass('hidden');
}
$('#userToggle').removeClass('hidden');
} else if (savedAddr) {
document.getElementById('currentAddr').innerHTML = savedAddr.slice(0, 16); // side menu
document.getElementById('currentAddr2').innerHTML = savedAddr.slice(0, 8); //top bar
$('#walletInfo').removeClass('hidden');
$('#save').addClass('hidden');
$('#savedSection').addClass('hidden');
if (savedAddr === metamaskAddr) {
document.getElementById('currentAddrDescr').innerHTML = 'Metamask address (Saved)';
} else {
document.getElementById('currentAddrDescr').innerHTML = 'Saved address';
}
$('#etherscan').attr("href", _util.addressLink(savedAddr, false, false));
setAddrImage(savedAddr);
if (metamaskAddr) {
$('#metamaskSection').removeClass('hidden');
}
$('#userToggle').removeClass('hidden');
} else if (metamaskAddr) {
document.getElementById('currentAddr').innerHTML = metamaskAddr.slice(0, 16); // side menu
document.getElementById('currentAddr2').innerHTML = metamaskAddr.slice(0, 8); //top bar
$('#walletInfo').removeClass('hidden');
$('#metamaskSection').addClass('hidden');
document.getElementById('currentAddrDescr').innerHTML = 'Metamask address';
$('#etherscan').attr("href", _util.addressLink(metamaskAddr, false, false));
setAddrImage(metamaskAddr);
$('#userToggle').removeClass('hidden');
}
// detect enter & keypresses in input
$('#address').keypress(function (e) {
if (e.keyCode == 13) {
myClick();
return false;
} else {
hideError();
return true;
}
});
$('body').on('expanded.pushMenu collapsed.pushMenu', function () {
// Add delay to trigger code only after the pushMenu animation completes
setTimeout(function () {
$("table").trigger("update", [true, () => { }]);
$("table").trigger("applyWidgets");
}, 300);
});
$(window).resize(function () {
$("table").trigger("applyWidgets");
hidePopovers();
});
//dismiss popovers on click outside
$('body').on('click', function (e) {
$('[data-toggle="popover"]').each(function () {
//the 'is' for buttons that trigger popups
//the 'has' for icons within a button that triggers a popup
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
hidePopover(this);
}
});
if (!$('#refreshButtonSearch').is(e.target)) {
hideError();
}
});
// url hash #0x..
var trans = '';
if (!trans) {
var hash = window.location.hash; // url parameter /#0x...
if (hash)
trans = hash.slice(1);
}
if (trans) {
trans = getTxHash(trans);
if (trans) {
transactionHash = trans;
window.location.hash = transactionHash;
autoStart = true;
// auto start loading
myClick();
}
}
if (!trans) {
$('#address').focus();
}
}
function disableInput(disable) {
$('#refreshButton').prop('disabled', disable);
$("#address").prop("disabled", disable);
if (disable)
$('#loading').addClass('dim');
else
$('#loading').removeClass('dim');
$("#loading").prop("disabled", disable);
}
function showLoading(balance, trans) {
$('#loading').addClass('fa-spin');
$('#loading').addClass('dim');
$('#loading').prop('disabled', true);
$('#loading').show();
$('#refreshButtonLoading').show();
$('#refreshButtonSearch').hide();
}
function buttonLoading() {
if (!transactionHash) {
hideLoading();
return;
}
$('#loading').removeClass('fa-spin');
$('#loading').removeClass('dim');
$('#loading').prop('disabled', false);
$('#loading').show();
$('#refreshButtonLoading').hide();
$('#refreshButtonSearch').show();
}
function hideLoading() {
$('#loading').hide();
$('#refreshButtonLoading').hide();
$('#refreshButtonSearch').show();
}
function myClick() {
if (running)
return;
if (!initiated) {
autoStart = true;
return;
}
hidePopovers();
wideOutput = false;
unknownToken = false;
hideError();
hideHint();
// disableInput(true);
showLoading();
clearOverview();
// validate address
if (!autoStart)
transactionHash = getTxHash();
autoStart = false;
if (transactionHash) {
$('#emptyMsg').hide();
$('.txOverviewTable').removeClass('hidden');
$('#hash').html(_util.hashLink(transactionHash, true));
window.location.hash = transactionHash;
getAll();
}
else {
console.log('invalid input');
disableInput(false);
hideLoading();
}
}
function getAll(autoload) {
if (running)
return;
running = true;
lastResult = undefined;
lastResult2 = undefined;
if (transactionHash) {
window.location.hash = transactionHash;
getTransactions();
} else {
running = false;
disableInput(false);
hideLoading();
}
}
// check if input hash is valid
function getTxHash(hash) {
//get address from input or else from html input
var inputHash = hash ? hash : document.getElementById('address').value;
if (inputHash) {
let checkedHash = _util.hashFromString(inputHash);
if (checkedHash) {
document.getElementById('address').value = checkedHash;
return checkedHash;
} else {
let address = _util.addressFromString(inputHash);
if (address) {
window.location = window.location.origin + window.location.pathname + '/../index.html#' + address;
return;
}
}
}
showError("Invalid transaction hash, try again");
return undefined;
}
function getTransactions() {
var transResult = undefined;
var logResult = undefined;
var statusResult = undefined;
var internalResult = undefined;
var gotBlockNum = false;
var transLoaded = 0;
const transNumber = 5;
getTransactionData();
function getTransactionData() {
var finished = false;
// get tx data & input from etherscan
_util.getURL('https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash=' + transactionHash + '&apikey=' + _delta.config.etherscanAPIKey, (err, result) => {
if (!err && result) {
if (finished)
return;
if (result && result.result) {
finished = true;
handleTransData(result.result);
} else {
web3GetTransaction();
}
} else {
web3GetTransaction();
}
});
function web3GetTransaction() {
//etherscan failed, try web3
if (!finished) {
_delta.web3s[0].eth.getTransaction(transactionHash, (err, result) => {
if (!err && result) {
finished = true;
handleTransData(result);
} else {
handleTransData(undefined);
}
});
}
}
// if etherscan takes >3 sec, try web3
setTimeout(function () {
web3GetTransaction();
}, 3000);
function handleTransData(res) {
if (res) {
transResult = res;
transLoaded++;
if (res.blockNumber) {
getBlockTime(Number(res.blockNumber));
getTransactionReceipt();
getInternal();
} else {
// tx is pending, no need to wait for tx status or logs
transLoaded = transNumber;
processTransactions(transResult, undefined, undefined, undefined);
return;
}
} else {
processTransactions(undefined, undefined, undefined, undefined);
return;
}
}
}
//get tx output logs from etherscan
function getTransactionReceipt() {
_util.txReceipt(_delta.web3s[0], transactionHash, (err, result, _) => {
if (!err && result) {
logResult = result;
if (result.blockNumber) {
if (Number(logResult.status) !== 1) {
getTxStatus(); // get error msg
} else {
transLoaded++;
}
}
}
transLoaded++;
if (transLoaded >= transNumber)
processTransactions(transResult, statusResult, logResult, internalResult);
});
}
function getBlockTime(num) {
num = Number(num);
if (gotBlockNum)
return;
else
gotBlockNum = true;
if (!blockDates[num]) {
_util.getBlockDate(_delta.web3s[0], num, (err, res, _) => {
if (!err && res) {
var unixtime = res;
if (unixtime) {
txDate = _util.toDateTime(unixtime);
blockDates[num] = txDate;
setBlockStorage();
}
}
transLoaded++;
if (transLoaded >= transNumber)
processTransactions(transResult, statusResult, logResult, internalResult);
});
} else {
txDate = blockDates[num];
transLoaded++;
if (transLoaded >= transNumber)
processTransactions(transResult, statusResult, logResult, internalResult);
}
}
function getTxStatus() {
_util.getURL('https://api.etherscan.io/api?module=transaction&action=getstatus&txhash=' + transactionHash + '&apikey=' + _delta.config.etherscanAPIKey, (err, result) => {
if (!err && result) {
if (result && result.status === '1')
statusResult = result.result;
}
transLoaded++;
if (transLoaded >= transNumber)
processTransactions(transResult, statusResult, logResult, internalResult);
});
}
function getInternal() {
_util.getURL('https://api.etherscan.io/api?module=account&action=txlistinternal&txhash=' + transactionHash + '&apikey=' + _delta.config.etherscanAPIKey, (err, result) => {
if (!err && result) {
if (result && result.status === '1')
internalResult = result.result;
}
transLoaded++;
if (transLoaded >= transNumber)
processTransactions(transResult, statusResult, logResult, internalResult);
});
}
function processTransactions(tx, txStatus, txLog, txInternal) {
if (!tx) {
console.log('error');
showError('failed to load transaction from <a href="https://etherscan.io/tx/' + transactionHash + '" + target="_blank"> Etherscan </a>');
disableInput(false);
hideLoading();
buttonLoading();
running = false;
return;
}
var pending = false;
if (!tx.blockHash || !tx.blockNumber || !tx.transactionIndex) {
pending = true;
}
var transaction = {
hash: tx.hash,
from: tx.from,
to: tx.to,
rawinput: tx.input,
nonce: Number(tx.nonce),
value: _util.weiToEth(tx.value),
gasPrice: _util.weiToEth(tx.gasPrice),
gasGwei: (Number(tx.gasPrice) / 1000000000),
gasLimit: Number(tx.gas),
status: 'Pending',
input: parseInput(tx, tx.input),
rawInput: tx.input,
}
transaction.internal = [];
function addTransfer(from, to, val, isInput) {
let eth = _delta.setToken(_delta.config.ethAddr);
let obj = {
'type': 'Transfer',
'note': 'Transferred ETH',
'token': eth,
'amount': val,
'from': from.toLowerCase(),
'to': to.toLowerCase(),
'unlisted': false,
};
if (isInput) {
transaction.input.push(obj);
} else {
transaction.internal.push(obj);
}
}
if (pending) {
if (transaction.value.greaterThan(0)) {
addTransfer(transaction.from, transaction.to, transaction.value, true);
}
}
else if (!pending) {
transaction.gasUsed = Number(txLog.gasUsed);
transaction.gasEth = _util.weiToEth(tx.gasPrice).times(txLog.gasUsed);
if ((txLog.logs && txLog.logs.length > 0) || Number(txLog.status) === 1) {
if (transaction.value.greaterThan(0)) {
addTransfer(transaction.from, transaction.to, transaction.value, false);
}
if (txInternal && txInternal.length > 0) {
for (let i = 0; i < txInternal.length; i++) {
let itx = txInternal[i];
let val = _util.weiToEth(itx.value);
addTransfer(itx.from, itx.to, val, false);
}
}
transaction.status = 'Completed';
transaction.blockNumber = tx.blockNumber;
transaction.blockHash = tx.blockHash;
transaction.rawoutput = null;
var parsedOutput = parseOutput(tx, txLog.logs);
transaction.output = parsedOutput.output;
transaction.outputErrors = parsedOutput.errors;
if (parsedOutput.output && parsedOutput.output[0]) {
if (!parsedOutput.output[0].error && (parsedOutput.output[0].type == '0x Error' || parsedOutput.output[0].type == 'AirSwap Error')) {
transaction.status = 'Failed';
}
}
}
else {
transaction.status = 'Error';
if (txStatus && txStatus.errDescription)
transaction.status += ': ' + txStatus.errDescription;
transaction.gasEth = transaction.gasLimit * transaction.gasPrice;
}
}
finish(transaction);
//to ed, val >0 deposit
// internal from >0 withdraw
function parseOutput(tx, outputLogs) {
var outputs = [];
var unknownEvents = 0;
var unpackedLogs = _util.processLogs(outputLogs);
if (unpackedLogs) {
for (let i = 0; i < unpackedLogs.length; i++) {
let unpacked = unpackedLogs[i];
if (!unpacked) {
unknownEvents++;
continue;
} else {
let myAddr = tx.from;
if (tx.to.toLowerCase() !== unpacked.address.toLowerCase() && unpacked.name !== 'Transfer' && unpacked.name !== 'Approve')
myAddr = tx.to.toLowerCase();
let obj = _delta.processUnpackedEvent(unpacked, myAddr);
if (obj && !obj.error) {
if (obj && obj.token && obj.token.name === "???" && obj.token.unknown)
unknownToken = true;
if (unpacked.name === 'Trade' || unpacked.name == 'Filled' || unpacked.name === 'ExecuteTrade' || unpacked.name == 'LogTake' || unpacked.name == 'Conversion' || unpacked.name == 'Order' || unpacked.name == 'TakeBuyOrder' || unpacked.name == 'TakeSellOrder') {
obj.feeToken = obj.feeCurrency;
delete obj.feeCurrency;
delete obj.transType;
delete obj.tradeType;
} else if (unpacked.name === 'LogFill' || unpacked.name === 'Fill') {
delete obj.transType;
delete obj.tradeType;
delete obj.relayer;
obj.feeToken = obj.feeCurrency;
delete obj.feeCurrency;
} else if (unpacked.name === 'LogCancel') {
delete obj.relayer;
}
outputs.push(obj);
} else {
unknownEvents++;
continue;
}
}
}
}
return { output: outputs, errors: unknownEvents };
}
function parseInput(tx, input) {
var unpacked = _util.processInput(input);
if (!unpacked)
return undefined;
let obj = _delta.processUnpackedInput(tx, unpacked);
if (obj) {
if (!Array.isArray(obj))
obj = [obj];
for (let i = 0; i < obj.length; i++) {
if (obj[i] && obj[i].token && obj[i].token.name === "???" && obj[i].token.unknown)
unknownToken = true;
if (obj[i].relayer)
delete obj[i].relayer;
if (obj[i].feeCurrency) {
obj[i].feeToken = obj[i].feeCurrency;
delete obj[i].feeCurrency;
}
}
}
return obj;
}
}
}
function showHint(text) {
$('#hinttext').html(text);
$('#hint').show();
}
function hideHint() {
$('#hint').hide();
}
function showError(text) {
$('#errortext').html(text);
$('#error').show();
}
function hideError() {
$('#error').hide();
}
// callback when balance request completes
function finish(transaction) {
/*
var transaction = {
hash: ,
from: ,
to: ,
input: ,
nonce: ,
value: ,
gasPrice: ,
gas: ,
gasUsed: ,
error: ,
errorText: ,
input: ,
output: '',
}
*/
if (transaction.internal) {
if (transaction.output) {
transaction.output = transaction.output.concat(transaction.internal);
} else {
transaction.output = transaction.internal;
}
}
//generate messages based on tx
var sum = '';
if (transaction.status === 'Completed') {
sum += 'Status: Completed<br>';
}
else if (transaction.status === 'Pending') {
sum += 'Status: Transaction is pending, try again later. For a faster transaction raise your gas price next time.<br> Pending for a really long time? Try to <a href="https://www.reddit.com/r/EtherDelta/comments/72tctz/guide_how_to_cancel_a_pending_transaction/" target="_blank">cancel or replace</a> it. <br>';
}
else if (transaction.status === 'Error: Bad jump destination' || transaction.status === 'Error: Reverted') {
if (transaction.input) {
if (transaction.input[0].type === 'Taker Sell' || transaction.input[0].type === 'Taker Buy') {
sum += 'Status: transaction failed, order already filled or cancelled.<br>';
}
else if (transaction.input[0].type === 'Token Deposit' || transaction.input[0].type === 'Token Withdraw') {
sum += 'Status: transaction failed, you might not have had the right account balance left. Otherwise check if the token is not locked. (Still in ICO, rewards period, disabled etc.)<br><br>';
} else if (transaction.input[0].type === 'Deposit' || transaction.input[0].type === 'Withdraw') {
sum += 'Status: transaction failed, you might not have had the right account balance left.<br>';
}
else {
sum += 'Status: transaction failed.<br>';
}
} else {
sum += 'Status: transaction failed.<br>';
}
} else if (transaction.status === 'Failed') {
sum += 'Status: Exchange operation failed.<br>';
} else {
sum += 'Status: Transaction failed.<br>';
}
if (unknownToken) {
sum += "<strong>This token is still unknown to DeltaBalances </strong>, amount and price might be wrong if the token has less than 18 decimals <br> "
}
let operations = {};
if (transaction.input && transaction.input.length > 0) {
for (let i = 0; i < transaction.input.length; i++) {
if (transaction.input[i].note) {
let operation = 'Operation: ' + transaction.input[i].note + '<br>';
//avoid double messages
if (!operations[operation]) {
sum += operation;
operations[operation] = true;
}
}
}
if (transaction.input[0].type.indexOf('aker') !== -1 && transaction.input[0].exchange == _delta.config.exchangeContracts.Idex.name) {
sum += '<br>Note: IDEX uses no transaction output events.';
}
} else if (!transaction.input && (!transaction.output || transaction.output.length == 0) && transaction.rawInput == '0x') {
//regular ETH transfer, no funciton calls
let operation = 'Operation: Transferred ' + transaction.value.toString() + ' ETH from ' + _util.addressLink(transaction.from, true, true) + ' to ' + _util.addressLink(transaction.to, true, true) + '<br>';
sum += operation;
}
else if (transaction.output && transaction.output.length > 0) {
if (transaction.rawInput == '0x') {
let operation = 'Operation: Transferred ' + transaction.value.toString() + ' ETH from ' + _util.addressLink(transaction.from, true, true) + ' to ' + _util.addressLink(transaction.to, true, true) + '<br>';
sum += operation;
}
for (let i = 0; i < transaction.output.length; i++) {
if (transaction.output[i].note) {
let operation = 'Operation: ' + transaction.output[i].note + '<br>';
//avoid double messages
if (!operations[operation]) {
sum += operation;
operations[operation] = true;
}
}
}
}
if (Object.keys(operations).length > 0)
sum += '<br>';
if (transaction.input && transaction.input[0].type === 'Transfer') {
if (_delta.uniqueTokens[transaction.input[0].to]) {
sum += '<strong>Warning</strong>, you sent tokens to a token contract. These tokens are most likely lost forever. <br>';
}
else if (_delta.isExchangeAddress(transaction.input[0].to)) {
sum += '<strong>Warning</strong>, you sent tokens to the Exchange contract without a deposit. Nobody can access these tokens anymore, they are most likely lost forever. <br>';
}
}
else if (!transaction.input && transaction.rawInput !== '0x' && (!transaction.output || transaction.output.length == 0)) {
sum += 'This does not seem to be a transaction with a supported decentralized exchange. <br>';
}
if (checkOldED(transaction.to)) {
sum += 'This transaction is to an outdated EtherDelta contract, only use these to withdraw old funds.<br>';
}
//handle tx output logs
var tradeCount = 0;
var zeroDecWarning = '';
if (transaction.output) {
if (transaction.input && transaction.output.length == 1 && transaction.output.price) {
//transaction.output[0].price = transaction.input[0].price;
if (transaction.input[0]['order size'].greaterThan(transaction.output[0].amount)) {
sum += "Partial fill, ";
}
}
//var spent = _delta.web3.toBigNumber(0);
//var received = _delta.web3.toBigNumber(0);
for (var i = 0; i < transaction.output.length; i++) {
if (transaction.output[i].type == 'Taker Buy' || transaction.output[i].type == 'Taker Sell') {
if (transaction.output[i].token.decimals == 0 && !zeroDecWarning) {
zeroDecWarning = "<strong>Note: </strong> " + transaction.output[i].token.name + " has 0 decimals precision. Numbers might be lower than expected due to rounding. <br>";
}
tradeCount++;
let typeWord = "Bought ";
if (transaction.output[i].type == 'Taker Sell') {
typeWord = "Sold ";
}
// add description bought/sold if not internal enclaves order
if (transaction.output[i].buyer !== _delta.config.exchangeContracts.Enclaves.addr && transaction.output[i].seller !== _delta.config.exchangeContracts.Enclaves.addr) {
sum += typeWord + transaction.output[i].amount + " " + transaction.output[i].token.name + " for " + transaction.output[i].price + " " + transaction.output[i].base.name + " each, " + transaction.output[i].baseAmount + " " + transaction.output[i].base.name + " in total. <br>";
}
//spent = transaction.output[i].ETH.plus(spent);
}
else if (transaction.output[i].type == "Deposit" || transaction.output[i].type == "Token Deposit") {
sum += "Deposited " + transaction.output[i].amount + " " + transaction.output[i].token.name + ", new exchange balance: " + transaction.output[i].balance + " " + transaction.output[i].token.name + '<br>';
}
else if (transaction.output[i].type == "Withdraw" || transaction.output[i].type == "Token Withdraw") {
sum += "Withdrew " + transaction.output[i].amount + " " + transaction.output[i].token.name + ", new exchange balance: " + transaction.output[i].balance + " " + transaction.output[i].token.name + '<br>';
}
}
if (tradeCount > 1 && !_delta.isExchangeAddress(transaction.to, true)) {
sum += '<br>This transaction was made by a contract that has made multiple trades in a single transaction. <br>';
// sum up what a custom cotract did in multiple trades
// sum += "ETH gain over these trades: " + (received.minus(spent).minus(transaction.gasEth)) + " (incl. gas cost). <br>";
}
else if (tradeCount > 0 && !_delta.isExchangeAddress(transaction.to, true)) {
sum += '<br>This transaction was made by a contract instead of a user. <br>';
}
if (zeroDecWarning)
sum += zeroDecWarning;
}
$('#summary').html(sum);
// handle generic tx data
$('#hash').html(_util.hashLink(transaction.hash, true));
$('#from').html(_util.addressLink(transaction.from, true, false));
$('#to').html(_util.addressLink(transaction.to, true, false));
$('#cost').html('??');
$('#gasgwei').html(transaction.gasGwei + ' Gwei (' + '<span data-toggle="tooltip" title="' + _util.exportNotation(transaction.gasPrice) + '">' + transaction.gasPrice.toFixed(10) + ' ETH)</span>');
if (!transaction.gasUsed)
transaction.gasUsed = '???';
$('#gasusedlimit').html(transaction.gasUsed + " / " + transaction.gasLimit);
if (transaction.status === 'Completed') {
$('#gascost').html('<span data-toggle="tooltip" title="' + _util.exportNotation(transaction.gasEth) + '">' + Number(transaction.gasEth).toFixed(5) + ' ETH</span>');
} else if (transaction.status === 'Pending') {
$('#gascost').html('Pending');
} else {
$('#gascost').html('<span data-toggle="tooltip" title="' + _util.exportNotation(transaction.gasEth) + '">' + transaction.gasEth.toFixed(5) + ' ETH</span>');
}
$('#nonce').html(transaction.nonce);
if (transaction.status === 'Completed') {
$('#status').html('<i style="color:green;" class="fa fa-check"></i>' + ' ' + transaction.status);
$('#time').html(txDate !== "??" ? _util.formatDate(txDate) : txDate);
}
else if (transaction.status === 'Pending') {
$('#status').html('<i class="fa fa-cog fa-fw"></i>' + ' ' + transaction.status);
$('#time').html('Pending');
}
else {
$('#status').html('<i style="color:red;" class="fa fa-exclamation-circle"></i>' + ' ' + transaction.status);
$('#time').html(txDate !== "??" ? _util.formatDate(txDate) : txDate);
}
$('#ethval').html('<span data-toggle="tooltip" title="' + _util.exportNotation(transaction.value) + '">' + transaction.value.toString() + '</span>');
$('#inputdata').html('');
if (transaction.input && transaction.input[0].type) {
$('#inputtype').html(transaction.input[0].type);
} else {
if (tradeCount == 0) {
if (transaction.output && transaction.output.length > 0 && transaction.output[0].type) {
$('#inputtype').html(transaction.output[0].type);
} else {
$('#inputtype').html('');
}
} else {
$('#inputtype').html('Trade');
}
}
if (transaction.input) {
displayParse(transaction.input, "#inputdata");
}
$('#outputdata').html('');
if (transaction.output) {
displayParse(transaction.output, "#outputdata");
if (transaction.outputErrors) {
$('#outputdata').append('<br> + ' + transaction.outputErrors + ' unrecognized events emitted');
}
}
else if (transaction.status === 'Pending')
$('#outputdata').html('Transaction is pending, no output available yet.');
else
$('#outputdata').html('');
running = false;
buttonLoading();
disableInput(false);
}
function clearOverview() {
$('#summary').html('');
$('#hash').html('');
$('#from').html('');
$('#to').html('');
$('#cost').html('');
$('#gasprice').html('');
$('#gasgwei').html('');
$('#gascost').html('');
$('#gaslimit').html('');
$('#gasusedlimit').html('');
$('#nonce').html('');
$('#status').html('');
$('#time').html('');
$('#ethval').html('');
$('#inputdata').html('');
$('#inputtype').html('');
$('#inputtype').html('');
$('#outputdata').html('');
}
function displayParse(parsedInput, id) {
if (!parsedInput) {
$(id).html('No familiar Exchange data recognized');
return;
}
// group similar typed events into the same table
let types = {};
for (var i = 0; i < parsedInput.length; i++) {
let uniqueType = parsedInput[i].type.toLowerCase();
if (uniqueType.indexOf('taker') !== -1 || uniqueType.indexOf('maker') !== -1) {
uniqueType = 'trade';
wideOutput = true;
}
// all cancels except 'cancel up to' (0x v2)
else if (uniqueType.indexOf('cancel') !== -1 && uniqueType.indexOf('up to') == -1) {
uniqueType = 'cancel';
wideOutput = true;
} else if (uniqueType === 'deposit' || uniqueType === 'token deposit' || uniqueType === 'withdraw' || uniqueType === 'token withdraw') {
uniqueType = 'depositWithdraw';
}
else if (uniqueType.indexOf(' up to') !== -1 || uniqueType.indexOf('offer') !== -1) {
wideOutput = true;
}
if (!types[uniqueType])
types[uniqueType] = [];
types[uniqueType].push(parsedInput[i]);
}
if (wideOutput) {
$('#inputdiv').removeClass('col-lg-6')
$('#outputdiv').removeClass('col-lg-6');
} else {
$('#inputdiv').addClass('col-lg-6')
$('#outputdiv').addClass('col-lg-6');
}
let batchedInput = Object.values(types);
for (var i = 0; i < batchedInput.length; i++) {
buildHtmlTable(id, batchedInput[i]);
}