aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-03-28 23:21:49 +0200
committerFlorian Dold <florian@dold.me>2022-03-28 23:21:49 +0200
commit80e43db2cac84e588c2ef3889e8d90b76bd53714 (patch)
tree04297a4ad1838f9c1add039d64ee1b1996cfd6b2 /packages/taler-util
parentc194bd539a9e01d083b953ef1e0022da90574339 (diff)
wallet: timeout handling refactoring WIP
Diffstat (limited to 'packages/taler-util')
-rw-r--r--packages/taler-util/src/amounts.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/packages/taler-util/src/amounts.ts b/packages/taler-util/src/amounts.ts
index 505a68f46..98cd4ad62 100644
--- a/packages/taler-util/src/amounts.ts
+++ b/packages/taler-util/src/amounts.ts
@@ -129,6 +129,17 @@ export class Amounts {
return Amounts.add(jsonAmounts[0], ...jsonAmounts.slice(1));
}
+ static sumOrZero(currency: string, amounts: AmountLike[]): Result {
+ if (amounts.length <= 0) {
+ return {
+ amount: Amounts.getZero(currency),
+ saturated: false,
+ };
+ }
+ const jsonAmounts = amounts.map((x) => Amounts.jsonifyAmount(x));
+ return Amounts.add(jsonAmounts[0], ...jsonAmounts.slice(1));
+ }
+
/**
* Add two amounts. Return the result and whether
* the addition overflowed. The overflow is always handled