From 267905b5e7b064c30d6a837dd2eb8b4dc095facf Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Thu, 8 Sep 2022 21:21:39 -0700 Subject: [PATCH] Reduce confusion --- BTCPayServer/Views/Shared/PayButton/PayButton.cshtml | 2 +- BTCPayServer/Views/UIInvoice/ListInvoices.cshtml | 2 +- BTCPayServer/wwwroot/crowdfund/app.js | 3 +-- BTCPayServer/wwwroot/modal/btcpay.js | 11 +++++++++-- BTCPayServer/wwwroot/payment-request/app.js | 3 +-- BTCPayServer/wwwroot/shopify/btcpay-shopify.js | 3 +-- BTCPayServer/wwwroot/tests/index.html | 2 +- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/BTCPayServer/Views/Shared/PayButton/PayButton.cshtml b/BTCPayServer/Views/Shared/PayButton/PayButton.cshtml index e54a5d1b9..4dd081d1e 100644 --- a/BTCPayServer/Views/Shared/PayButton/PayButton.cshtml +++ b/BTCPayServer/Views/Shared/PayButton/PayButton.cshtml @@ -32,7 +32,7 @@ var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200 && this.responseText) { - window.btcpay.showInvoice(JSON.parse(this.responseText).invoiceId); + window.btcpay.appendInvoiceFrame(JSON.parse(this.responseText).invoiceId); } }; xhttp.open('POST', event.target.getAttribute('action'), true); diff --git a/BTCPayServer/Views/UIInvoice/ListInvoices.cshtml b/BTCPayServer/Views/UIInvoice/ListInvoices.cshtml index e7f8a718f..c8da2c4ec 100644 --- a/BTCPayServer/Views/UIInvoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/UIInvoice/ListInvoices.cshtml @@ -51,7 +51,7 @@ delegate('click', '.showInvoice', e => { e.preventDefault(); const { invoiceId } = e.target.dataset; - btcpay.showInvoice(invoiceId); + btcpay.appendInvoiceFrame(invoiceId); }) $('#btnCustomRangeDate').on('click', function (sender) { diff --git a/BTCPayServer/wwwroot/crowdfund/app.js b/BTCPayServer/wwwroot/crowdfund/app.js index 31a0e7cdd..b5be5891b 100644 --- a/BTCPayServer/wwwroot/crowdfund/app.js +++ b/BTCPayServer/wwwroot/crowdfund/app.js @@ -219,8 +219,7 @@ document.addEventListener("DOMContentLoaded",function (ev) { this.sound = this.srvModel.soundsEnabled; this.animation = this.srvModel.animationsEnabled; eventAggregator.$on("invoice-created", function (invoiceId) { - btcpay.showInvoice(invoiceId); - btcpay.showFrame(); + btcpay.appendAndShowInvoiceFrame(invoiceId); self.contributeModalOpen = false; self.setLoading(false); diff --git a/BTCPayServer/wwwroot/modal/btcpay.js b/BTCPayServer/wwwroot/modal/btcpay.js index af9cd8d71..148383f4a 100644 --- a/BTCPayServer/wwwroot/modal/btcpay.js +++ b/BTCPayServer/wwwroot/modal/btcpay.js @@ -105,7 +105,7 @@ onModalReceiveMessageMethod(event); } - function showInvoice(invoiceId, params) { + function appendInvoiceFrame(invoiceId, params) { showingInvoice = true; window.document.body.appendChild(iframe); var invoiceUrl = origin + '/invoice?id=' + invoiceId + '&view=modal'; @@ -115,6 +115,11 @@ iframe.src = invoiceUrl; } + function appendAndShowInvoiceFrame(invoiceId, params) { + appendInvoiceFrame(invoiceId, params); + showFrame(); + } + function setButtonListeners() { var buttons = window.document.querySelectorAll('[data-btcpay-button]'); for (var i = 0; i < buttons.length; i++) { @@ -133,7 +138,9 @@ window.btcpay = { showFrame: showFrame, hideFrame: hideFrame, - showInvoice: showInvoice, + showInvoice: appendInvoiceFrame, + appendInvoiceFrame: appendInvoiceFrame, + appendAndShowInvoiceFrame: appendAndShowInvoiceFrame, onModalWillEnter: onModalWillEnter, onModalWillLeave: onModalWillLeave, setApiUrlPrefix: setApiUrlPrefix, diff --git a/BTCPayServer/wwwroot/payment-request/app.js b/BTCPayServer/wwwroot/payment-request/app.js index 6e113c118..767588140 100644 --- a/BTCPayServer/wwwroot/payment-request/app.js +++ b/BTCPayServer/wwwroot/payment-request/app.js @@ -128,8 +128,7 @@ document.addEventListener("DOMContentLoaded",function (ev) { eventAggregator.$on("invoice-created", function (invoiceId) { self.setLoading(false); - btcpay.showInvoice(invoiceId); - btcpay.showFrame(); + btcpay.appendAndShowInvoiceFrame(invoiceId); }); eventAggregator.$on("invoice-cancelled", function (){ self.setLoading(false); diff --git a/BTCPayServer/wwwroot/shopify/btcpay-shopify.js b/BTCPayServer/wwwroot/shopify/btcpay-shopify.js index d98e0621f..5a2afb58b 100644 --- a/BTCPayServer/wwwroot/shopify/btcpay-shopify.js +++ b/BTCPayServer/wwwroot/shopify/btcpay-shopify.js @@ -132,8 +132,7 @@ window.BTCPayShopifyIntegrationModule = function () { handleInvoiceData(d, {backgroundCheck: true}) }); }); - window.btcpay.showInvoice(currentInvoiceData.invoiceId); - window.btcpay.showFrame(); + btcpay.appendAndShowInvoiceFrame(currentInvoiceData.invoiceId); } } diff --git a/BTCPayServer/wwwroot/tests/index.html b/BTCPayServer/wwwroot/tests/index.html index 064d66883..9db82d381 100644 --- a/BTCPayServer/wwwroot/tests/index.html +++ b/BTCPayServer/wwwroot/tests/index.html @@ -8,7 +8,7 @@ window.onload = function(){ const urlParams = new URLSearchParams(window.location.search); const myParam = urlParams.get('invoice'); - btcpay.showInvoice(myParam); + btcpay.appendInvoiceFrame(myParam); }