Skip to content

Commit e1797f8

Browse files
committed
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.
1 parent d671f4d commit e1797f8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/components/modals/MoonpayModal.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ export default defineComponent({
101101
102102
const widgetReady = ref(false);
103103
104+
let widget: any;
105+
104106
onMounted(async () => {
105107
await loadScript('MoonPayWebSdk', 'https://static.moonpay.com/web-sdk/v1/moonpay-web-sdk.min.js');
106108
107-
const widget = window.MoonPayWebSdk.init({
109+
widget = window.MoonPayWebSdk.init({
108110
debug: config.environment !== ENV_MAIN,
109111
flow: props.flow,
110112
environment: config.environment === ENV_MAIN ? 'production' : 'sandbox',
@@ -156,10 +158,10 @@ export default defineComponent({
156158
157159
widget.show();
158160
widgetReady.value = true;
159-
160-
onBeforeUnmount(() => widget.close());
161161
});
162162
163+
onBeforeUnmount(() => widget && widget.close());
164+
163165
async function sendBitcoin(properties: InitiateDepositProperties) {
164166
try {
165167
const value = parseInt(properties.cryptoCurrencyAmountSmallestDenomination, 10);

0 commit comments

Comments
 (0)