[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] 01/02: taler-util: amount currency normalization
From: |
gnunet |
Subject: |
[taler-wallet-core] 01/02: taler-util: amount currency normalization |
Date: |
Wed, 01 Dec 2021 18:07:59 +0100 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
commit 2dc876d6d6e766eeeda4efdb2c4e1d0ac19fa524
Author: Florian Dold <florian@dold.me>
AuthorDate: Wed Dec 1 18:07:27 2021 +0100
taler-util: amount currency normalization
---
packages/taler-util/src/amounts.ts | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/packages/taler-util/src/amounts.ts
b/packages/taler-util/src/amounts.ts
index 41fd14be..25b3a2c8 100644
--- a/packages/taler-util/src/amounts.ts
+++ b/packages/taler-util/src/amounts.ts
@@ -151,7 +151,7 @@ export class Amounts {
}
let fraction = first.fraction % amountFractionalBase;
for (const x of rest) {
- if (x.currency !== currency) {
+ if (x.currency.toUpperCase() !== currency.toUpperCase()) {
throw Error(`Mismatched currency: ${x.currency} and ${currency}`);
}
@@ -187,7 +187,7 @@ export class Amounts {
let fraction = a.fraction;
for (const b of rest) {
- if (b.currency !== currency) {
+ if (b.currency.toUpperCase() !== a.currency.toUpperCase()) {
throw Error(`Mismatched currency: ${b.currency} and ${currency}`);
}
if (fraction < b.fraction) {
@@ -299,7 +299,7 @@ export class Amounts {
return undefined;
}
return {
- currency: res[1],
+ currency: res[1].toUpperCase(),
fraction: Math.round(amountFractionalBase * Number.parseFloat(tail)),
value,
};
@@ -403,11 +403,17 @@ export class Amounts {
*/
static stringify(a: AmountLike): string {
a = Amounts.jsonifyAmount(a);
- const s = this.stringifyValue(a)
+ const s = this.stringifyValue(a);
return `${a.currency}:${s}`;
}
+ static isSameCurrency(a1: AmountLike, a2: AmountLike): boolean {
+ const x1 = this.jsonifyAmount(a1);
+ const x2 = this.jsonifyAmount(a2);
+ return x1.currency.toUpperCase() === x2.currency.toUpperCase();
+ }
+
static stringifyValue(a: AmountJson, minFractional: number = 0): string {
const av = a.value + Math.floor(a.fraction / amountFractionalBase);
const af = a.fraction % amountFractionalBase;
@@ -424,6 +430,6 @@ export class Amounts {
n = (n * 10) % amountFractionalBase;
}
}
- return s
+ return s;
}
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.