aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-03-11 18:30:44 -0300
committerSebastian <sebasjm@gmail.com>2023-03-11 18:30:51 -0300
commit77c71a4c2d4d202f82a33bd44f5a099f82249482 (patch)
treeb50ff6653ce907b8150d2e3b8558fe8b130dc996
parentc67d94c56e154be4b2cf91572cdc2d8d2da7f8e4 (diff)
check if threshold is number or amount and default to 0
-rw-r--r--packages/demobank-ui/src/hooks/access.ts18
1 files changed, 13 insertions, 5 deletions
diff --git a/packages/demobank-ui/src/hooks/access.ts b/packages/demobank-ui/src/hooks/access.ts
index 750b95fa0..ee8566efe 100644
--- a/packages/demobank-ui/src/hooks/access.ts
+++ b/packages/demobank-ui/src/hooks/access.ts
@@ -183,18 +183,26 @@ export function useAccountDetails(
//FIXME: remove optional when libeufin sandbox has implemented the feature
if (data && typeof data.data.debitThreshold === "undefined") {
- data.data.debitThreshold = "100";
+ data.data.debitThreshold = "0";
}
//FIXME: sandbox server should return amount string
if (data) {
- const d = structuredClone(data);
+ const isAmount = Amounts.parse(data.data.debitThreshold);
+ if (isAmount) {
+ //server response with correct format
+ return data;
+ }
const { currency } = Amounts.parseOrThrow(data.data.balance.amount);
- d.data.debitThreshold = Amounts.stringify({
+ const clone = structuredClone(data);
+
+ const theNumber = Number.parseInt(data.data.debitThreshold, 10);
+ const value = Number.isNaN(theNumber) ? 0 : theNumber;
+ clone.data.debitThreshold = Amounts.stringify({
currency,
- value: Number.parseInt(d.data.debitThreshold, 10),
+ value: value,
fraction: 0,
});
- return d;
+ return clone;
}
if (error) return error.info;
return { loading: true };