forked from blockchain/unused-My-Wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
address_page.js
153 lines (113 loc) · 4.6 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
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
function insertParam(key, value) {
key = escape(key); value = escape(value);
var kvp = document.location.search.substr(1).split('&');
if (kvp == '') {
document.location.search = '?' + key + '=' + value;
}
else {
var i = kvp.length; var x; while (i--) {
x = kvp[i].split('=');
if (x[0] == key) {
x[1] = value;
kvp[i] = x.join('=');
break;
}
}
if (i < 0) { kvp[kvp.length] = [key, value].join('='); }
//this will reload the page, it's likely better to store this until finished
document.location.search = kvp.join('&');
}
}
$(document).ready(function() {
var filter = parseInt($(document.body).data('filter'));
var offset = parseInt($(document.body).data('offet'));
var address = $(document.body).data('address');
$('#payment-request').click(function() {
loadScript('wallet/frame-modal', function() {
showFrameModal({
title : 'Create Payment Request',
description : 'Request Payment into address <b>'+address+'</b>',
src : root + 'payment_request?address='+address
});
});
});
$('#create-donation-button').click(function() {
loadScript('wallet/frame-modal', function() {
showFrameModal({
title : 'Create Donation Button',
description : 'Create Donation Button To Address <b>'+address+'</b>',
src : root + 'create_donation_button?address='+address,
height : '600px'
});
});
});
$('.tx_filter a').click(function(){
var value = $(this).data('value');
if (value == 'export') {
loadScript('wallet/frame-modal', function() {
showFrameModal({
title : 'Export History',
description : '',
src : root + 'export-history?active='+address
});
});
return;
}
insertParam('filter', $(this).data('value'));
});
if (filter == 0 && offset == 0) {
webSocketConnect(function(ws) {
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;
playSound('beep');
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];
if (!input.prev_out)
continue;
var value = parseInt(input.prev_out.value);
//If it is our address then subtract the value
if (input.prev_out.addr == address) {
result -= value;
}
}
for (var i = 0; i < tx.out.length; i++) {
var output = tx.out[i];
var value = parseInt(output.value);
if (output.addr == address) {
result += value;
}
}
$('#total_received span').data('c', parseInt($('#total_received span').data('c')) + Math.max(result, 0));
$('#final_balance span').data('c', parseInt($('#final_balance span').data('c')) + result);
tx.result = result;
$('#no_tx').hide();
var tx_html = tx.getHTML();
var container = $('#tx_container');
container.prepend(tx_html);
setupSymbolToggle();
tx_html.hide().slideDown('slow');
if (container.find('.txdiv').length > 50) {
container.find('.txdiv:last-child').remove();
}
$('#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');
};
});
}
});