@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.cjs
CHANGED
|
@@ -1447,6 +1447,16 @@ var EMPTY_CART = {
|
|
|
1447
1447
|
total: 0,
|
|
1448
1448
|
currency: "EGP"
|
|
1449
1449
|
};
|
|
1450
|
+
function normalizeCartFromServer(cart) {
|
|
1451
|
+
const toMajor = (n) => typeof n === "number" ? n / 100 : 0;
|
|
1452
|
+
return {
|
|
1453
|
+
...cart,
|
|
1454
|
+
subtotal: toMajor(cart.subtotal),
|
|
1455
|
+
total: toMajor(cart.total),
|
|
1456
|
+
...cart.discount_amount != null ? { discount_amount: toMajor(cart.discount_amount) } : {},
|
|
1457
|
+
items: Array.isArray(cart.items) ? cart.items.map((it) => ({ ...it, price: toMajor(it.price) })) : []
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1450
1460
|
function readCsrfCookie() {
|
|
1451
1461
|
if (typeof document === "undefined") return null;
|
|
1452
1462
|
const match = document.cookie.match(/(?:^|;\s*)numu_csrf=([^;]+)/);
|
|
@@ -1649,7 +1659,7 @@ function NuMuProvider({
|
|
|
1649
1659
|
if (!res.ok || cancelled) return;
|
|
1650
1660
|
const data = await res.json();
|
|
1651
1661
|
if (data && typeof data === "object") {
|
|
1652
|
-
setCart(data);
|
|
1662
|
+
setCart(normalizeCartFromServer(data));
|
|
1653
1663
|
}
|
|
1654
1664
|
} catch {
|
|
1655
1665
|
}
|
|
@@ -1670,7 +1680,7 @@ function NuMuProvider({
|
|
|
1670
1680
|
return;
|
|
1671
1681
|
}
|
|
1672
1682
|
latestApplied.current = token;
|
|
1673
|
-
setCart(newCart);
|
|
1683
|
+
setCart(normalizeCartFromServer(newCart));
|
|
1674
1684
|
},
|
|
1675
1685
|
[]
|
|
1676
1686
|
);
|