diff options
author | Florian Dold <florian@dold.me> | 2022-11-02 13:40:03 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-11-02 13:40:03 +0100 |
commit | fe011321a4b65bc0736634ee2a4d9c7bf0618351 (patch) | |
tree | 5bf2b5b3eff072390c0a857431b1212fd6d134f2 /packages/taler-wallet-core/src/operations/recoup.ts | |
parent | 87bc4a6fcd3b274f25ffe9a74196aa5f4f586b7e (diff) | |
download | wallet-core-fe011321a4b65bc0736634ee2a4d9c7bf0618351.tar.xz |
wallet-core: compute residual amount for recoup properly
Diffstat (limited to 'packages/taler-wallet-core/src/operations/recoup.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/recoup.ts | 20 |
1 files changed, 15 insertions, 5 deletions
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); |