diff options
author | Florian Dold <florian@dold.me> | 2021-03-15 13:43:53 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-03-15 13:44:25 +0100 |
commit | 44b1896b9ec8af72aa0eb25e8c89a4cc0c841766 (patch) | |
tree | 5a1b60cfd7334a64bb9cf6e465b3d62ee9dacde0 /packages/taler-wallet-core/src/util/amounts.ts | |
parent | fb3da3a28d6ed6a16ca7d0fa8ec775de51c7df6b (diff) | |
download | wallet-core-44b1896b9ec8af72aa0eb25e8c89a4cc0c841766.tar.gz wallet-core-44b1896b9ec8af72aa0eb25e8c89a4cc0c841766.tar.bz2 wallet-core-44b1896b9ec8af72aa0eb25e8c89a4cc0c841766.zip |
improved pay coin selection
support for multiple exchanges and healing a previous selection
Diffstat (limited to 'packages/taler-wallet-core/src/util/amounts.ts')
-rw-r--r-- | packages/taler-wallet-core/src/util/amounts.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/util/amounts.ts b/packages/taler-wallet-core/src/util/amounts.ts index 801c3385e..7a242f41d 100644 --- a/packages/taler-wallet-core/src/util/amounts.ts +++ b/packages/taler-wallet-core/src/util/amounts.ts @@ -381,6 +381,25 @@ function mult(a: AmountJson, n: number): Result { return add(acc, x); } +function max(a: AmountLike, b: AmountLike): AmountJson { + const cr = Amounts.cmp(a, b); + if (cr >= 0) { + return jsonifyAmount(a); + } else { + return jsonifyAmount(b); + } +} + +function min(a: AmountLike, b: AmountLike): AmountJson { + const cr = Amounts.cmp(a, b); + if (cr >= 0) { + return jsonifyAmount(b); + } else { + return jsonifyAmount(a); + } +} + + // Export all amount-related functions here for better IDE experience. export const Amounts = { stringify: stringify, @@ -391,6 +410,8 @@ export const Amounts = { sum: sum, sub: sub, mult: mult, + max: max, + min: min, check: check, getZero: getZero, isZero: isZero, |