forked from DeltaBalances/DeltaBalances.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx.js
1227 lines (1067 loc) · 33.3 KB
/
tx.js
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
{
'use strict';
// Parameters
// ##########################################################################################################################################
// shorthands
let _util = bundle.utility;
let _delta = bundle.EtherDelta;
// initiation
let initiated = false;
let autoStart = false;
// loading states
let running = false;
var etherscanFallback = false;
// settings
let decimals = false;
let fixedDecimals = 3;
// user input & data
let transactionHash = '';
let lastTxData = undefined;
let lastTxLog = undefined;
let uniqueTokens = {};
// Functions - initialisation
// ##########################################################################################################################################
init();
$(document).ready(function()
{
readyInit();
});
function init()
{
// borrow some ED code for compatibility
_delta.startEtherDelta(() =>
{
//import of (updated?) etherdelta config
if(etherDeltaConfig)
{
_delta.config.tokens = etherDeltaConfig.tokens;
_delta.config.pairs = etherDeltaConfig.pairs;
}
for(let i = 0; i < _delta.config.tokens.length; i++)
{
let token = _delta.config.tokens[i];
if(token && !uniqueTokens[token.addr])
uniqueTokens[token.addr] = token;
}
//filter out custom tokens that have been listed by now
_delta.config.customTokens = offlineCustomTokens.filter((x) => {return !(uniqueTokens[x.addr]) && true;});
for(let i = 0; i < _delta.config.customTokens.length; i++)
{
let token = _delta.config.customTokens[i];
if(token && !uniqueTokens[token.addr])
uniqueTokens[token.addr] = token;
}
if(stagingTokens)
{
let stageTokens = stagingTokens.filter((x) => {return !(uniqueTokens[x.addr]) && true;});
for(let i = 0; i < _delta.config.customTokens.length; i++)
{
let token = stageTokens[i];
if(token && !uniqueTokens[token.addr])
{
token.longname = token.name;
uniqueTokens[token.addr] = token;
_delta.config.customTokens.push(token);
}
}
}
initiated = true;
if(autoStart)
myClick();
});
}
function readyInit()
{
hideLoading();
// detect enter & keypresses in input
$('#address').keypress(function(e)
{
if (e.keyCode == 13) {
$('#refreshButton').click();
return false;
} else {
hideError();
return true;
}
});
// url parameter ?addr=0x... /#0x..
let trans = getParameterByName('trans');
if(! trans)
{
let hash = window.location.hash; // url parameter /#0x...
if(hash)
trans = hash.slice(1);
}
if(trans)
{
trans = getAddress(trans);
if(trans)
{
transactionHash = trans;
autoStart = true;
// auto start loading
myClick();
}
}
}
// Functions - input
// ##########################################################################################################################################
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();
}
function buttonLoading()
{
if(!transactionHash)
{
hideLoading();
return;
}
$('#loading').removeClass('fa-spin');
$('#loading').removeClass('dim');
$('#loading').prop('disabled', false);
$('#loading').show();
}
function hideLoading()
{
$('#loading').hide();
}
function myClick()
{
if(running)
return;
if(!initiated)
{
autoStart = true;
return;
}
hideError();
hideHint();
disableInput(true);
showLoading();
clearOverview();
// validate address
if(!autoStart)
transactionHash = getAddress();
autoStart = false;
if(transactionHash)
{
$('#direct').html('<a target="_blank" href="https://deltaBalances.github.io/transaction.html#' + transactionHash + '"> Direct Link </a> to this page');
getAll();
}
else
{
console.log('invalid input');
disableInput(false);
hideLoading();
}
}
function getAll(autoload)
{
if(running)
return;
running = true;
lastResult = undefined;
lastResult2 = undefined;
if (transactionHash)
{
//$('#direct').html('<a target="_blank" href="https://deltaBalances.github.io/transaction.html#' + transactionHash + '"> Direct Link </a> to this page');
getTransactions();
} else {
running = false;
disableInput(false);
hideLoading();
}
}
// Functions - validation
// ##########################################################################################################################################
// check if input address is valid
function getAddress(addr)
{
let address = '';
address = addr ? addr : document.getElementById('address').value;
address = address.trim();
{
//check if url ending in address
if(address.indexOf('/0x') !== -1)
{
let parts = address.split('/');
let lastSegment = parts.pop() || parts.pop(); // handle potential trailing slash
if(lastSegment)
address = lastSegment;
}
{
if (address.length == 66 && address.slice(0, 2) === '0x')
{
// address is ok
}
else if (address.length == 64 && address.slice(0, 2) !== '0x')
{
address = '0x'+ address;
}
else
{
if (!addr) // ignore if in url arguments
{
showError("Invalid transaction hash, try again");
}
return undefined;
}
}
}
document.getElementById('address').value = address;
return address;
}
// get parameter from url
function getParameterByName(name, url)
{
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// Functions - requests
// ##########################################################################################################################################
function getTransactions()
{
let transResult = undefined;
let logResult = undefined;
let statusResult = undefined;
let transLoaded = 0;
// status https://api.etherscan.io/api?module=transaction&action=getstatus&txhash=0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a&apikey=YourApiKeyToken
// https://api.etherscan.io/api?module=proxy&action=eth_GetTransactionReceipt&txhash='+ transactionHash;
// https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash='+ transactionHash;
$.getJSON('https://api.etherscan.io/api?module=transaction&action=getstatus&txhash=' + transactionHash + '&apikey=' + _delta.config.etherscanAPIKey, (result) => {
if(result && result.status === '1')
statusResult = result.result;
transLoaded++;
if(transLoaded == 3)
processTransactions(transResult, statusResult, logResult);
});
$.getJSON('https://api.etherscan.io/api?module=proxy&action=eth_GetTransactionReceipt&txhash=' + transactionHash + '&apikey=' + _delta.config.etherscanAPIKey, (result) => {
if(result )
logResult = result.result;
transLoaded++;
if(transLoaded == 3)
processTransactions(transResult, statusResult, logResult);
});
$.getJSON('https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash=' + transactionHash + '&apikey=' + _delta.config.etherscanAPIKey, (result) => {
if(result )
transResult = result.result;
transLoaded++;
if(transLoaded == 3)
processTransactions(transResult, statusResult, logResult);
});
function processTransactions(tx, txStatus, txLog)
{
console.log('completed requests');
let pending = false;
if(!tx.blockHash ||!tx.blockNumber || !tx.transactionIndex)
{
pending = true;
}
let transaction = {
hash: tx.hash,
from: tx.from,
to: tx.to,
rawinput: tx.input,
nonce: Number(tx.nonce),
value: _util.weiToEth(Number(tx.value)),
gasPrice: _util.weiToEth(Number(tx.gasPrice)),
gasGwei: (Number(tx.gasPrice) / 1000000000),
gasLimit: Number(tx.gas),
status: 'Pending',
input: parseInput(tx, tx.input),
}
if(!pending)
{
if(txStatus.isError === '0') {
transaction.status = 'Completed';
transaction.gasUsed = Number(txLog.gasUsed),
transaction.gasEth = Number(txLog.gasUsed) * _util.weiToEth(Number(tx.gasPrice));
transaction.blockNumber = tx.blockNumber;
transaction.blockHash = tx.blockHash;
transaction.rawoutput = null;
transaction.output = parseOutput(tx, txLog.logs);
}
else {
transaction.status = 'Error: ' + txStatus.errDescription;
}
}
finish(transaction);
//to ed, val >0 deposit
// internal from >0 withdraw
function parseOutput(tx, outputLogs)
{
console.log('parsing input');
let outputs = [];
for(i = 0; i < outputLogs.length; i++)
{
let unpacked = _util.processOutputMethod (_delta.web3, tx.to, outputLogs[i]);
if(!unpacked)
{
outputs.push({'error': 'unknown output'});
continue;
}
if(unpacked.name == 'Trade')
{
let tradeType = 'Sell';
let token = undefined;
let base = undefined;
let maker = unpacked.params[4].value;
let taker = unpacked.params[5].value;
if(unpacked.params[0].value === _delta.config.tokens[0].addr) // send get eth -> buy form sell order
{
tradeType = 'Buy';
token = uniqueTokens[unpacked.params[2].value];
base = uniqueTokens[unpacked.params[0].value];
}
else // taker sell
{
token = uniqueTokens[unpacked.params[0].value];
base = uniqueTokens[unpacked.params[2].value];
}
if(token && base && token.addr && base.addr)
{
let amount = 0;
let oppositeAmount = 0;
if(tradeType === 'Sell')
{
amount = unpacked.params[1].value;
oppositeAmount = unpacked.params[3].value;
} else
{
oppositeAmount = unpacked.params[1].value;
amount = unpacked.params[3].value;
}
let unlisted = token.longname && true;
let dvsr = divisorFromDecimals(token.decimals)
let dvsr2 = divisorFromDecimals(base.decimals)
let val = _util.weiToEth(amount, dvsr);
let val2 = _util.weiToEth(oppositeAmount, dvsr2);
let price = 0;
// if(tradeType === 'sell')
{
price = val2 / val;
}
let obj = {
'type': 'Taker '+ tradeType,
'note': 'Clicked an order in the orderbook to trade.',
'token': token,
'amount': val,
'price': price,
'ETH': val2,
'unlisted': unlisted,
};
outputs.push(obj);
}
}
else if(unpacked.name == 'Deposit' || unpacked.name == 'Withdraw')
{
let type = unpacked.name;
let token = uniqueTokens[unpacked.params[0].value];
let user = unpacked.params[1].value;
let rawAmount = unpacked.params[2].value;
let rawBalance = unpacked.params[3].value;
if(token && token.addr)
{
let unlisted = token.longname && true;
let dvsr = divisorFromDecimals(token.decimals)
let val = _util.weiToEth(rawAmount, dvsr);
let balance = _util.weiToEth(rawBalance, dvsr);
if(unpacked.name === 'Withdraw')
{
note = 'Withdrawn from EtherDelta';
}
else
{
note = 'Deposited into EtherDelta';
}
if(token.addr !== '0x0000000000000000000000000000000000000000')
type = 'Token ' + type;
let obj = {
'type': type,
'note': note,
'token':token,
'amount':val,
'balance': balance,
'unlisted':unlisted,
};
outputs.push(obj);
}
}
else if(unpacked.name == 'Cancel')
{
let cancelType = 'sell';
let token = undefined;
let token2 = undefined;
if(unpacked.params[0].value === _delta.config.tokens[0].addr) // get eth -> sell
{
cancelType = 'buy';
token = uniqueTokens[unpacked.params[2].value];
token2 = uniqueTokens[unpacked.params[0].value];
}
else // buy
{
token = uniqueTokens[unpacked.params[0].value];
token2 = uniqueTokens[unpacked.params[2].value];
}
if(token && token2 && token.addr && token2.addr)
{
let amount = 0;
let oppositeAmount = 0;
if(cancelType === 'sell')
{
amount = unpacked.params[1].value;
oppositeAmount = unpacked.params[3].value;
} else
{
oppositeAmount = unpacked.params[1].value;
amount = unpacked.params[3].value;
}
let unlisted = token.longname && true;
let dvsr = divisorFromDecimals(token.decimals)
let dvsr2 = divisorFromDecimals(token2.decimals)
let val = _util.weiToEth(amount, dvsr);
let val2 = _util.weiToEth(oppositeAmount, dvsr2);
let price = 0;
//if(cancelType === 'sell')
{
price = val2 / val;
}
let obj = {
'type': 'Cancel '+ cancelType,
'note': 'Cancelled an open order on EtherDelta',
'token':token,
'amount':val,
'price': price,
'unlisted':unlisted,
};
outputs.push(obj);
}
}
else if(unpacked.name == 'Transfer')
{
let from = outputLogs[i].topics[1];
from = '0x' + from.slice(from.length -40);
let to = outputLogs[i].topics[2];
to = '0x' + to.slice(to.length -40);
let rawAmount = unpacked.params[0].value;
let token = uniqueTokens[outputLogs[i].address];
let dvsr = divisorFromDecimals(token.decimals)
let val = _util.weiToEth(rawAmount, dvsr);
let unlisted = token.longname && true;
let obj = {
'type': 'Transfer',
'note': 'Tokens transferred',
'token': token,
'to': to,
'amount': val,
'unlisted': unlisted,
};
outputs.push(obj);
}
else if(unpacked.name == 'Approval')
{
let sender = outputLogs[i].topics[1];
sender = '0x' + sender.slice(sender.length -40);
let to = outputLogs[i].topics[2];
to = '0x' + to.slice(to.length -40);
let rawAmount = unpacked.params[0].value;
let token = uniqueTokens[outputLogs[i].address];
let dvsr = divisorFromDecimals(token.decimals)
let val = _util.weiToEth(rawAmount, dvsr);
let unlisted = token.longname && true;
let obj = {
'type': 'Approve',
'note': 'Now allows tokens to be transferred by deposit transaction (2/2)',
'sender':sender,
'token': token,
'to': to,
'amount': val,
'unlisted': unlisted,
};
outputs.push(obj);
}
// Order
}
return outputs;
}
function parseInput(tx, input)
{
console.log('parsing output');
// transfer 0xa9059cbb adress to, uint value
let method = input.slice(0, 10);
if(method === '0xa9059cbb') // token transfer
{
let unpacked = _util.processInputMethod (_delta.web3, tx.to, input);
if(unpacked && unpacked.name === 'transfer')
{
let to = unpacked.params[0].value;
let rawAmount = unpacked.params[1].value;
let amount = 0;
let token = uniqueTokens[tx.to];
let unlisted = true;
if(token && token.addr)
{
let dvsr = divisorFromDecimals(token.decimals);
amount = _util.weiToEth(rawAmount, dvsr);
unlisted = token.longname && true;
}
let obj =
{
'type': 'Transfer',
'note': 'Give the token contract the order to transfer your tokens',
'token': token,
'to': to,
'amount': amount,
'unlisted': unlisted,
};
return obj;
}
}
else if(method === '0x095ea7b3') // approve
{
//sender, //amount /to is contractAddr
let unpacked = _util.processInputMethod (_delta.web3, tx.to, input); // contractEtherDelta contractToken
if(unpacked && unpacked.name === 'approve')
{
let sender = unpacked.params[0].value;
let rawAmount = unpacked.params[1].value;
let amount = 0;
let token = uniqueTokens[tx.to];
let unlisted = true;
if(token && token.addr)
{
let dvsr = divisorFromDecimals(token.decimals);
amount = _util.weiToEth(rawAmount, dvsr);
unlisted = token.longname && true;
}
let obj =
{
'type': 'Approve',
'note': 'Transaction (1/2) of a deposit. Approve EtherDelta to move tokens for you.',
'token':token,
'sender':sender,
'amount':amount,
'unlisted': unlisted,
};
return obj;
}
}
else if(method === '0xd0e30db0' || method === '0x2e1a7d4d' ) // deposit /withdraw ETH
{
let unpacked = _util.processInputMethod (_delta.web3, _delta.contractEtherDelta, input);
if(unpacked && (unpacked.name === 'deposit' || unpacked.name === 'withdraw'))
{
let type = '';
let note = '';
let rawVal = 0;
if(unpacked.name === 'deposit') {
rawVal = tx.value;
type = 'Deposit';
note = 'Deposit ETH into EtherDelta contract';
} else {
rawVal = unpacked.params[0].value;
type = 'Withdraw';
note = 'Request EtherDelta to withdraw ETH';
}
let val = _util.weiToEth(rawVal);
let obj = {
'type': type,
'note': note,
'amount':val,
};
return obj;
}
}
//deposit 0xd0e30db0
//withdraw 0x2e1a7d4d
//approve 0x095ea7b3
else if(method === '0x9e281a98' || method === '0x338b5dea') //methodIDs depositToken & wihdrawToken
{
let unpacked = _util.processInputMethod (_delta.web3, _delta.contractEtherDelta, input);
if(unpacked && (unpacked.name === 'depositToken' || unpacked.name === 'withdrawToken'))
{
let token = uniqueTokens[unpacked.params[0].value];
if(token && token.addr)
{
let unlisted = token.longname && true;
let dvsr = divisorFromDecimals(token.decimals)
let val = _util.weiToEth(unpacked.params[1].value, dvsr);
let type = '';
let note = '';
if(unpacked.name === 'withdrawToken')
{
type = 'Withdraw';
note = 'Request EtherDelta to withdraw tokens';
}
else
{
type = 'Deposit';
note = 'Transaction (2/2) of a deposit, request EtherDelta to deposit tokens';
}
let obj = {
'type': 'Token ' + type,
'note': note,
'token':token,
'amount':val,
'unlisted':unlisted,
};
return obj;
}
}
} else if(method === '0x278b8c0e') // cancel
{
//Function: cancelOrder(address tokenGet, uint256 amountGet, address tokenGive, uint256 amountGive, uint256 expires, uint256 nonce, uint8 v, bytes32 r, bytes32 s)
//MethodID: 0x278b8c0e
let unpacked = _util.processInputMethod(_delta.web3, _delta.contractEtherDelta, input);
if(unpacked && (unpacked.name === 'cancelOrder'))
{
let cancelType = 'sell';
let token = undefined;
let token2 = undefined;
if(unpacked.params[0].value === _delta.config.tokens[0].addr) // get eth -> sell
{
cancelType = 'buy';
token = uniqueTokens[unpacked.params[2].value];
token2 = uniqueTokens[unpacked.params[0].value];
}
else // buy
{
token = uniqueTokens[unpacked.params[0].value];
token2 = uniqueTokens[unpacked.params[2].value];
}
if(token && token2 && token.addr && token2.addr)
{
let amount = 0;
let oppositeAmount = 0;
if(cancelType === 'sell')
{
amount = unpacked.params[1].value;
oppositeAmount = unpacked.params[3].value;
} else
{
oppositeAmount = unpacked.params[1].value;
amount = unpacked.params[3].value;
}
let unlisted = token.longname && true;
let dvsr = divisorFromDecimals(token.decimals)
let dvsr2 = divisorFromDecimals(token2.decimals)
let val = _util.weiToEth(amount, dvsr);
let val2 = _util.weiToEth(oppositeAmount, dvsr2);
let price = 0;
//if(cancelType === 'sell')
{
price = val2 / val;
}
let obj = {
'type': 'Cancel '+ cancelType,
'note': 'Cancel an open order on EtherDelta',
'token':token,
'amount':val,
'price': price,
'unlisted':unlisted,
};
return obj;
}
}
} else if(method === '0x0a19b14a') // trade
{
//Function: trade(address tokenGet, uint256 amountGet, address tokenGive, uint256 amountGive, uint256 expires, uint256 nonce, address user, uint8 v, bytes32 r, bytes32 s, uint256 amount)
//MethodID: 0x0a19b14a
let unpacked = _util.processInputMethod(_delta.web3, _delta.contractEtherDelta, input);
if(unpacked && (unpacked.name === 'trade'))
{
let tradeType = 'Sell';
let token = undefined;
let token2 = undefined;
if(unpacked.params[0].value === _delta.config.tokens[0].addr) // get eth -> sell
{
tradeType = 'Buy';
token = uniqueTokens[unpacked.params[2].value];
token2 = uniqueTokens[unpacked.params[0].value];
}
else // buy
{
token = uniqueTokens[unpacked.params[0].value];
token2 = uniqueTokens[unpacked.params[2].value];
}
if(token && token2 && token.addr && token2.addr)
{
let amount = 0;
let oppositeAmount = 0;
if(tradeType === 'Sell')
{
amount = unpacked.params[1].value;
oppositeAmount = unpacked.params[3].value;
} else
{
oppositeAmount = unpacked.params[1].value;
amount = unpacked.params[3].value;
}
let unlisted = token.longname && true;
let dvsr = divisorFromDecimals(token.decimals)
let dvsr2 = divisorFromDecimals(token2.decimals)
let val = _util.weiToEth(amount, dvsr);
let val2 = _util.weiToEth(oppositeAmount, dvsr2);
let price = 0;
// if(tradeType === 'sell')
{
price = val2 / val;
}
let obj = {
'type': 'Taker '+ tradeType,
'note': 'Clicked an order in the orderbook to trade.',
'token':token,
'amount':val,
'price': price,
'ETH': val2,
'unlisted':unlisted,
};
return obj;
}
}
}
}
}
}
// Functions - output
// ##########################################################################################################################################
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)
{
console.log('outputting data');
/*
let transaction = {
hash: ,
from: ,
to: ,
input: ,
nonce: ,
value: ,
gasPrice: ,
gas: ,
gasUsed: ,
error: ,
errorText: ,
input: ,
output: '',
}
*/
let sum = '';
if(transaction.status === 'Completed') {
sum += 'Success!<br>';
}
else if(transaction.status === 'Pending') {
sum += 'Transaction is pending, try again later. If it takes too long, raise your gas price.<br>';
}
else if(transaction.status === 'Error: Bad jump destination' ) {
if (transaction.input.type === 'Taker Sell' || transaction.input.type === 'Taker Buy') {
sum += 'Bad jump destination, someone filled this order before you. (Sent earlier or with a higher gas price).<br>';
}
else if ( transaction.input.type === 'Token Deposit' || transaction.input.type === 'Token Withdraw') {
sum += 'Bad jump destination, token deposit/withdraw failed. You might not have had the right account balance left. Otherwsise check if the token is not locked. (Still in ICO, rewards period, disabled etc.)<br>';
}
} else {
sum += 'Transaction failed.<br>';
}
if(transaction.input && transaction.input.note)
{
sum += transaction.input.note +'<br>';
} else if(transaction.output && transaction.output.length > 0)
{
sum += transaction.output[0].note +'<br>';
}
if(transaction.input && transaction.input.type === 'Transfer' )
{
if(uniqueTokens[transaction.input.to])
{
sum += 'Warning, you sent tokens to a token contract, this is usually a mistake. <br>';
}
else if(transaction.input.to === _delta.config.contractEtherDeltaAddr)
{
sum += 'Warning, you sent tokens to the EtherDelta contract without a deposit, you can no longer access these tokens. <br>';
}
}
if(!transaction.input && (!transaction.output || transaction.output.length == 0))
{
sum += 'This does not seem to be an EtherDelta transaction <br>';
}
if(checkOldED(transaction.to)) {
sum += 'This transaction is to an outdated EtherDelta contract, only use these to withdraw old funds.<br>';
}
let tradeCount = 0;
if(transaction.output)
{
for(i = 0; i < transaction.output.length; i++)
{
if(transaction.output[i].type === 'Taker Sell' || transaction.output[i].type === 'Taker Buy')
{
tradeCount++;
}
}
if(tradeCount > 1 && transaction.to !== _delta.config.contractEtherDeltaAddr)
{
sum += 'This transaction was made by a contract that has made multiple trades in a single transaction.';
}
}
$('#summary').html(sum);
$('#hash').html(hashLink(transaction.hash, true));
$('#from').html(addressLink(transaction.from, true));
$('#to').html(addressLink(transaction.to, true));
$('#cost').html('??');
$('#gasprice').html();
$('#gasgwei').html(transaction.gasGwei + ' Gwei (' + transaction.gasPrice.toFixed(10) + ' ETH)');
if(transaction.status === 'Completed') {
$('#gascost').html(Number(transaction.gasEth).toFixed(5) + ' ETH');
} else if(transaction.status === 'Pending') {
$('#gascost').html('Pending');
} else {
$('#gascost').html('Failed');
}
$('#gaslimit').html(transaction.gasLimit);
$('#nonce').html(transaction.nonce);
if(transaction.status === 'Completed')
$('#status').html('<i style="color:green;" class="fa fa-check"></i>' + ' ' + transaction.status);
else if(transaction.status === 'Pending')
$('#status').html('<i class="fa fa-cog fa-fw"></i>' + ' ' + transaction.status);
else
$('#status').html('<i style="color:red;" class="fa fa-exclamation-circle"></i>' + ' ' + transaction.status);
$('#time').html('??');
$('#ethval').html(transaction.value);
$('#inputdata').html('');
if(transaction.input && transaction.input.type)
{
$('#inputtype').html(transaction.input.type);
} else
{
if(tradeCount == 0)
$('#inputtype').html('');