check if threshold is number or amount and default to 0
This commit is contained in:
parent
c67d94c56e
commit
77c71a4c2d
@ -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 };
|
||||
|
Loading…
Reference in New Issue
Block a user