From 5f670fd166cc931251945227988ae5b56bbdbf4c Mon Sep 17 00:00:00 2001 From: Joe Polny Date: Thu, 13 Jan 2022 03:24:10 +0000 Subject: [PATCH] support showing "popups" in an iframe --- lib/main.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 896cd6c..7d75ce7 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,6 +24,7 @@ const bridge = new Messaging(); * @property {string} [bridgeUrl] Override wallet.myalgo.com default frame url. * @property {number} [timeout] Number of msec to wait the popup response, default value: 1600000 msec. * @property {boolean} [disableLedgerNano] It will disable ledger nano accounts and returns only mnemonic accounts. + * @property {HTMLIFrameElement} [iframe] Render "popups" in this iframe rather than a new window */ /** @@ -248,6 +249,12 @@ class MyAlgoConnect { * @type {boolean} */ this.disableLedgerNano = (options && options.disableLedgerNano) ? options.disableLedgerNano : false; + + /** + * @access private + * @type {HTMLIFrameElement} + */ + this.iframe = options.iframe; } /** @@ -269,7 +276,12 @@ class MyAlgoConnect { } try { - this.currentConnectPopup = openPopup(this.url + "/connect.html"); + if(this.iframe) { + this.iframe.src = this.url + "/connect.html" + this.currentConnectPopup = this.iframe.contentWindow + } else { + this.currentConnectPopup = openPopup(this.url + "/connect.html"); + } await this.waitForWindowToLoad(this.currentConnectPopup); @@ -321,7 +333,12 @@ class MyAlgoConnect { txn = prepareTxn(transaction); try { - this.currentSigntxPopup = openPopup(this.url + "/signtx.html"); + if(this.iframe) { + this.iframe.src = this.url + "/signtx.html" + this.currentSigntxPopup = this.iframe.contentWindow + } else { + this.currentSigntxPopup = openPopup(this.url + "/signtx.html"); + } await this.waitForWindowToLoad(this.currentSigntxPopup); @@ -380,7 +397,13 @@ class MyAlgoConnect { } try { - this.currentSignLogicSigPopup = openPopup(this.url + "/logicsigtx.html"); + if(this.iframe) { + this.iframe.src = this.url + "/logicsigtx.html" + this.currentSignLogicSigPopup = this.iframe.contentWindow + } else { + this.currentSignLogicSigPopup = openPopup(this.url + "/logicsigtx.html"); + } + await this.waitForWindowToLoad(this.currentSignLogicSigPopup); // Send program @@ -439,7 +462,9 @@ class MyAlgoConnect { * @returns {void} */ closeWindow(window) { - if (window && !window.closed && window.close) { + if (this.iframe) { + this.iframe.src = '' + } else if (window && !window.closed && window.close) { window.close(); } }