From 0c211cd411c3c3ea1155efc8c185e835ec95d780 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Sun, 19 Oct 2025 18:17:16 -0400 Subject: [PATCH] Fix zap dialog behavior for logged-out users --- js/app.js | 19 +++++++++---- js/ui/components/VideoModal.js | 4 +++ tests/video-modal-zap.test.mjs | 52 ++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/js/app.js b/js/app.js index 882cf31f..ad54ecbd 100644 --- a/js/app.js +++ b/js/app.js @@ -692,12 +692,21 @@ class Application { }; this.boundVideoModalZapOpenHandler = (event) => { const requiresLogin = Boolean(event?.detail?.requiresLogin); - if (requiresLogin) { - this.pendingModalZapOpen = true; - } else { - this.pendingModalZapOpen = false; + this.pendingModalZapOpen = requiresLogin; + + const openResult = this.zapController?.open({ requiresLogin }); + if (!openResult) { + if (!requiresLogin) { + this.pendingModalZapOpen = false; + } + this.videoModal?.closeZapDialog?.({ + silent: true, + restoreFocus: false, + }); + return; } - this.zapController?.open({ requiresLogin }); + + this.pendingModalZapOpen = false; }; this.boundVideoModalZapCloseHandler = () => { this.zapController?.close(); diff --git a/js/ui/components/VideoModal.js b/js/ui/components/VideoModal.js index cb3cc0b2..9ced7731 100644 --- a/js/ui/components/VideoModal.js +++ b/js/ui/components/VideoModal.js @@ -1054,6 +1054,10 @@ export class VideoModal { } async openZapDialog() { + if (this.modalZapRequiresLogin) { + return Promise.resolve(false); + } + if (this.modalZapOpenPromise) { return this.modalZapOpenPromise; } diff --git a/tests/video-modal-zap.test.mjs b/tests/video-modal-zap.test.mjs index e97639b6..96e6bcd6 100644 --- a/tests/video-modal-zap.test.mjs +++ b/tests/video-modal-zap.test.mjs @@ -183,9 +183,16 @@ function createVideoModalStub() { setCopyEnabled: noop, setShareEnabled: noop, setZapVisibility: noop, + dialogOpen: false, + closeZapDialogCalls: [], + closeZapDialog(options = {}) { + this.closeZapDialogCalls.push(options); + this.dialogOpen = false; + }, resetStats: noop, updateViewCountLabel: noop, setViewCountPointer: noop, + completedStates: [], addEventListener(type, handler) { listeners.set(type, handler); }, @@ -202,6 +209,9 @@ function createVideoModalStub() { setZapPending(value) { this.setZapPendingCalls.push(Boolean(value)); }, + setZapCompleted(value) { + this.completedStates.push(Boolean(value)); + }, setZapStatus(message, tone) { this.statusMessages.push({ message, tone }); }, @@ -297,6 +307,48 @@ async function createApp({ splitAndZap }) { return { app, modalStub, creatorAddress, platformAddress }; } +await (async () => { + // Test: logged-out zap request closes modal and queues reopen + const { app, modalStub } = await createApp({ + splitAndZap: async () => ({ receipts: [] }), + }); + + let loginNotificationCount = 0; + app.zapController.notifyLoginRequired = () => { + loginNotificationCount += 1; + }; + + modalStub.dialogOpen = true; + modalStub.closeZapDialogCalls = []; + + app.pendingModalZapOpen = false; + + app.boundVideoModalZapOpenHandler({ detail: { requiresLogin: true } }); + + assert.equal( + loginNotificationCount, + 1, + "should request login notification when zapping logged out", + ); + assert.equal( + app.pendingModalZapOpen, + true, + "zap should remain pending for post-login reopen", + ); + assert.equal( + modalStub.closeZapDialogCalls.length, + 1, + "zap dialog should close immediately when login required", + ); + assert.deepEqual(modalStub.closeZapDialogCalls[0], { + silent: true, + restoreFocus: false, + }); + assert.equal(modalStub.dialogOpen, false, "zap dialog should be closed"); + + app.destroy(); +})(); + await (async () => { // Test: wallet required before zapping const splitCalls = [];