From d0c724412bf32f20e51aba0488a240a3054135c1 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Tue, 8 Nov 2022 21:14:54 +0400 Subject: [PATCH] Fix closing payment popup on error --- src/components/popups/paymentCard.ts | 3 ++- src/components/popups/paymentVerification.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/popups/paymentCard.ts b/src/components/popups/paymentCard.ts index 891398bf9..490c61836 100644 --- a/src/components/popups/paymentCard.ts +++ b/src/components/popups/paymentCard.ts @@ -226,7 +226,7 @@ export default class PopupPaymentCard extends PopupElement<{ if(SUPPORTED_NATIVE_PROVIDERS.has(paymentForm.native_provider as PaymentsNativeProvider)) { this.d(); } else { - const iframe = createVerificationIframe(paymentForm.url, (event) => { + const {iframe, onMount} = createVerificationIframe(paymentForm.url, (event) => { if(event.eventType !== 'payment_form_submit') { return; } @@ -257,6 +257,7 @@ export default class PopupPaymentCard extends PopupElement<{ // putPreloader(this.body, true); this.body.append(iframe); this.show(); + onMount(); } } diff --git a/src/components/popups/paymentVerification.ts b/src/components/popups/paymentVerification.ts index d9c649e53..d307b72fc 100644 --- a/src/components/popups/paymentVerification.ts +++ b/src/components/popups/paymentVerification.ts @@ -27,11 +27,12 @@ export function createVerificationIframe(url: string, callback: TelegramWebviewE iframe.classList.add('payment-verification'); iframe.src = url; - iframe.addEventListener('load', () => { - weakMap.set(iframe.contentWindow, callback); - }, {once: true}); - - return iframe; + return { + iframe, + onMount: () => { + weakMap.set(iframe.contentWindow, callback); + } + }; } export default class PopupPaymentVerification extends PopupElement<{ @@ -49,7 +50,7 @@ export default class PopupPaymentVerification extends PopupElement<{ } private d() { - const iframe = createVerificationIframe(this.url, (event) => { + const {iframe, onMount} = createVerificationIframe(this.url, (event) => { if(event.eventType !== 'web_app_open_tg_link') { return; } @@ -63,5 +64,6 @@ export default class PopupPaymentVerification extends PopupElement<{ this.body.append(iframe); this.show(); + onMount(); } }