implement mint removal

This commit is contained in:
lemonknowsall committed 2025-10-15 23:12:01 -07:00
1 parent 73c68f2655
commit 77803dda38
4 files changed
+118 -30

No files matched your search

+19 -14
View File
@@ -38,6 +38,7 @@ export interface UseCashuReturn {
// Utility functions
clearError: () => void;
getEncodedToken: typeof getEncodedToken;
refreshMints: () => Promise<void>;
}
export function useCashu(): UseCashuReturn {
@@ -64,6 +65,22 @@ export function useCashu(): UseCashuReturn {
return bip39.generateMnemonic(wordlist);
}, []);
const refreshMints = useCallback(async () => {
const coco = cocoRef.current;
if (!coco) return;
try {
const mintList = await coco.mint.getAllMints();
setMints(mintList.map((m: any) => ({
url: m.mintUrl,
name: m.name,
info: m.mintInfo
})));
} catch (err) {
console.error('Failed to refresh mints:', err);
}
}, []);
const setMnemonic = useCallback((newMnemonic: string) => {
if (!bip39.validateMnemonic(newMnemonic, wordlist)) {
throw new Error('Invalid mnemonic');
@@ -184,19 +201,6 @@ export function useCashu(): UseCashuReturn {
}
};
const refreshMints = async () => {
try {
const mintList = await coco.mint.getAllMints();
setMints(mintList.map((m: any) => ({
url: m.mintUrl,
name: m.name,
info: m.mintInfo
})));
} catch (err) {
// Silent failure - errors are handled by the manager
}
};
// Initial load
refreshBalances();
refreshMints();
@@ -212,7 +216,7 @@ export function useCashu(): UseCashuReturn {
];
return () => unsubs.forEach(unsub => unsub());
}, [isInitialized]);
}, [isInitialized, refreshMints]);
// Calculate total balance
const totalBalance = Object.values(balances).reduce((sum, balance) => sum + balance, 0);
@@ -242,5 +246,6 @@ export function useCashu(): UseCashuReturn {
// Utility functions
clearError,
getEncodedToken,
refreshMints,
};
}