start on confirm sign tx thing
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Do you want to sign this transaction?</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Do you want to sign this transaction?</h1>
|
||||||
|
|
||||||
|
<h2>Tx Base64</h2>
|
||||||
|
<pre id="tx-base64"></pre>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Tx Decomposed info</h2>
|
||||||
|
<pre id="tx-decomposed"></pre>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<button id="good">Yes</button>
|
||||||
|
<br>
|
||||||
|
<button id="bad">No</button>
|
||||||
|
|
||||||
|
<script type="module" src="../dist/tx_confirm.js"></script>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
/**
|
||||||
|
* Page script for "confirm sign message" popup window
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
main();
|
||||||
|
|
||||||
|
|
||||||
|
async function
|
||||||
|
main
|
||||||
|
()
|
||||||
|
: Promise<void>
|
||||||
|
{
|
||||||
|
console.log('msg_confirm main');
|
||||||
|
|
||||||
|
let result : '' | 'good' | 'bad'
|
||||||
|
= '';
|
||||||
|
|
||||||
|
document.getElementById('good')!.onclick
|
||||||
|
= function() {
|
||||||
|
console.log('click good');
|
||||||
|
result = 'good';
|
||||||
|
};
|
||||||
|
document.getElementById('bad')!.onclick
|
||||||
|
= function() {
|
||||||
|
console.log('click bad');
|
||||||
|
result = 'bad';
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
type bg_msg
|
||||||
|
= {msg_str : string};
|
||||||
|
|
||||||
|
async function listener
|
||||||
|
(msg : bg_msg,
|
||||||
|
_sender : any,
|
||||||
|
_sendResponse : any)
|
||||||
|
: Promise<'good' | 'bad'>
|
||||||
|
{
|
||||||
|
console.log('listener triggered', msg);
|
||||||
|
console.log('msg_str:', msg.msg_str);
|
||||||
|
document.getElementById('message')!.innerHTML = msg.msg_str;
|
||||||
|
|
||||||
|
// every 5 ms check
|
||||||
|
// timeout of 10 minutes = 10*60 secs * 20 iterations =
|
||||||
|
// number of iters in a full second
|
||||||
|
let ITERS = 1;
|
||||||
|
let SEC = 200*ITERS;
|
||||||
|
let MIN = 60*SEC;
|
||||||
|
//let n_max = 10*MIN;
|
||||||
|
let n = 1;
|
||||||
|
let n_max = 30*SEC;
|
||||||
|
|
||||||
|
while
|
||||||
|
(result === '') {
|
||||||
|
// if haven't timed out yet
|
||||||
|
if (n <= n_max) {
|
||||||
|
await sleep(5);
|
||||||
|
n = n + 1;
|
||||||
|
}
|
||||||
|
// if timed out
|
||||||
|
else {
|
||||||
|
result = 'bad';
|
||||||
|
// this break is implied but you're not smart enough to figure
|
||||||
|
// that out yourself
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// send result back
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add listener
|
||||||
|
browser.runtime.onMessage.addListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hack from stack overflow somewhere to sleep for the given number of ms
|
||||||
|
*/
|
||||||
|
async function
|
||||||
|
sleep
|
||||||
|
(ms: number)
|
||||||
|
: Promise<void>
|
||||||
|
{
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user