mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
improvements
This commit is contained in:
parent
016d464043
commit
daf89024f5
1 changed files with 53 additions and 11 deletions
|
|
@ -127,13 +127,13 @@ const AuthorizationHTML = `
|
||||||
<p id="infomessage">Please wait...</p>
|
<p id="infomessage">Please wait...</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="form" class="wrapper">
|
<form id="form" class="wrapper">
|
||||||
<br/>
|
<br/>
|
||||||
<p id="message" class="message"></p>
|
<p id="message" class="message"></p>
|
||||||
<p id="passwordField"><label>Password Required:</label><input id="password" type="password" /></p>
|
<p id="passwordField"><label>Password Required:</label><input id="password" type="password" /></p>
|
||||||
<button id="cancel-button" autofocus>Cancel</button>
|
<button id="cancel-button" type="button" autofocus>Cancel</button>
|
||||||
<button id="confirm-button" >Confirm</button>
|
<button id="confirm-button" type="button" >Confirm</button>
|
||||||
</div>
|
</form>
|
||||||
|
|
||||||
<div id="modal-dialog" class="wrapper">
|
<div id="modal-dialog" class="wrapper">
|
||||||
<h3 id="modal-dialog-title" class="title">Title</h3>
|
<h3 id="modal-dialog-title" class="title">Title</h3>
|
||||||
|
|
@ -142,6 +142,8 @@ const AuthorizationHTML = `
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
var noMessageReceivedYet = true;
|
||||||
|
var closedByCode = false;
|
||||||
var pleaseWait = document.getElementById("pleasewait");
|
var pleaseWait = document.getElementById("pleasewait");
|
||||||
var form = document.getElementById("form");
|
var form = document.getElementById("form");
|
||||||
var cancelButton = document.getElementById("cancel-button");
|
var cancelButton = document.getElementById("cancel-button");
|
||||||
|
|
@ -164,6 +166,12 @@ const AuthorizationHTML = `
|
||||||
}else if(window.parent != window){
|
}else if(window.parent != window){
|
||||||
source = window.parent;
|
source = window.parent;
|
||||||
}else{
|
}else{
|
||||||
|
console.log("closing");
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeWindow(){
|
||||||
|
closedByCode = true;
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,6 +209,11 @@ const AuthorizationHTML = `
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hideMessage(){
|
||||||
|
modalDialog.style.display = "none";
|
||||||
|
modalDialogButton.onclick = null;
|
||||||
|
}
|
||||||
|
|
||||||
function sendAsync(url,payload, callback) {
|
function sendAsync(url,payload, callback) {
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
request.open('POST', url, true);
|
request.open('POST', url, true);
|
||||||
|
|
@ -275,14 +288,14 @@ const AuthorizationHTML = `
|
||||||
|
|
||||||
cancelButton.onclick = function(){
|
cancelButton.onclick = function(){
|
||||||
sourceWindow.postMessage({id:data.id,result:null,error:{message:"Not Authorized"},type:"cancel"},sourceWindow.location.href);
|
sourceWindow.postMessage({id:data.id,result:null,error:{message:"Not Authorized"},type:"cancel"},sourceWindow.location.href);
|
||||||
window.close();
|
closeWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmButton.onclick = function(){
|
var submitFunc = function(){
|
||||||
if(requireUnlock){
|
if(requireUnlock){
|
||||||
if(password.value == ""){
|
if(password.value == ""){
|
||||||
password.style.border = "2px solid red";
|
password.style.border = "2px solid red";
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
password.style.border = "none";
|
password.style.border = "none";
|
||||||
var params = [transactionInfo.from,password.value,3];
|
var params = [transactionInfo.from,password.value,3];
|
||||||
|
|
@ -293,7 +306,7 @@ const AuthorizationHTML = `
|
||||||
}else{
|
}else{
|
||||||
sendAsync(data.url,data.payload,function(error,result){
|
sendAsync(data.url,data.payload,function(error,result){
|
||||||
sourceWindow.postMessage({id:data.id,result:result,error:error},sourceWindow.location.href);
|
sourceWindow.postMessage({id:data.id,result:result,error:error},sourceWindow.location.href);
|
||||||
window.close();
|
closeWindow();
|
||||||
});
|
});
|
||||||
showWaiting();
|
showWaiting();
|
||||||
}
|
}
|
||||||
|
|
@ -304,14 +317,19 @@ const AuthorizationHTML = `
|
||||||
processMessage(data,sourceWindow);
|
processMessage(data,sourceWindow);
|
||||||
}else{
|
}else{
|
||||||
sourceWindow.postMessage({id:data.id,result:result,error:error},sourceWindow.location.href);
|
sourceWindow.postMessage({id:data.id,result:result,error:error},sourceWindow.location.href);
|
||||||
window.close();
|
closeWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
showWaiting();
|
showWaiting();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form.onsubmit = submitFunc;
|
||||||
|
confirmButton.onclick = submitFunc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function needToAndCanUnlockAccount(address,url,callback){
|
function needToAndCanUnlockAccount(address,url,callback){
|
||||||
|
|
@ -338,8 +356,18 @@ const AuthorizationHTML = `
|
||||||
}else{
|
}else{
|
||||||
firstUrl = event.origin;
|
firstUrl = event.origin;
|
||||||
}
|
}
|
||||||
|
hideMessage();
|
||||||
|
noMessageReceivedYet = false;
|
||||||
var data = event.data;
|
var data = event.data;
|
||||||
|
try{
|
||||||
processMessage(data,event.source);
|
processMessage(data,event.source);
|
||||||
|
}catch(e){
|
||||||
|
event.source.postMessage({id:data.id,result:null,error:{message:"Could not process message data"},type:"notValid"},event.source.location.href);
|
||||||
|
showMessage("Error","The application has sent invalid data", function(){
|
||||||
|
closeWindow();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function processMessage(data, sourceWindow){
|
function processMessage(data, sourceWindow){
|
||||||
|
|
@ -377,7 +405,7 @@ const AuthorizationHTML = `
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
sourceWindow.postMessage({id:data.id,result:null,error:{message:"Need to specify from , to, gas and gasPrice"},type:"notValid"},sourceWindow.location.href);
|
sourceWindow.postMessage({id:data.id,result:null,error:{message:"Need to specify from , to, gas and gasPrice"},type:"notValid"},sourceWindow.location.href);
|
||||||
window.close();
|
closeWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -387,6 +415,20 @@ const AuthorizationHTML = `
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.onbeforeunload = function (event) {
|
||||||
|
if(!closedByCode){
|
||||||
|
source.postMessage({id:data.id,result:null,error:{message:"Not Authorized",type:"cancel"}},source.location.href);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function checkMessageNotReceived(){
|
||||||
|
if(noMessageReceivedYet){
|
||||||
|
showMessage("Error","No transaction received. Please make sure popup are not blocked.", function(){
|
||||||
|
closeWindow();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTimeout(checkMessageNotReceived,1000);
|
||||||
|
|
||||||
window.addEventListener("message", receiveMessage);
|
window.addEventListener("message", receiveMessage);
|
||||||
if(source){
|
if(source){
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue