From 7af7aee47c74ff7cc2900ab13f6952c637a1a6ad Mon Sep 17 00:00:00 2001 From: lemonknowsall Date: Sun, 12 Oct 2025 14:07:59 -0700 Subject: [PATCH] history event listeners to update transactions live --- src/components/CashuWallet.tsx | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/components/CashuWallet.tsx b/src/components/CashuWallet.tsx index 2751be3..d83b3c5 100644 --- a/src/components/CashuWallet.tsx +++ b/src/components/CashuWallet.tsx @@ -560,6 +560,44 @@ export function CashuWallet() { } }, [isInitialized, historyEntries.length, loadHistory]); + // Auto-refresh transaction history on new transactions + useEffect(() => { + if (!isInitialized) return; + + console.log('📜 Setting up history auto-refresh listeners...'); + + // Listen for history updates (fires on send, receive transactions) + const unsubscribeHistoryUpdated = on('history:updated', () => { + console.log('📜 History updated event, refreshing...'); + loadHistory(); + }); + + // Listen for melt quote creation (coco-cashu bug: doesn't emit history:updated) + const unsubscribeMeltCreated = on('melt-quote:created', () => { + console.log('📜 Melt quote created, refreshing history...'); + loadHistory(); + }); + + // Listen for melt quote paid (backup, in case creation event missed) + const unsubscribeMeltPaid = on('melt-quote:paid', () => { + console.log('📜 Melt quote paid, refreshing history...'); + loadHistory(); + }); + + // Listen for mint quote REDEEMED (only after invoice is paid, not created) + const unsubscribeMintRedeemed = on('mint-quote:redeemed', () => { + console.log('📜 Mint quote redeemed (invoice paid), refreshing history...'); + loadHistory(); + }); + + return () => { + unsubscribeHistoryUpdated(); + unsubscribeMeltCreated(); + unsubscribeMeltPaid(); + unsubscribeMintRedeemed(); + }; + }, [isInitialized, on, loadHistory]); + // Cleanup mint quote listener on component unmount useEffect(() => { return () => {