mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 00:37:23 +00:00
addMintQuote addition
This commit is contained in:
1 parent
579cd3584b
commit
ec465d9892
2 files changed
+49
-32
No files matched your search
@@ -31,6 +31,7 @@ export function CashuWallet() {
|
|||||||
createMeltQuote,
|
createMeltQuote,
|
||||||
payMeltQuote,
|
payMeltQuote,
|
||||||
redeemMintQuote,
|
redeemMintQuote,
|
||||||
|
addMintQuote,
|
||||||
refreshBalances,
|
refreshBalances,
|
||||||
refreshMints,
|
refreshMints,
|
||||||
checkAndRedeemPendingQuotes,
|
checkAndRedeemPendingQuotes,
|
||||||
@@ -505,7 +506,6 @@ export function CashuWallet() {
|
|||||||
mint_url: quote.mintUrl,
|
mint_url: quote.mintUrl,
|
||||||
amount: quote.amount,
|
amount: quote.amount,
|
||||||
state: quote.state,
|
state: quote.state,
|
||||||
request: quote.request?.substring(0, 50) + '...'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add mint if not already added
|
// Add mint if not already added
|
||||||
@@ -515,37 +515,15 @@ export function CashuWallet() {
|
|||||||
await addMint(quote.mintUrl);
|
await addMint(quote.mintUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the mint's API directly since this is an external quote
|
// Use coco-cashu's addMintQuote API instead of calling mint directly
|
||||||
console.log('🔄 Redeeming npubx.cash quote via mint API:', quote.quoteId, 'from mint:', quote.mintUrl);
|
console.log('🔄 Adding mint quote to coco-cashu:', quote.quoteId);
|
||||||
console.log('🔄 Lightning invoice:', quote.request);
|
await addMintQuote(quote.mintUrl, quote.quoteId);
|
||||||
|
|
||||||
// Try the /mint endpoint for quote redemption
|
console.log('✅ Quote added to coco-cashu successfully');
|
||||||
const response = await fetch(`${quote.mintUrl}/mint`, {
|
console.log('💡 Coco will automatically redeem when mint processor runs');
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
// Trigger the mint processor to check and redeem the quote
|
||||||
'Content-Type': 'application/json',
|
await checkAndRedeemPendingQuotes();
|
||||||
},
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Refresh quotes and balances
|
// Refresh quotes and balances
|
||||||
await fetchQuotes();
|
await fetchQuotes();
|
||||||
@@ -557,7 +535,6 @@ export function CashuWallet() {
|
|||||||
alert(`Failed to claim: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
alert(`Failed to claim: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleShowDenominations = async (mintUrl: string) => {
|
const handleShowDenominations = async (mintUrl: string) => {
|
||||||
try {
|
try {
|
||||||
console.log('🔍 Getting token denominations for mint:', mintUrl);
|
console.log('🔍 Getting token denominations for mint:', mintUrl);
|
||||||
|
|||||||
@@ -85,6 +85,9 @@ export interface CashuActions {
|
|||||||
refreshMints: () => Promise<void>;
|
refreshMints: () => Promise<void>;
|
||||||
checkAndRedeemPendingQuotes: () => Promise<void>;
|
checkAndRedeemPendingQuotes: () => Promise<void>;
|
||||||
clearError: () => 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;
|
export type UseCashuReturn = CashuState & CashuActions;
|
||||||
@@ -581,6 +584,42 @@ export function useCashu(): UseCashuReturn {
|
|||||||
}
|
}
|
||||||
}, [refreshBalances]);
|
}, [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> => {
|
const createMeltQuote = useCallback(async (mintUrl: string, invoice: string): Promise<CashuMeltQuote> => {
|
||||||
if (!managerRef.current) throw new Error('Wallet not initialized');
|
if (!managerRef.current) throw new Error('Wallet not initialized');
|
||||||
|
|
||||||
@@ -692,5 +731,6 @@ export function useCashu(): UseCashuReturn {
|
|||||||
refreshMints,
|
refreshMints,
|
||||||
checkAndRedeemPendingQuotes,
|
checkAndRedeemPendingQuotes,
|
||||||
clearError,
|
clearError,
|
||||||
|
addMintQuote,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user