npubxcash lightning address redemption working

This commit is contained in:
lemonknowsall committed 2025-10-15 21:29:39 -07:00
1 parent bd956cef3f
commit f78013b083
2 files changed
+102 -1

No files matched your search

+84
View File
@@ -38,6 +38,7 @@ export function CashuWallet() {
const {
setMint: setNpubCashMint,
getUserInfo: getNpubCashUserInfo,
getAllQuotes,
isLoggedIn: isNpubCashLoggedIn,
isLoading: isNpubCashLoading,
error: npubCashError,
@@ -154,6 +155,87 @@ export function CashuWallet() {
}
}, []);
// ============================================================================
// HELPER FUNCTIONS - Quote Refresh
// ============================================================================
/**
* Refresh quotes from npub.cash and add them to the wallet
* This matches the functionality from main.ts example
*/
const handleRefreshQuotes = useCallback(async () => {
if (!coco || !isNpubCashLoggedIn) return;
try {
// Fetch all quotes from npub.cash
const quotes = await getAllQuotes();
if (quotes.length === 0) {
toast({
title: "No Quotes Found",
description: "No pending quotes found on npub.cash",
});
return;
}
// Group quotes by mint URL
const quotesByMint = quotes.reduce((acc, quote) => {
if (!acc[quote.mintUrl]) {
acc[quote.mintUrl] = [];
}
acc[quote.mintUrl].push(quote);
return acc;
}, {} as Record<string, typeof quotes>);
let addedQuotes = 0;
// Process each mint's quotes
for (const [mintUrl, mintQuotes] of Object.entries(quotesByMint)) {
try {
// Check if mint exists, add if not
const isKnown = await coco.mint.isKnownMint(mintUrl);
if (!isKnown) {
await coco.mint.addMint(mintUrl);
}
// Add quotes to the wallet (matching main.ts format)
coco.quotes.addMintQuote(
mintUrl,
mintQuotes.map((q) => ({
...q,
expiry: q.expiresAt,
quote: q.quoteId,
state: "PAID",
unit: "sat",
})),
);
addedQuotes += mintQuotes.length;
} catch (err) {
console.warn(`Failed to process quotes for mint ${mintUrl}:`, err);
}
}
if (addedQuotes > 0) {
toast({
title: "Quotes Refreshed",
description: `Successfully added ${addedQuotes} quotes from npub.cash`,
});
} else {
toast({
title: "No New Quotes",
description: "All quotes from npub.cash are already processed",
});
}
} catch (err) {
toast({
variant: "destructive",
title: "Refresh Failed",
description: err instanceof Error ? err.message : 'Failed to refresh quotes',
});
}
}, [coco, isNpubCashLoggedIn, getAllQuotes, toast]);
// ============================================================================
// HELPER FUNCTIONS - Mint Management
// ============================================================================
@@ -666,6 +748,8 @@ export function CashuWallet() {
setShowLightningAddressQR(true);
}}
generateQRCode={generateQRCode}
onRefreshQuotes={handleRefreshQuotes}
isRefreshingQuotes={isNpubCashLoading}
/>
{/* ========================================================================