File tree 6 files changed +38
-34
lines changed
6 files changed +38
-34
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ window.addEventListener('message', function(e) {
81
81
82
82
It is useful for Dapp to get the current account address in the extension. Here is the explanation on how to achive this.
83
83
84
- Method 1:
84
+ #### Method 1:
85
85
``` js
86
86
var userAddrerss;
87
87
@@ -98,14 +98,14 @@ function getUserAddress() {
98
98
window .addEventListener (' message' , function (e ) {
99
99
// e.detail contains the transferred data (can
100
100
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 ) {
102
102
userAddrerss = e .data .data .account ;
103
103
}
104
104
})
105
105
106
106
```
107
107
108
- Method 2:
108
+ #### Method 2:
109
109
A module ` NasExtWallet ` is injected to your page if NasExtWallet is installed, then you can use the code below to get user account:
110
110
``` js
111
111
var userAddrerss;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ var neb = new nebulas.Neb();
14
14
var gAccount ;
15
15
var network , chainId ;
16
16
17
- var sourceName = 'nebulas_WebExtensionWallet ' ;
17
+ // var sourceName = 'NasExtWallet ';
18
18
19
19
function resetNeb ( ) {
20
20
//network = (localSave.getItem("network") || "").toLowerCase();
@@ -92,13 +92,14 @@ chrome.runtime.onConnect.addListener(function(port) {
92
92
else if ( msg . data . method === "neb_call" ) {
93
93
rpc_call ( msg . data . data , function ( resp ) {
94
94
port . postMessage ( {
95
- source : sourceName ,
95
+ // source: sourceName,
96
96
neb_call : resp
97
97
} )
98
98
} )
99
99
}
100
100
else if ( msg . data . method === "getAccount" )
101
101
port . postMessage ( {
102
+ //source: sourceName,
102
103
account : AccAddress ,
103
104
accountPubKey : AccPubKey ,
104
105
accountPubKeyString : AccPubKeyString
@@ -115,9 +116,6 @@ chrome.runtime.onConnect.addListener(function(port) {
115
116
}
116
117
else if ( ! ! msg . data . changeNetwork ) {
117
118
if ( msg . data . changeNetwork !== network ) {
118
- //localSave.setItem("network", msg.data.network);
119
- //localSave.setItem("chainId", msg.data.chainId);
120
- //location.reload(true)
121
119
resetNeb ( ) ;
122
120
}
123
121
}
@@ -126,7 +124,7 @@ chrome.runtime.onConnect.addListener(function(port) {
126
124
}
127
125
else if ( ! ! msg . data . getNextTx ) {
128
126
port . postMessage ( {
129
- source : sourceName ,
127
+ // source: sourceName,
130
128
unapprovedTxs : unapprovedTxs
131
129
} )
132
130
}
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ port.onMessage.addListener(function(msg) {
17
17
//console.log("port.onMessage: " +JSON.stringify(msg));
18
18
19
19
window . postMessage ( { //forward msg from background to webpage
20
+ "src" : "content" ,
21
+ "dst" : "inpage" ,
20
22
"data" :msg
21
23
} , "*" ) ;
22
24
@@ -34,7 +36,6 @@ chrome.runtime.onMessage.addListener(
34
36
// console.log(sender.tab ?
35
37
// "from a content script:" + sender.tab.url :
36
38
// "from the extension");
37
- // console.log("chrome.runtime.onMessage." + JSON.stringify(request));
38
39
39
40
if ( request . logo === "nebulas" ) {
40
41
request . src = "content"
@@ -43,6 +44,7 @@ chrome.runtime.onMessage.addListener(
43
44
}
44
45
45
46
window . postMessage ( { //forward msg from background to webpage
47
+ "src" : "content" ,
46
48
"data" : request
47
49
} , "*" ) ;
48
50
@@ -53,16 +55,15 @@ window.addEventListener('message', function(e) {
53
55
//if (e.source != window)
54
56
// return;
55
57
56
- //console.log("window.addEventListener: msg.data: " + JSON.stringify(e.data) );
57
-
58
+ //first version,
58
59
if ( e . data . target === "contentscript" ) {
59
60
port . postMessage ( { //forward msg from webpage to background, [just for compatible]
60
61
src : "contentScript" ,
61
62
dst : "background" ,
62
63
data : e . data
63
64
} )
64
65
}
65
-
66
+ //add nebpay support
66
67
if ( e . data . logo === "nebulas" && e . data . src === "nebPay" ) { //msg from nebPay
67
68
e . data . src = "content"
68
69
chrome . runtime . sendMessage ( e . data , function ( response ) {
Original file line number Diff line number Diff line change @@ -20,29 +20,33 @@ $("#btn_done").on("click", function () {
20
20
window . close ( )
21
21
} ) ;
22
22
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
+ } )
27
30
28
- var interval = 0 ;
31
+ var countDown
29
32
function setAutoCheck ( ) {
30
- if ( interval === 1000 )
31
- return
32
33
33
34
if ( $ ( ".status" ) . text ( ) !== "success" ) {
34
- interval = 1000
35
- var second = 15
35
+ var interval = 1000
36
+ var second = 15 + 1
36
37
var number = second
37
- var countDown = setInterval ( function ( ) {
38
+
39
+ clearInterval ( countDown )
40
+ countDown = setInterval ( function ( ) {
38
41
if ( $ ( ".status" ) . text ( ) === "success" ||
39
42
$ ( ".status" ) . text ( ) === "fail" ) {
40
- clearInterval ( countDown )
41
43
//$("#counterDown").remove()
42
44
$ ( "#btn" ) . hide ( )
43
45
$ ( "#btn_done" ) . show ( )
44
46
}
45
47
48
+ number -- ;
49
+ //创建或更新倒计时显示,显示number值
46
50
if ( $ ( "#counterDown" ) . length > 0 ) {
47
51
$ ( "#counterDown" ) . text ( ' (' + number + ')' )
48
52
} else {
@@ -51,19 +55,21 @@ function setAutoCheck() {
51
55
spanTag . innerHTML = '(' + number + ')' ;
52
56
$ ( "#btn" ) . append ( spanTag ) ;
53
57
}
54
-
58
+ //等待倒计时结束
55
59
if ( number === 0 ) {
56
- number = second
60
+ // number = second
57
61
onClickBtn ( )
58
62
}
59
-
60
- number -- ;
61
-
62
63
} , interval )
63
64
}
64
65
65
66
}
66
67
68
+ // function onClickBtn() {
69
+ // setAutoCheck()
70
+ // onClickBtnRefresh()
71
+ // }
72
+
67
73
function onClickBtn ( ) {
68
74
var addr = $ ( "#input" ) . val ( ) ;
69
75
Original file line number Diff line number Diff line change @@ -264,8 +264,8 @@ function onClickModalConfirmS() {
264
264
setTimeout ( ( ) => {
265
265
window . location . href = "check.html?" + mTxHash ;
266
266
} , 1000 )
267
-
268
- return neb . api . getTransactionReceipt ( mTxHash ) ;
267
+ return ;
268
+ // return neb.api.getTransactionReceipt(mTxHash);
269
269
} ) . then ( function ( resp ) {
270
270
$ ( "#receipt" ) . text ( mTxHash ) . prop ( "href" , "check.html?" + mTxHash ) ;
271
271
$ ( "#receipt_state" ) . val ( JSON . stringify ( resp ) ) ;
Original file line number Diff line number Diff line change @@ -12,16 +12,15 @@ var _NasExtWallet = function () {
12
12
getUserAddressCallback = callback
13
13
window . postMessage ( {
14
14
"target" : "contentscript" ,
15
- "data" :{
16
- } ,
15
+ "data" :{ } ,
17
16
"method" : "getAccount" ,
18
17
} , "*" ) ;
19
18
}
20
19
21
20
// listen message from contentscript
22
21
window . addEventListener ( 'message' , function ( e ) {
23
22
// 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 ) {
25
24
userAddrerss = e . data . data . account ;
26
25
if ( typeof getUserAddressCallback === 'function' ) {
27
26
getUserAddressCallback ( userAddrerss )
You can’t perform that action at this time.
0 commit comments