aboutsummaryrefslogtreecommitdiff
path: root/src/util/amounts.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-04-02 20:33:01 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-04-02 20:33:01 +0530
commitef0acf06bfb7820a21c4719dba0d659f600be3c7 (patch)
tree216d34722240f682e5ee58632947fa75e9b4fcee /src/util/amounts.ts
parent1728e5011e16f226c6e3675aa196872af39f6c4e (diff)
downloadwallet-core-ef0acf06bfb7820a21c4719dba0d659f600be3c7.tar.xz
model reserve history in the exchange, improve reserve handling logic
Diffstat (limited to 'src/util/amounts.ts')
-rw-r--r--src/util/amounts.ts20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/util/amounts.ts b/src/util/amounts.ts
index 8deeaeccc..aee7b12b5 100644
--- a/src/util/amounts.ts
+++ b/src/util/amounts.ts
@@ -299,7 +299,7 @@ export function fromFloat(floatVal: number, currency: string) {
* Convert to standard human-readable string representation that's
* also used in JSON formats.
*/
-export function toString(a: AmountJson): string {
+export function stringify(a: AmountJson): string {
const av = a.value + Math.floor(a.fraction / fractionalBase);
const af = a.fraction % fractionalBase;
let s = av.toString();
@@ -322,7 +322,7 @@ export function toString(a: AmountJson): string {
/**
* Check if the argument is a valid amount in string form.
*/
-export function check(a: any): boolean {
+function check(a: any): boolean {
if (typeof a !== "string") {
return false;
}
@@ -333,3 +333,19 @@ export function check(a: any): boolean {
return false;
}
}
+
+// Export all amount-related functions here for better IDE experience.
+export const Amounts = {
+ stringify: stringify,
+ parse: parse,
+ parseOrThrow: parseOrThrow,
+ cmp: cmp,
+ add: add,
+ sum: sum,
+ sub: sub,
+ check: check,
+ getZero: getZero,
+ isZero: isZero,
+ maxAmountValue: maxAmountValue,
+ fromFloat: fromFloat,
+}; \ No newline at end of file