From e1797f84b58f401cb5a0f3a2437ab4fedcd12350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Wed, 5 Jul 2023 10:10:19 +0200 Subject: [PATCH] Fix Vue error in MoonpayModal Calling onBeforeUnmount is not allowed outside the setup() function, and because onMount has an async callback, that callback is outside the setup() function. --- src/components/modals/MoonpayModal.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/modals/MoonpayModal.vue b/src/components/modals/MoonpayModal.vue index cb3e163be..89452c56f 100644 --- a/src/components/modals/MoonpayModal.vue +++ b/src/components/modals/MoonpayModal.vue @@ -101,10 +101,12 @@ export default defineComponent({ const widgetReady = ref(false); + let widget: any; + onMounted(async () => { await loadScript('MoonPayWebSdk', 'https://static.moonpay.com/web-sdk/v1/moonpay-web-sdk.min.js'); - const widget = window.MoonPayWebSdk.init({ + widget = window.MoonPayWebSdk.init({ debug: config.environment !== ENV_MAIN, flow: props.flow, environment: config.environment === ENV_MAIN ? 'production' : 'sandbox', @@ -156,10 +158,10 @@ export default defineComponent({ widget.show(); widgetReady.value = true; - - onBeforeUnmount(() => widget.close()); }); + onBeforeUnmount(() => widget && widget.close()); + async function sendBitcoin(properties: InitiateDepositProperties) { try { const value = parseInt(properties.cryptoCurrencyAmountSmallestDenomination, 10);