From 0e7a0741c67ef788523eb26afa36105a49405f68 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 31 Oct 2022 17:18:16 +0100 Subject: -type fixes --- packages/taler-util/src/amounts.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'packages/taler-util/src/amounts.ts') diff --git a/packages/taler-util/src/amounts.ts b/packages/taler-util/src/amounts.ts index 337f342a3..c9a78356e 100644 --- a/packages/taler-util/src/amounts.ts +++ b/packages/taler-util/src/amounts.ts @@ -192,16 +192,18 @@ export class Amounts { * * Throws when currencies don't match. */ - static sub(a: AmountJson, ...rest: AmountJson[]): Result { - const currency = a.currency; - let value = a.value; - let fraction = a.fraction; + static sub(a: AmountLike, ...rest: AmountLike[]): Result { + const aJ = Amounts.jsonifyAmount(a); + const currency = aJ.currency; + let value = aJ.value; + let fraction = aJ.fraction; for (const b of rest) { - if (b.currency.toUpperCase() !== a.currency.toUpperCase()) { - throw Error(`Mismatched currency: ${b.currency} and ${currency}`); + const bJ = Amounts.jsonifyAmount(b); + if (bJ.currency.toUpperCase() !== aJ.currency.toUpperCase()) { + throw Error(`Mismatched currency: ${bJ.currency} and ${currency}`); } - if (fraction < b.fraction) { + if (fraction < bJ.fraction) { if (value < 1) { return { amount: { currency, value: 0, fraction: 0 }, @@ -211,12 +213,12 @@ export class Amounts { value--; fraction += amountFractionalBase; } - console.assert(fraction >= b.fraction); - fraction -= b.fraction; - if (value < b.value) { + console.assert(fraction >= bJ.fraction); + fraction -= bJ.fraction; + if (value < bJ.value) { return { amount: { currency, value: 0, fraction: 0 }, saturated: true }; } - value -= b.value; + value -= bJ.value; } return { amount: { currency, value, fraction }, saturated: false }; -- cgit v1.2.3