From 6afa0bb7f19d939aa12bc9efa52a24a17aed53ea Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Mon, 17 Mar 2025 11:01:11 -0300 Subject: [PATCH] refactor: simplify deletion of expired quote ids expiredQuoteIds --- packages/ditto/controllers/api/cashu.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/ditto/controllers/api/cashu.ts b/packages/ditto/controllers/api/cashu.ts index 9e80bb7f..795a82b2 100644 --- a/packages/ditto/controllers/api/cashu.ts +++ b/packages/ditto/controllers/api/cashu.ts @@ -97,7 +97,12 @@ route.post('/mint/:quote_id', userMiddleware({ enc: 'nip44' }), async (c) => { const now = nostrNow(); try { - if (mintUrl && (expiration > now) && (quote_id === decryptedQuoteId)) { // TODO: organize order of operations of deleting expired quote ids + if (mintUrl && (quote_id === decryptedQuoteId)) { + if (expiration <= now) { + expiredQuoteIds.push(event.id); + continue; + } + const mint = new CashuMint(mintUrl); const wallet = new CashuWallet(mint); await wallet.loadMint(); @@ -131,7 +136,6 @@ route.post('/mint/:quote_id', userMiddleware({ enc: 'nip44' }), async (c) => { ), }, c); - expiredQuoteIds.push(event.id); await deleteExpiredQuotes(expiredQuoteIds); return c.json({ success: 'Minting successful!', state: MintQuoteState.ISSUED }, 200); @@ -145,8 +149,6 @@ route.post('/mint/:quote_id', userMiddleware({ enc: 'nip44' }), async (c) => { logi({ level: 'error', ns: 'ditto.api.cashu.mint', error: errorJson(e) }); return c.json({ error: 'Server error' }, 500); } - - expiredQuoteIds.push(event.id); } await deleteExpiredQuotes(expiredQuoteIds);