This repository has been archived by the owner on May 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
125 lines (95 loc) · 3.48 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//this port communicate with background
var port = chrome.runtime.connect({name: "popup"});
port.postMessage({src: "popup",dst:"background"});
port.onMessage.addListener(function(msg) {
console.log("msg listened: " +JSON.stringify(msg));
if (!! msg.unapprovedTxs) {
var length = msg.unapprovedTxs.length
if(msg.unapprovedTxs.length > 0) {
var data = msg.unapprovedTxs[length - 1].data
console.log("to address: " + data.to + ", mount: " + data.value)
$(".icon-address.to input").val(data.to);
$("#amount").val(data.value);
}else{
console.log("no more unapprovedTxs")
$(".icon-address.to input").val('');
$("#amount").val('');
}
}
});
/*
chrome.runtime.onConnect.addListener(function(port) {
console.log("Connected ....." + port.name);
port.onMessage.addListener(function(msg) {
console.log("msg listened: " + JSON.stringify(msg));
})
})
*/
//load stored keyfle info from chrome.storage.local
document.addEventListener("DOMContentLoaded", function() {
console.log("popout page loaded...")
chrome.storage.local.get(['keyInfo'], function(result) {
console.log('keyInfo Value is :' + JSON.stringify(result.keyInfo));
result = JSON.parse(result.keyInfo)
if(!!result){
$(".container select-wallet-file").addClass("active1")
console.log("unlockFile:")
UnlockFile(result.fileJson, result.password)
getNextTx()
}
});
});
var AccAddress ;
function getNextTx() {
port.postMessage({
src: "popup",
dst:"background",
data: {
getNextTx : 'true'
}
});
}
function UnlockFile( fileJson, password) {
console.log("\tfileJson: " + JSON.stringify(fileJson) )
try {
var address;
var Account = require("nebulas").Account
var account = Account.fromAddress(fileJson.address)
account.fromKey(fileJson, password);
address = account.getAddressString();
gAccount = account;
AccAddress = address;
console.log("AccAddress got...")
port.postMessage({
src: "popup",
dst:"background",
data: {
AccAddress : AccAddress
}
});
console.log("\tfileJson: " + JSON.stringify(gAccount) )
$(".icon-address.from input").val(address).trigger("input"); // gen icon from addr, needs trigger 'input' event if via set o.value
$("#unlock").hide();
$("#send").show();
neb.api.getAccountState(address)
.then(function (resp) {
var nas = Unit.fromBasic(resp.balance, "nas").toNumber();
console.log("\tbalance: " + nas +", nonce: " + resp.nonce)
$("#balance").val(nas).trigger("input"); // add comma & unit from value, needs trigger 'input' event if via set o.value
$("#nonce").val(parseInt(resp.nonce || 0) + 1);
})
.catch(function (e) {
// this catches e thrown by nebulas.js!neb
bootbox.dialog({
backdrop: true,
onEscape: true,
message: i18n.apiErrorToText(e.message),
size: "large",
title: "Error"
});
});
} catch (e) {
// this catches e thrown by nebulas.js!account
console.log("unlockFile error:" + JSON.stringify(e))
}
}