Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# PWA build files
public/service-worker.js
public/service-worker.js.map
public/workbox-*.js
public/workbox-*.js.map
67 changes: 55 additions & 12 deletions components/cart-invoice-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ import { LightningAddress } from "@getalby/lightning-tools";
import QRCode from "qrcode";
import { v4 as uuidv4 } from "uuid";
import { nip19 } from "nostr-tools";
import { ProductData } from "@/utils/parsers/product-parser-functions";
import {
ProductData,
resolveEffectiveUnitPrice,
} from "@/utils/parsers/product-parser-functions";
import { webln } from "@getalby/sdk";
import { formatWithCommas } from "./utility-components/display-monetary-info";
import { SHOPSTRBUTTONCLASSNAMES } from "@/utils/STATIC-VARIABLES";
Expand Down Expand Up @@ -468,6 +471,7 @@ export default function CartInvoiceCard({
donationPercentage: donationPercentageValue,
selectedSize: product.selectedSize,
selectedVolume: product.selectedVolume,
selectedWeight: product.selectedWeight,
selectedBulkOption: product.selectedBulkOption,
};
} else if (isReceipt) {
Expand All @@ -489,6 +493,7 @@ export default function CartInvoiceCard({
donationPercentage: donationPercentageValue,
selectedSize: product.selectedSize,
selectedVolume: product.selectedVolume,
selectedWeight: product.selectedWeight,
selectedBulkOption: product.selectedBulkOption,
};
} else if (isDonation) {
Expand All @@ -510,6 +515,7 @@ export default function CartInvoiceCard({
donationPercentage: donationPercentageValue,
selectedSize: product.selectedSize,
selectedVolume: product.selectedVolume,
selectedWeight: product.selectedWeight,
selectedBulkOption: product.selectedBulkOption,
};
}
Expand Down Expand Up @@ -1129,6 +1135,13 @@ export default function CartInvoiceCard({
productDetails += " in a " + product.selectedVolume;
}
}
if (product.selectedWeight) {
if (productDetails) {
productDetails += " and weight " + product.selectedWeight;
} else {
productDetails += " in weight " + product.selectedWeight;
}
}
if (product.selectedBulkOption) {
if (productDetails) {
productDetails +=
Expand Down Expand Up @@ -1252,6 +1265,13 @@ export default function CartInvoiceCard({
productDetails += " in a " + product.selectedVolume;
}
}
if (product.selectedWeight) {
if (productDetails) {
productDetails += " and weight " + product.selectedWeight;
} else {
productDetails += " in weight " + product.selectedWeight;
}
}
if (product.selectedBulkOption) {
if (productDetails) {
productDetails +=
Expand Down Expand Up @@ -1334,6 +1354,13 @@ export default function CartInvoiceCard({
productDetails += " in a " + product.selectedVolume;
}
}
if (product.selectedWeight) {
if (productDetails) {
productDetails += " and weight " + product.selectedWeight;
} else {
productDetails += " in weight " + product.selectedWeight;
}
}
if (product.selectedBulkOption) {
if (productDetails) {
productDetails +=
Expand Down Expand Up @@ -1496,6 +1523,13 @@ export default function CartInvoiceCard({
productDetails += " in a " + product.selectedVolume;
}
}
if (product.selectedWeight) {
if (productDetails) {
productDetails += " and weight " + product.selectedWeight;
} else {
productDetails += " in weight " + product.selectedWeight;
}
}
if (product.selectedBulkOption) {
if (productDetails) {
productDetails +=
Expand Down Expand Up @@ -1629,6 +1663,13 @@ export default function CartInvoiceCard({
productDetails += " in a " + product.selectedVolume;
}
}
if (product.selectedWeight) {
if (productDetails) {
productDetails += " and weight " + product.selectedWeight;
} else {
productDetails += " in weight " + product.selectedWeight;
}
}
if (product.selectedBulkOption) {
if (productDetails) {
productDetails +=
Expand Down Expand Up @@ -2186,6 +2227,11 @@ export default function CartInvoiceCard({
Volume: {product.selectedVolume}
</p>
)}
{product.selectedWeight && (
<p className="text-sm text-gray-600 dark:text-gray-400">
Weight: {product.selectedWeight}
</p>
)}
{product.selectedBulkOption && (
<p className="mb-1 text-gray-600 dark:text-gray-400">
Bundle: {product.selectedBulkOption} units
Expand All @@ -2208,11 +2254,8 @@ export default function CartInvoiceCard({
{products.map((product) => {
const discount = appliedDiscounts[product.pubkey] || 0;
const basePrice =
(product.bulkPrice !== undefined
? product.bulkPrice
: product.volumePrice !== undefined
? product.volumePrice
: product.price) * (quantities[product.id] || 1);
resolveEffectiveUnitPrice(product) *
(quantities[product.id] || 1);
const discountedPrice =
discount > 0
? basePrice * (1 - discount / 100)
Expand Down Expand Up @@ -2404,6 +2447,11 @@ export default function CartInvoiceCard({
Volume: {product.selectedVolume}
</p>
)}
{product.selectedWeight && (
<p className="text-sm text-gray-600 dark:text-gray-400">
Weight: {product.selectedWeight}
</p>
)}
{product.selectedBulkOption && (
<p className="mb-1 text-gray-600 dark:text-gray-400">
Bundle: {product.selectedBulkOption} units
Expand All @@ -2425,12 +2473,7 @@ export default function CartInvoiceCard({
<div className="space-y-3">
{products.map((product) => {
const discount = appliedDiscounts[product.pubkey] || 0;
const originalPrice =
product.bulkPrice !== undefined
? product.bulkPrice
: product.volumePrice !== undefined
? product.volumePrice
: product.price;
const originalPrice = resolveEffectiveUnitPrice(product);
const basePrice =
originalPrice * (quantities[product.id] || 1);
const discountedPrice =
Expand Down
18 changes: 18 additions & 0 deletions components/display-product-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,24 @@ export default function DisplayProductModal({
</div>
</>
) : null}
{productData.weights && productData.weights.length > 0 ? (
<>
<span className="text-xl font-semibold">Weights: </span>
<div className="flex flex-wrap items-center">
{productData.weights && productData.weights.length > 0
? productData.weights.map((weight: string) => (
<span
key={weight}
className="mb-2 mr-4 text-light-text dark:text-dark-text"
>
{weight}: {productData.weightPrices?.get(weight) || 0}{" "}
{productData.currency}
</span>
))
: null}
</div>
</>
) : null}
{productData.bulkPrices && productData.bulkPrices.size > 0 ? (
<>
<span className="text-xl font-semibold">Bulk Pricing: </span>
Expand Down
Loading