Skip to content

Commit 51b8449

Browse files
committed
update
1 parent dbad9c8 commit 51b8449

File tree

6 files changed

+38
-34
lines changed

6 files changed

+38
-34
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ window.addEventListener('message', function(e) {
8181

8282
It is useful for Dapp to get the current account address in the extension. Here is the explanation on how to achive this.
8383

84-
Method 1:
84+
#### Method 1:
8585
```js
8686
var userAddrerss;
8787

@@ -98,14 +98,14 @@ function getUserAddress() {
9898
window.addEventListener('message', function(e) {
9999
// e.detail contains the transferred data (can
100100
console.log("recived by page:" + e + ", e.data:" + JSON.stringify(e.data));
101-
if (!!e.data.data.account) {
101+
if (!!e.data.data && !!e.data.data.account) {
102102
userAddrerss = e.data.data.account;
103103
}
104104
})
105105

106106
```
107107

108-
Method 2:
108+
#### Method 2:
109109
A module `NasExtWallet` is injected to your page if NasExtWallet is installed, then you can use the code below to get user account:
110110
```js
111111
var userAddrerss;

background.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var neb = new nebulas.Neb();
1414
var gAccount;
1515
var network ,chainId;
1616

17-
var sourceName = 'nebulas_WebExtensionWallet';
17+
//var sourceName = 'NasExtWallet';
1818

1919
function resetNeb() {
2020
//network = (localSave.getItem("network") || "").toLowerCase();
@@ -92,13 +92,14 @@ chrome.runtime.onConnect.addListener(function(port) {
9292
else if (msg.data.method === "neb_call"){
9393
rpc_call(msg.data.data,function (resp) {
9494
port.postMessage({
95-
source: sourceName,
95+
//source: sourceName,
9696
neb_call: resp
9797
})
9898
})
9999
}
100100
else if (msg.data.method === "getAccount")
101101
port.postMessage({
102+
//source: sourceName,
102103
account: AccAddress,
103104
accountPubKey: AccPubKey,
104105
accountPubKeyString: AccPubKeyString
@@ -115,9 +116,6 @@ chrome.runtime.onConnect.addListener(function(port) {
115116
}
116117
else if(!!msg.data.changeNetwork){
117118
if(msg.data.changeNetwork !== network){
118-
//localSave.setItem("network", msg.data.network);
119-
//localSave.setItem("chainId", msg.data.chainId);
120-
//location.reload(true)
121119
resetNeb();
122120
}
123121
}
@@ -126,7 +124,7 @@ chrome.runtime.onConnect.addListener(function(port) {
126124
}
127125
else if (!!msg.data.getNextTx){
128126
port.postMessage({
129-
source: sourceName,
127+
//source: sourceName,
130128
unapprovedTxs : unapprovedTxs
131129
})
132130
}

contentscript.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ port.onMessage.addListener(function(msg) {
1717
//console.log("port.onMessage: " +JSON.stringify(msg));
1818

1919
window.postMessage({ //forward msg from background to webpage
20+
"src": "content",
21+
"dst": "inpage",
2022
"data":msg
2123
}, "*");
2224

@@ -34,7 +36,6 @@ chrome.runtime.onMessage.addListener(
3436
// console.log(sender.tab ?
3537
// "from a content script:" + sender.tab.url :
3638
// "from the extension");
37-
// console.log("chrome.runtime.onMessage." + JSON.stringify(request));
3839

3940
if(request.logo === "nebulas"){
4041
request.src = "content"
@@ -43,6 +44,7 @@ chrome.runtime.onMessage.addListener(
4344
}
4445

4546
window.postMessage({ //forward msg from background to webpage
47+
"src": "content",
4648
"data": request
4749
}, "*");
4850

@@ -53,16 +55,15 @@ window.addEventListener('message', function(e) {
5355
//if (e.source != window)
5456
// return;
5557

56-
//console.log("window.addEventListener: msg.data: " + JSON.stringify(e.data) );
57-
58+
//first version,
5859
if(e.data.target === "contentscript") {
5960
port.postMessage({ //forward msg from webpage to background, [just for compatible]
6061
src: "contentScript",
6162
dst: "background",
6263
data: e.data
6364
})
6465
}
65-
66+
//add nebpay support
6667
if(e.data.logo === "nebulas" && e.data.src === "nebPay") { //msg from nebPay
6768
e.data.src = "content"
6869
chrome.runtime.sendMessage(e.data, function (response) {

html/js/check.js

+22-16
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,33 @@ $("#btn_done").on("click", function () {
2020
window.close()
2121
});
2222

23-
if (hash) {
24-
$("#input").val(hash);
25-
$("#btn").trigger("click");
26-
}
23+
$(function () {
24+
if (hash) { //如果hash不为空,说明是从交易页面跳转过来的,直接出发查询过程
25+
$("#input").val(hash);
26+
$("#btn").trigger("click");
27+
}
28+
29+
})
2730

28-
var interval = 0;
31+
var countDown
2932
function setAutoCheck() {
30-
if(interval === 1000)
31-
return
3233

3334
if($(".status").text() !== "success"){
34-
interval = 1000
35-
var second = 15
35+
var interval = 1000
36+
var second = 15 + 1
3637
var number = second
37-
var countDown = setInterval(function () {
38+
39+
clearInterval(countDown)
40+
countDown = setInterval(function () {
3841
if($(".status").text() === "success" ||
3942
$(".status").text() === "fail"){
40-
clearInterval(countDown)
4143
//$("#counterDown").remove()
4244
$("#btn").hide()
4345
$("#btn_done").show()
4446
}
4547

48+
number--;
49+
//创建或更新倒计时显示,显示number值
4650
if( $("#counterDown").length > 0){
4751
$("#counterDown").text(' (' + number + ')')
4852
}else{
@@ -51,19 +55,21 @@ function setAutoCheck() {
5155
spanTag.innerHTML = '(' + number + ')';
5256
$("#btn").append(spanTag);
5357
}
54-
58+
//等待倒计时结束
5559
if(number === 0){
56-
number = second
60+
//number = second
5761
onClickBtn()
5862
}
59-
60-
number--;
61-
6263
}, interval)
6364
}
6465

6566
}
6667

68+
// function onClickBtn() {
69+
// setAutoCheck()
70+
// onClickBtnRefresh()
71+
// }
72+
6773
function onClickBtn() {
6874
var addr = $("#input").val();
6975

html/js/sendNas.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ function onClickModalConfirmS() {
264264
setTimeout(() => {
265265
window.location.href = "check.html?" + mTxHash;
266266
}, 1000)
267-
268-
return neb.api.getTransactionReceipt(mTxHash);
267+
return;
268+
//return neb.api.getTransactionReceipt(mTxHash);
269269
}).then(function (resp) {
270270
$("#receipt").text(mTxHash).prop("href", "check.html?" + mTxHash);
271271
$("#receipt_state").val(JSON.stringify(resp));

inpage.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ var _NasExtWallet = function () {
1212
getUserAddressCallback = callback
1313
window.postMessage({
1414
"target": "contentscript",
15-
"data":{
16-
},
15+
"data":{},
1716
"method": "getAccount",
1817
}, "*");
1918
}
2019

2120
// listen message from contentscript
2221
window.addEventListener('message', function(e) {
2322
// e.detail contains the transferred data (can
24-
if (!!e.data.data.account) {
23+
if (e.data.src ==="content" && e.data.dst === "inpage" && !!e.data.data && !!e.data.data.account) {
2524
userAddrerss = e.data.data.account;
2625
if(typeof getUserAddressCallback === 'function'){
2726
getUserAddressCallback(userAddrerss)

0 commit comments

Comments
 (0)