mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 08:23:35 +00:00
addMintQuote addition
This commit is contained in:
1 parent
579cd3584b
commit
ec465d9892
2 files changed
+49
-32
No files matched your search
@@ -85,6 +85,9 @@ export interface CashuActions {
|
||||
refreshMints: () => Promise<void>;
|
||||
checkAndRedeemPendingQuotes: () => Promise<void>;
|
||||
clearError: () => void;
|
||||
|
||||
// Add mint quote (for external quotes like from npubx.cash)
|
||||
addMintQuote: (mintUrl: string, quoteId: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export type UseCashuReturn = CashuState & CashuActions;
|
||||
@@ -581,6 +584,42 @@ export function useCashu(): UseCashuReturn {
|
||||
}
|
||||
}, [refreshBalances]);
|
||||
|
||||
// Add this implementation in the useCashu function
|
||||
const addMintQuote = useCallback(async (mintUrl: string, quoteId: string) => {
|
||||
if (!managerRef.current || !repositoriesRef.current) throw new Error('Wallet not initialized');
|
||||
|
||||
try {
|
||||
setError(null);
|
||||
console.log('📝 Adding mint quote to repository:', { mintUrl, quoteId });
|
||||
|
||||
// Access the mint quote repository
|
||||
const mintQuoteRepo = (repositoriesRef.current as {
|
||||
mintQuoteRepository?: {
|
||||
addMintQuote: (quote: { quote: string; mintUrl: string; state: string }) => Promise<void>
|
||||
}
|
||||
})?.mintQuoteRepository;
|
||||
|
||||
if (!mintQuoteRepo) {
|
||||
throw new Error('Mint quote repository not available');
|
||||
}
|
||||
|
||||
// Add the quote to the repository with UNPAID state
|
||||
// The mint processor will check and redeem it
|
||||
await mintQuoteRepo.addMintQuote({
|
||||
quote: quoteId,
|
||||
mintUrl: mintUrl,
|
||||
state: 'UNPAID', // Mark as UNPAID so coco will check it
|
||||
});
|
||||
|
||||
console.log('✅ Mint quote added to repository successfully');
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : 'Failed to add mint quote';
|
||||
console.error('❌ Error adding mint quote:', err);
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const createMeltQuote = useCallback(async (mintUrl: string, invoice: string): Promise<CashuMeltQuote> => {
|
||||
if (!managerRef.current) throw new Error('Wallet not initialized');
|
||||
|
||||
@@ -692,5 +731,6 @@ export function useCashu(): UseCashuReturn {
|
||||
refreshMints,
|
||||
checkAndRedeemPendingQuotes,
|
||||
clearError,
|
||||
addMintQuote,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user