check if threshold is number or amount and default to 0

This commit is contained in:
Sebastian 2023-03-11 18:30:44 -03:00
parent c67d94c56e
commit 77c71a4c2d
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069

View File

@ -183,18 +183,26 @@ export function useAccountDetails(
//FIXME: remove optional when libeufin sandbox has implemented the feature //FIXME: remove optional when libeufin sandbox has implemented the feature
if (data && typeof data.data.debitThreshold === "undefined") { if (data && typeof data.data.debitThreshold === "undefined") {
data.data.debitThreshold = "100"; data.data.debitThreshold = "0";
} }
//FIXME: sandbox server should return amount string //FIXME: sandbox server should return amount string
if (data) { 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); 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, currency,
value: Number.parseInt(d.data.debitThreshold, 10), value: value,
fraction: 0, fraction: 0,
}); });
return d; return clone;
} }
if (error) return error.info; if (error) return error.info;
return { loading: true }; return { loading: true };