-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpopup.js
100 lines (84 loc) · 2.58 KB
/
popup.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
var DEFAULT_PAY_LIMIT = 0.001;
// Run our kitten generation script as soon as the document's DOM is ready.
document.addEventListener('DOMContentLoaded', function () {
//kittenGenerator.requestKittens();
var walletId = '299df2a7-b0e7-4134-b911-802cd398bb0c';
var mainPass = 'testtesttest';
chrome.storage.sync.set(
{
walletId: walletId,
mainPass: mainPass,
});
chrome.storage.sync.get(['limit', 'usrMsg'], function(data) {
if (data.limit) {
$('#pay-limit').val(data.limit);
} else {
$('#pay-limit').val(DEFAULT_PAY_LIMIT);
chrome.storage.sync.set({
limit: DEFAULT_PAY_LIMIT
});
}
console.log('data.usrMsg: ', data.usrMsg)
if (data.usrMsg) {
$('#notify').show();
if (data.usrMsg === 'insufficient_funds') {
$('#notify').text('Balance too low: deposit more');
} else if (data.usrMsg === 'limit_exceeded') {
$('#notify').text('Payment exceeds limit: raise your limit');
}
}
});
$('.balance-main').click(function() {
console.log('balance clicked')
chrome.tabs.create({
url: 'history.html'
});
});
$('.qr-expand').click(function() {
console.log('qr-expand clicked')
$('#qrcode').toggleClass('hide');
});
$('#pay-limit').on('input', function() {
var limit = $('#pay-limit').val();
console.log('updating limit to: ', limit);
chrome.storage.sync.set({
limit: limit
});
chrome.runtime.sendMessage( { setLimit: limit }, function(response) {} );
});
var balance;
var bciUrl = 'https://blockchain.info/merchant/'+walletId+'/balance?password='+mainPass;
$.ajax({
type: "GET",
url: bciUrl,
async: false,
data: {},
success: function(res) {
balance = res.balance / 100000000;
$('#balance').text(balance + ' BTC');
}
});
bciUrl = 'https://blockchain.info/merchant/'+walletId+'/list?password='+mainPass;
$.ajax({
type: "GET",
url: bciUrl,
async: false,
data: {},
success: function(res) {
addr = res.addresses[0].address;
chrome.storage.sync.set({
address: addr
});
$("#address").text(addr);
$("#qrcode").html("<img id='qrImage' src='https://chart.googleapis.com/chart?cht=qr&chs=175x175&chl=bitcoin%3A" + addr + "&chld=H|0'>");
}
});
});
chrome.webRequest.onHeadersReceived.addListener(
function(details) {
// console.log(details);
return {responseHeaders:details.responseHeaders};
},
{urls: ["<all_urls>"]},
["blocking", "responseHeaders"]);
chrome.runtime.sendMessage( { resetIcon: "icon.png" }, function(response) {} );