aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-12-25 19:11:20 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-12-25 19:11:20 +0100
commitadebfab94e76ee5d34a4f22d15fc085daef9ae00 (patch)
tree2dd0f233661fc32d2e5c2ee83750b3616d421359 /src/util
parent54f7999c63292ca63f5f584c49bdef0b55627d71 (diff)
fix and simplify coin selection
Diffstat (limited to 'src/util')
-rw-r--r--src/util/amounts.ts6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/util/amounts.ts b/src/util/amounts.ts
index c85c4839a..8deeaeccc 100644
--- a/src/util/amounts.ts
+++ b/src/util/amounts.ts
@@ -184,7 +184,7 @@ export function sub(a: AmountJson, ...rest: AmountJson[]): Result {
* Compare two amounts. Returns 0 when equal, -1 when a < b
* and +1 when a > b. Throws when currencies don't match.
*/
-export function cmp(a: AmountJson, b: AmountJson): number {
+export function cmp(a: AmountJson, b: AmountJson): -1 | 0 | 1 {
if (a.currency !== b.currency) {
throw Error(`Mismatched currency: ${a.currency} and ${b.currency}`);
}
@@ -244,6 +244,10 @@ export function isNonZero(a: AmountJson): boolean {
return a.value > 0 || a.fraction > 0;
}
+export function isZero(a: AmountJson): boolean {
+ return a.value === 0 && a.fraction === 0;
+}
+
/**
* Parse an amount like 'EUR:20.5' for 20 Euros and 50 ct.
*/