diff options
author | Florian Dold <florian@dold.me> | 2022-03-28 23:21:49 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-03-28 23:21:49 +0200 |
commit | 80e43db2cac84e588c2ef3889e8d90b76bd53714 (patch) | |
tree | 04297a4ad1838f9c1add039d64ee1b1996cfd6b2 /packages/taler-util | |
parent | c194bd539a9e01d083b953ef1e0022da90574339 (diff) |
wallet: timeout handling refactoring WIP
Diffstat (limited to 'packages/taler-util')
-rw-r--r-- | packages/taler-util/src/amounts.ts | 11 |
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 |