From 89de8a990770b783d9a792cd60ebde50f57f9495 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 27 Feb 2024 01:10:43 +0100 Subject: [PATCH] Fix out of order undos for turbo zaps (#883) Turbo zaps had different toast bodies so they weren't merged together. This gave stackers the option to undo these zaps out of order. When zaps are undone out of order, the client cache can get in a bad state. Using the item id as a tag fixes that such that zaps for the same item will always get merged together. This can be seen as a workaround for hacky zap undo code but I think it's also better UX so maybe we should do this anyway. --- components/item-act.js | 1 + components/toast.js | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/item-act.js b/components/item-act.js index 8047cb0c..a2ccea9b 100644 --- a/components/item-act.js +++ b/components/item-act.js @@ -340,6 +340,7 @@ export function useZap () { let undoUpdate return { flowId, + tag: itemId, type: 'zap', pendingMessage: `zapped ${amount} sats`, onPending: () => diff --git a/components/toast.js b/components/toast.js index d43be0f8..7a48f3ee 100644 --- a/components/toast.js +++ b/components/toast.js @@ -127,13 +127,12 @@ export const ToastProvider = ({ children }) => { // merge toasts with same tag const prevToast = toasts[idx] - let { rawBody, body, amount } = prevToast - rawBody ??= body + let { amount } = prevToast amount = amount ? amount + 1 : 2 - body = `(${amount}) ${rawBody}` + const body = `(${amount}) ${toast.body}` return [ ...toasts.slice(0, idx), - { ...toast, rawBody, amount, body }, + { ...toast, amount, body }, ...toasts.slice(idx + 1) ] }