modals and mint removal

This commit is contained in:
lemonknowsall committed 2025-10-09 21:19:02 -07:00
1 parent 22d3675f2b
commit a8faa03b49
4 files changed
+368 -165

No files matched your search

+37 -1
View File
@@ -17,7 +17,7 @@ export function useCashuBalances(manager: unknown | null): UseCashuBalancesRetur
// Throttling refs
const lastRefreshTimeRef = useRef<number>(0);
const isRefreshingRef = useRef<boolean>(false);
const REFRESH_THROTTLE_MS = 500;
const REFRESH_THROTTLE_MS = 200;
const refreshBalances = useCallback(async () => {
if (!manager) return;
@@ -102,10 +102,46 @@ export function useCashuBalances(manager: unknown | null): UseCashuBalancesRetur
refreshBalances();
});
const unsubscribeSendCreated = (manager as { on: (event: string, handler: (payload: unknown) => void | Promise<void>) => () => void }).on('send:created', () => {
console.log('📤 Send created, refreshing balances...');
// Bypass throttling for send operations to ensure immediate balance update
setTimeout(async () => {
if (!manager) return;
try {
console.log('🔄 send:created: Getting balances from wallet...');
const newBalances = await (manager as { wallet: { getBalances: () => Promise<CashuBalance> } }).wallet.getBalances();
console.log('💰 send:created: Raw balances from wallet:', newBalances);
setBalances(prevBalances => {
const hasChanged =
Object.keys(newBalances).length !== Object.keys(prevBalances).length ||
Object.keys(newBalances).some(key => newBalances[key] !== prevBalances[key]);
if (hasChanged) {
console.log('✅ send:created: Balances changed, updating state:', Object.keys(newBalances).length, 'mints');
return newBalances;
} else {
console.log('⏭️ send:created: Balances unchanged, skipping state update');
return prevBalances;
}
});
} catch (err) {
console.error('❌ send:created: Failed to refresh balances:', err);
}
}, 100);
});
const unsubscribeReceiveCreated = (manager as { on: (event: string, handler: (payload: unknown) => void | Promise<void>) => () => void }).on('receive:created', () => {
console.log('📥 Receive created, refreshing balances...');
refreshBalances();
});
return () => {
unsubscribeProofsSaved();
unsubscribeProofsStateChanged();
unsubscribeMintQuoteRedeemed();
unsubscribeSendCreated();
unsubscribeReceiveCreated();
};
}, [manager, refreshBalances]);
+27 -7
View File
@@ -78,13 +78,33 @@ export function useCashuMints(manager: unknown | null): UseCashuMintsReturn {
}
}, [manager]);
const removeMint = useCallback(async (_mintUrl: string) => {
// Note: coco-cashu doesn't have a direct remove mint method
// This would need to be implemented at the repository level
const error = new CashuWalletError('Remove mint functionality not yet implemented', 'REMOVE_MINT_NOT_IMPLEMENTED');
setError(error);
throw error;
}, []);
const removeMint = useCallback(async (mintUrl: string) => {
if (!manager) throw new CashuWalletError('Wallet not initialized', 'WALLET_NOT_INITIALIZED');
try {
setIsLoading(true);
setError(null);
// Access the mintService directly through the manager to use deleteMint
// The manager has a private mintService property that we can access
const mintService = (manager as any).mintService;
if (!mintService || typeof mintService.deleteMint !== 'function') {
throw new CashuWalletError('Mint service not available', 'MINT_SERVICE_ERROR');
}
await mintService.deleteMint(mintUrl);
// No need to manually refresh - events will handle it automatically
console.log('✅ Mint removed successfully:', mintUrl);
} catch (err) {
const errorMessage = err instanceof Error ? err.message : 'Failed to remove mint';
const cashuError = new CashuWalletError(errorMessage, 'REMOVE_MINT_ERROR', { mintUrl, originalError: err });
setError(cashuError);
throw cashuError;
} finally {
setIsLoading(false);
}
}, [manager]);
// Set up event listeners for automatic mint updates using coco events
useEffect(() => {