-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathaddress_page.js
109 lines (75 loc) · 3.02 KB
/
address_page.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
$(document).ready(function() {
$('#add-to-wallet').click(function() {
goToWallet(address);
});
$('#deposit').click(function() {
loadScript(resource + 'wallet/deposit/deposit.js', function() {
showDepositModal(address, 'bitinstant', 'Deposit Using Cash');
});
});
$('#payment-request').click(function() {
loadScript(resource + 'wallet/payment-request.js', function() {
showPaymentRequestModal(address, 'Payment Request');
});
});
loadScript(resource + 'wallet/qr.code.creator.js', function() {
var canvas = makeQRCode(255,250, 1, address);
$('#qr-code').append(canvas);
});
$('#filter').change(function(){
$(this).parent().submit();
});
try {
var ws = new WebSocket(getWebSocketURL());
ws.onmessage = function(e) {
var obj = $.parseJSON(e.data);
if (obj.op == 'status') {
$('#status').html(obj.msg);
} else if (obj.op == 'utx') {
op = obj.x;
try {
playSound('beep');
} catch(e) { console.log(e); }
var tx = TransactionFromJSON(op);
tx.setConfirmations(0);
/* Calculate the result */
var result = 0;
for (var i = 0; i < tx.inputs.length; i++) {
var input = tx.inputs[i];
console.log(input.prev_out.addr);
//If it is our address then subtract the value
if (input.prev_out.addr == address) {
result -= parseInt(input.prev_out.value);
}
}
console.log('result ' + result);
var total_received = 0;
for (var i = 0; i < tx.out.length; i++) {
var output = tx.out[i];
if (output.addr == address) {
total_received += parseInt(output.value);
}
}
$('#total_received span').attr('data-c', parseInt($('#total_received span').attr('data-c')) + total_received);
result += total_received;
$('#final_balance span').attr('data-c', parseInt($('#final_balance span').attr('data-c')) + result);
flashTitle('New Transaction');
tx.result = result;
$('#tx_container').prepend(tx.getHTML());
$('#tx-'+op.txIndex).fadeIn("slow").slideDown('slow');
console.log($('#n_transactions').val());
$('#n_transactions').text(parseInt($('#n_transactions').text())+1);
calcMoney();
}
};
ws.onopen = function() {
$('#status').html('Connected. ');
ws.send('{"op":"addr_sub", "addr":"'+address+'"}');
};
ws.onclose = function() {
$('#status').html('Disconnected');
};
} catch (e) {
console.log(e);
}
});