From adebfab94e76ee5d34a4f22d15fc085daef9ae00 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 25 Dec 2019 19:11:20 +0100 Subject: fix and simplify coin selection --- src/util/amounts.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/util') 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. */ -- cgit v1.2.3