From 7d87fd626f856661873f159f7fe9c25eba9a0f5c Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 2 Oct 2023 08:20:45 -0600 Subject: [PATCH] start on confirm sign tx thing --- jrx/pages/tx_confirm.html | 25 +++++++++++ jrx/src/tx_confirm.ts | 89 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 jrx/pages/tx_confirm.html create mode 100644 jrx/src/tx_confirm.ts diff --git a/jrx/pages/tx_confirm.html b/jrx/pages/tx_confirm.html new file mode 100644 index 0000000..26f9ec5 --- /dev/null +++ b/jrx/pages/tx_confirm.html @@ -0,0 +1,25 @@ + + + + + Do you want to sign this transaction? + + +

Do you want to sign this transaction?

+ +

Tx Base64

+

+
+
+

Tx Decomposed info

+

+
+
+ +
+ + + + + + diff --git a/jrx/src/tx_confirm.ts b/jrx/src/tx_confirm.ts new file mode 100644 index 0000000..d5723d3 --- /dev/null +++ b/jrx/src/tx_confirm.ts @@ -0,0 +1,89 @@ +/** + * Page script for "confirm sign message" popup window + */ + + +main(); + + +async function +main + () + : Promise +{ + 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 +{ + return new Promise(resolve => setTimeout(resolve, ms)); +}