From fe011321a4b65bc0736634ee2a4d9c7bf0618351 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 2 Nov 2022 13:40:03 +0100 Subject: wallet-core: compute residual amount for recoup properly --- packages/taler-wallet-core/src/operations/recoup.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/recoup.ts') diff --git a/packages/taler-wallet-core/src/operations/recoup.ts b/packages/taler-wallet-core/src/operations/recoup.ts index f16225295..c2df6115b 100644 --- a/packages/taler-wallet-core/src/operations/recoup.ts +++ b/packages/taler-wallet-core/src/operations/recoup.ts @@ -279,11 +279,21 @@ async function recoupRefreshCoin( checkDbInvariant(!!oldCoinDenom); checkDbInvariant(!!revokedCoinDenom); revokedCoin.status = CoinStatus.Dormant; - recoupGroup.scheduleRefreshCoins.push({ - coinPub: oldCoin.coinPub, - //amount: Amounts.sub(oldCoinDenom.value, revokedCoinDenom.value).amount, - amount: revokedCoinDenom.value, - }); + if (!revokedCoin.spendAllocation) { + // We don't know what happened to this coin + logger.error( + `can't refresh-recoup coin ${revokedCoin.coinPub}, no spendAllocation known`, + ); + } else { + let residualAmount = Amounts.sub( + revokedCoinDenom.value, + revokedCoin.spendAllocation.amount, + ).amount; + recoupGroup.scheduleRefreshCoins.push({ + coinPub: oldCoin.coinPub, + amount: residualAmount, + }); + } await tx.coins.put(revokedCoin); await tx.coins.put(oldCoin); await putGroupAsFinished(ws, tx, recoupGroup, coinIdx); -- cgit v1.2.3