addMintQuote addition

This commit is contained in:
lemonknowsall committed 2025-10-07 21:35:07 -07:00
1 parent 579cd3584b
commit ec465d9892
2 files changed
+49 -32

No files matched your search

+9 -32
View File
@@ -31,6 +31,7 @@ export function CashuWallet() {
createMeltQuote,
payMeltQuote,
redeemMintQuote,
addMintQuote,
refreshBalances,
refreshMints,
checkAndRedeemPendingQuotes,
@@ -505,7 +506,6 @@ export function CashuWallet() {
mint_url: quote.mintUrl,
amount: quote.amount,
state: quote.state,
request: quote.request?.substring(0, 50) + '...'
});
// Add mint if not already added
@@ -515,37 +515,15 @@ export function CashuWallet() {
await addMint(quote.mintUrl);
}
// Call the mint's API directly since this is an external quote
console.log('🔄 Redeeming npubx.cash quote via mint API:', quote.quoteId, 'from mint:', quote.mintUrl);
console.log('🔄 Lightning invoice:', quote.request);
// Use coco-cashu's addMintQuote API instead of calling mint directly
console.log('🔄 Adding mint quote to coco-cashu:', quote.quoteId);
await addMintQuote(quote.mintUrl, quote.quoteId);
// Try the /mint endpoint for quote redemption
const response = await fetch(`${quote.mintUrl}/mint`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
quote: quote.quoteId, // Use the quote ID to redeem
}),
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({ message: 'Failed to redeem quote' }));
throw new Error(errorData.message || `Mint API error: ${response.status}`);
}
const data = await response.json();
console.log('✅ Mint API response:', data);
if (data.paid && data.proofs) {
// We received tokens, now we need to add them to our wallet
console.log('🔄 Adding received tokens to wallet...');
await receive(JSON.stringify(data.proofs));
console.log('✅ Successfully claimed tokens from npubx.cash quote');
} else {
throw new Error('No tokens received from mint');
}
console.log('✅ Quote added to coco-cashu successfully');
console.log('💡 Coco will automatically redeem when mint processor runs');
// Trigger the mint processor to check and redeem the quote
await checkAndRedeemPendingQuotes();
// Refresh quotes and balances
await fetchQuotes();
@@ -557,7 +535,6 @@ export function CashuWallet() {
alert(`Failed to claim: ${err instanceof Error ? err.message : 'Unknown error'}`);
}
};
const handleShowDenominations = async (mintUrl: string) => {
try {
console.log('🔍 Getting token denominations for mint:', mintUrl);