upgrade amount api

This commit is contained in:
Sebastian 2022-11-04 10:58:13 -03:00
parent 50e51429ee
commit 80ab8ccce9
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
3 changed files with 4 additions and 4 deletions

View File

@ -140,7 +140,7 @@ export function CreatePage({
}: Props): VNode { }: Props): VNode {
const [value, valueHandler] = useState(with_defaults(instanceConfig)); const [value, valueHandler] = useState(with_defaults(instanceConfig));
const config = useConfigContext(); const config = useConfigContext();
const zero = Amounts.getZero(config.currency); const zero = Amounts.zeroOfCurrency(config.currency);
const inventoryList = Object.values(value.inventoryProducts || {}); const inventoryList = Object.values(value.inventoryProducts || {});
const productList = Object.values(value.products || {}); const productList = Object.values(value.products || {});

View File

@ -432,7 +432,7 @@ function PaidPage({
const refund_taken = order.refund_details.reduce((prev, cur) => { const refund_taken = order.refund_details.reduce((prev, cur) => {
if (cur.pending) return prev; if (cur.pending) return prev;
return Amounts.add(prev, Amounts.parseOrThrow(cur.amount)).amount; return Amounts.add(prev, Amounts.parseOrThrow(cur.amount)).amount;
}, Amounts.getZero(amount.currency)); }, Amounts.zeroOfCurrency(amount.currency));
value.refund_taken = Amounts.stringify(refund_taken); value.refund_taken = Amounts.stringify(refund_taken);
return ( return (

View File

@ -268,14 +268,14 @@ export function RefundModal({
.map((r) => r.amount) .map((r) => r.amount)
.reduce( .reduce(
(p, c) => Amounts.add(p, Amounts.parseOrThrow(c)).amount, (p, c) => Amounts.add(p, Amounts.parseOrThrow(c)).amount,
Amounts.getZero(config.currency) Amounts.zeroOfCurrency(config.currency)
); );
const orderPrice = const orderPrice =
order.order_status === "paid" order.order_status === "paid"
? Amounts.parseOrThrow(order.contract_terms.amount) ? Amounts.parseOrThrow(order.contract_terms.amount)
: undefined; : undefined;
const totalRefundable = !orderPrice const totalRefundable = !orderPrice
? Amounts.getZero(totalRefunded.currency) ? Amounts.zeroOfCurrency(totalRefunded.currency)
: refunds.length : refunds.length
? Amounts.sub(orderPrice, totalRefunded).amount ? Amounts.sub(orderPrice, totalRefunded).amount
: orderPrice; : orderPrice;