history event listeners to update transactions live

This commit is contained in:
lemonknowsall committed 2025-10-12 14:07:59 -07:00
1 parent 2569f0dd0d
commit 7af7aee47c
1 file changed
+38
+38
View File
@@ -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 () => {