Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yupnano committed Jun 25, 2018
1 parent dbad9c8 commit 51b8449
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 34 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -81,7 +81,7 @@ window.addEventListener('message', function(e) {

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

Method 1:
#### Method 1:
```js
var userAddrerss;

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

```

Method 2:
#### Method 2:
A module `NasExtWallet` is injected to your page if NasExtWallet is installed, then you can use the code below to get user account:
```js
var userAddrerss;
Expand Down
10 changes: 4 additions & 6 deletions background.js
Expand Up @@ -14,7 +14,7 @@ var neb = new nebulas.Neb();
var gAccount;
var network ,chainId;

var sourceName = 'nebulas_WebExtensionWallet';
//var sourceName = 'NasExtWallet';

function resetNeb() {
//network = (localSave.getItem("network") || "").toLowerCase();
Expand Down Expand Up @@ -92,13 +92,14 @@ chrome.runtime.onConnect.addListener(function(port) {
else if (msg.data.method === "neb_call"){
rpc_call(msg.data.data,function (resp) {
port.postMessage({
source: sourceName,
//source: sourceName,
neb_call: resp
})
})
}
else if (msg.data.method === "getAccount")
port.postMessage({
//source: sourceName,
account: AccAddress,
accountPubKey: AccPubKey,
accountPubKeyString: AccPubKeyString
Expand All @@ -115,9 +116,6 @@ chrome.runtime.onConnect.addListener(function(port) {
}
else if(!!msg.data.changeNetwork){
if(msg.data.changeNetwork !== network){
//localSave.setItem("network", msg.data.network);
//localSave.setItem("chainId", msg.data.chainId);
//location.reload(true)
resetNeb();
}
}
Expand All @@ -126,7 +124,7 @@ chrome.runtime.onConnect.addListener(function(port) {
}
else if (!!msg.data.getNextTx){
port.postMessage({
source: sourceName,
//source: sourceName,
unapprovedTxs : unapprovedTxs
})
}
Expand Down
9 changes: 5 additions & 4 deletions contentscript.js
Expand Up @@ -17,6 +17,8 @@ port.onMessage.addListener(function(msg) {
//console.log("port.onMessage: " +JSON.stringify(msg));

window.postMessage({ //forward msg from background to webpage
"src": "content",
"dst": "inpage",
"data":msg
}, "*");

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

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

window.postMessage({ //forward msg from background to webpage
"src": "content",
"data": request
}, "*");

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

//console.log("window.addEventListener: msg.data: " + JSON.stringify(e.data) );

//first version,
if(e.data.target === "contentscript") {
port.postMessage({ //forward msg from webpage to background, [just for compatible]
src: "contentScript",
dst: "background",
data: e.data
})
}

//add nebpay support
if(e.data.logo === "nebulas" && e.data.src === "nebPay") { //msg from nebPay
e.data.src = "content"
chrome.runtime.sendMessage(e.data, function (response) {
Expand Down
38 changes: 22 additions & 16 deletions html/js/check.js
Expand Up @@ -20,29 +20,33 @@ $("#btn_done").on("click", function () {
window.close()
});

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

})

var interval = 0;
var countDown
function setAutoCheck() {
if(interval === 1000)
return

if($(".status").text() !== "success"){
interval = 1000
var second = 15
var interval = 1000
var second = 15 + 1
var number = second
var countDown = setInterval(function () {

clearInterval(countDown)
countDown = setInterval(function () {
if($(".status").text() === "success" ||
$(".status").text() === "fail"){
clearInterval(countDown)
//$("#counterDown").remove()
$("#btn").hide()
$("#btn_done").show()
}

number--;
//创建或更新倒计时显示,显示number值
if( $("#counterDown").length > 0){
$("#counterDown").text(' (' + number + ')')
}else{
Expand All @@ -51,19 +55,21 @@ function setAutoCheck() {
spanTag.innerHTML = '(' + number + ')';
$("#btn").append(spanTag);
}

//等待倒计时结束
if(number === 0){
number = second
//number = second
onClickBtn()
}

number--;

}, interval)
}

}

// function onClickBtn() {
// setAutoCheck()
// onClickBtnRefresh()
// }

function onClickBtn() {
var addr = $("#input").val();

Expand Down
4 changes: 2 additions & 2 deletions html/js/sendNas.js
Expand Up @@ -264,8 +264,8 @@ function onClickModalConfirmS() {
setTimeout(() => {
window.location.href = "check.html?" + mTxHash;
}, 1000)

return neb.api.getTransactionReceipt(mTxHash);
return;
//return neb.api.getTransactionReceipt(mTxHash);
}).then(function (resp) {
$("#receipt").text(mTxHash).prop("href", "check.html?" + mTxHash);
$("#receipt_state").val(JSON.stringify(resp));
Expand Down
5 changes: 2 additions & 3 deletions inpage.js
Expand Up @@ -12,16 +12,15 @@ var _NasExtWallet = function () {
getUserAddressCallback = callback
window.postMessage({
"target": "contentscript",
"data":{
},
"data":{},
"method": "getAccount",
}, "*");
}

// listen message from contentscript
window.addEventListener('message', function(e) {
// e.detail contains the transferred data (can
if (!!e.data.data.account) {
if (e.data.src ==="content" && e.data.dst === "inpage" && !!e.data.data && !!e.data.data.account) {
userAddrerss = e.data.data.account;
if(typeof getUserAddressCallback === 'function'){
getUserAddressCallback(userAddrerss)
Expand Down

0 comments on commit 51b8449

Please sign in to comment.