@numueg/theme-sdk 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +12 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +12 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1445,6 +1445,16 @@ var EMPTY_CART = {
|
|
|
1445
1445
|
total: 0,
|
|
1446
1446
|
currency: "EGP"
|
|
1447
1447
|
};
|
|
1448
|
+
function normalizeCartFromServer(cart) {
|
|
1449
|
+
const toMajor = (n) => typeof n === "number" ? n / 100 : 0;
|
|
1450
|
+
return {
|
|
1451
|
+
...cart,
|
|
1452
|
+
subtotal: toMajor(cart.subtotal),
|
|
1453
|
+
total: toMajor(cart.total),
|
|
1454
|
+
...cart.discount_amount != null ? { discount_amount: toMajor(cart.discount_amount) } : {},
|
|
1455
|
+
items: Array.isArray(cart.items) ? cart.items.map((it) => ({ ...it, price: toMajor(it.price) })) : []
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1448
1458
|
function readCsrfCookie() {
|
|
1449
1459
|
if (typeof document === "undefined") return null;
|
|
1450
1460
|
const match = document.cookie.match(/(?:^|;\s*)numu_csrf=([^;]+)/);
|
|
@@ -1647,7 +1657,7 @@ function NuMuProvider({
|
|
|
1647
1657
|
if (!res.ok || cancelled) return;
|
|
1648
1658
|
const data = await res.json();
|
|
1649
1659
|
if (data && typeof data === "object") {
|
|
1650
|
-
setCart(data);
|
|
1660
|
+
setCart(normalizeCartFromServer(data));
|
|
1651
1661
|
}
|
|
1652
1662
|
} catch {
|
|
1653
1663
|
}
|
|
@@ -1668,7 +1678,7 @@ function NuMuProvider({
|
|
|
1668
1678
|
return;
|
|
1669
1679
|
}
|
|
1670
1680
|
latestApplied.current = token;
|
|
1671
|
-
setCart(newCart);
|
|
1681
|
+
setCart(normalizeCartFromServer(newCart));
|
|
1672
1682
|
},
|
|
1673
1683
|
[]
|
|
1674
1684
|
);
|