From cf4d888ad58839ed6c5f692d740ef3f2df5b8b09 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Tue, 25 Feb 2025 16:20:40 -0300 Subject: [PATCH] fix: total balance can be equal to the amount, access undefined with ? --- packages/ditto/controllers/api/cashu.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ditto/controllers/api/cashu.ts b/packages/ditto/controllers/api/cashu.ts index 5effd45c..249c5b60 100644 --- a/packages/ditto/controllers/api/cashu.ts +++ b/packages/ditto/controllers/api/cashu.ts @@ -348,7 +348,7 @@ route.post('/nutzap', userMiddleware({ enc: 'nip44' }), async (c) => { let selectedMint: string | undefined; for (const mint of recipientMints) { - if (organizedProofs[mint].totalBalance > amount) { + if (organizedProofs[mint]?.totalBalance >= amount) { selectedMint = mint; let minimumRequiredBalance = 0; @@ -357,7 +357,7 @@ route.post('/nutzap', userMiddleware({ enc: 'nip44' }), async (c) => { continue; } - if (minimumRequiredBalance > amount) { + if (minimumRequiredBalance >= amount) { break; }