aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/refresh.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-09-19 14:41:50 +0200
committerFlorian Dold <florian@dold.me>2022-09-19 14:42:04 +0200
commitffe6a9521400ceabca713c08010532ece03152a8 (patch)
tree4982f8487f1b6c3704ea03be84f61de8f9e9d0f6 /packages/taler-wallet-core/src/operations/refresh.ts
parent97267e7d1fbdab7827fe3a6df2abc9f1a7ba73da (diff)
downloadwallet-core-ffe6a9521400ceabca713c08010532ece03152a8.tar.xz
wallet-core: handle suspended coins properly in refresh
Diffstat (limited to 'packages/taler-wallet-core/src/operations/refresh.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/refresh.ts36
1 files changed, 25 insertions, 11 deletions
diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts
index 9560a3543..55070618f 100644
--- a/packages/taler-wallet-core/src/operations/refresh.ts
+++ b/packages/taler-wallet-core/src/operations/refresh.ts
@@ -67,6 +67,7 @@ import {
EXCHANGE_COINS_LOCK,
InternalWalletState,
} from "../internal-wallet-state.js";
+import { assertUnreachable } from "../util/assertUnreachable.js";
import {
readSuccessResponseJsonOrThrow,
readUnexpectedResponseDetails,
@@ -879,17 +880,30 @@ export async function createRefreshGroup(
!!denom,
"denomination for existing coin must be in database",
);
- if (coin.status !== CoinStatus.Dormant) {
- coin.status = CoinStatus.Dormant;
- const coinAv = await tx.coinAvailability.get([
- coin.exchangeBaseUrl,
- coin.denomPubHash,
- coin.maxAge,
- ]);
- checkDbInvariant(!!coinAv);
- checkDbInvariant(coinAv.freshCoinCount > 0);
- coinAv.freshCoinCount--;
- await tx.coinAvailability.put(coinAv);
+ switch (coin.status) {
+ case CoinStatus.Dormant:
+ break;
+ case CoinStatus.Fresh: {
+ coin.status = CoinStatus.Dormant;
+ const coinAv = await tx.coinAvailability.get([
+ coin.exchangeBaseUrl,
+ coin.denomPubHash,
+ coin.maxAge,
+ ]);
+ checkDbInvariant(!!coinAv);
+ checkDbInvariant(coinAv.freshCoinCount > 0);
+ coinAv.freshCoinCount--;
+ await tx.coinAvailability.put(coinAv);
+ break;
+ }
+ case CoinStatus.FreshSuspended: {
+ // For suspended coins, we don't have to adjust coin
+ // availability, as they are not counted as available.
+ coin.status = CoinStatus.Dormant;
+ break;
+ }
+ default:
+ assertUnreachable(coin.status);
}
const refreshAmount = coin.currentAmount;
inputPerCoin.push(refreshAmount);