) => {
@@ -148,8 +253,8 @@ export const highlights = [
data: {
// TODO add any data necessary for
// fulfillment provider
- },
- }),
+ }
+ })
})
.then((res) => res.json())
.then(({ cart: updatedCart }) => {
@@ -158,6 +263,26 @@ export const highlights = [
.finally(() => setLoading(false))
}
+ const formatPrice = (amount: number): string => {
+ return new Intl.NumberFormat("en-US", {
+ style: "currency",
+ currency: cart?.currency_code,
+ })
+ .format(amount)
+ }
+
+ const getShippingOptionPrice = useCallback((shippingOption: HttpTypes.StoreCartShippingOption) => {
+ if (shippingOption.price_type === "flat") {
+ return formatPrice(shippingOption.amount)
+ }
+
+ if (!calculatedPrices[shippingOption.id]) {
+ return
+ }
+
+ return formatPrice(calculatedPrices[shippingOption.id])
+ }, [calculatedPrices])
+
return (
{loading || !cart && Loading...}
@@ -168,14 +293,19 @@ export const highlights = [
e.target.value
)}
>
- {shippingOptions.map((shippingOption) => (
-
- ))}
+ {shippingOptions.map((shippingOption) => {
+ const price = getShippingOptionPrice(shippingOption)
+
+ return (
+
+ )
+ })}