Fix zap dialog behavior for logged-out users

This commit is contained in:
thePR0M3TH3AN committed 2025-10-19 18:17:16 -04:00
1 parent 4715641b9a
commit 0c211cd411
3 files changed
+70 -5

No files matched your search

+14 -5
View File
@@ -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();
+4
View File
@@ -1054,6 +1054,10 @@ export class VideoModal {
}
async openZapDialog() {
if (this.modalZapRequiresLogin) {
return Promise.resolve(false);
}
if (this.modalZapOpenPromise) {
return this.modalZapOpenPromise;
}
+52
View File
@@ -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 = [];