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: 4 additions & 2 deletions components/product-currency-symbol.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { toFormat, type Dinero } from 'dinero.js';
import { toSnapshot, type Dinero } from 'dinero.js';

export const ProductCurrencySymbol = ({
dinero,
}: {
dinero: Dinero<number>;
}) => {
const { currency } = toSnapshot(dinero);

let symbol = '';
switch (toFormat(dinero, ({ currency }) => currency.code)) {
switch (currency.code) {
case 'GBP': {
symbol = '£';
break;
Expand Down
6 changes: 3 additions & 3 deletions components/product-deal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProductCurrencySymbol } from '#/components/product-currency-symbol';
import { toUnit, type Dinero } from 'dinero.js';
import { toDecimal, type Dinero } from 'dinero.js';

export const ProductDeal = ({
price: priceRaw,
Expand All @@ -10,8 +10,8 @@ export const ProductDeal = ({
amount: Dinero<number>;
};
}) => {
const discount = toUnit(discountRaw.amount);
const price = toUnit(priceRaw);
const discount = Number(toDecimal(discountRaw.amount));
const price = Number(toDecimal(priceRaw));
const percent = Math.round(100 - (discount / price) * 100);

return (
Expand Down
4 changes: 2 additions & 2 deletions components/product-price.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Product } from '#/types/product';
import { ProductCurrencySymbol } from '#/components/product-currency-symbol';
import { ProductDeal } from '#/components/product-deal';
import { ProductLighteningDeal } from '#/components/product-lightening-deal';
import { multiply, toUnit, type Dinero } from 'dinero.js';
import { multiply, toDecimal, type Dinero } from 'dinero.js';

function isDiscount(obj: any): obj is { percent: number; expires?: number } {
return typeof obj?.percent === 'number';
Expand Down Expand Up @@ -45,7 +45,7 @@ export const ProductPrice = ({
<ProductCurrencySymbol dinero={price} />
</div>
<div className="text-lg font-bold leading-snug text-white">
{toUnit(price)}
{toDecimal(price)}
</div>
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions components/product-split-payments.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ProductCurrencySymbol } from '#/components/product-currency-symbol';
import { allocate, toUnit, up, type Dinero } from 'dinero.js';
import { allocate, toDecimal, transformScale, up, type Dinero } from 'dinero.js';

export const ProductSplitPayments = ({ price }: { price: Dinero<number> }) => {
// only offer split payments for more expensive items
if (toUnit(price) < 150) {
if (Number(toDecimal(price)) < 150) {
return null;
}

const [perMonth] = allocate(price, [1, 2]);
return (
<div className="text-sm text-gray-400">
Or <ProductCurrencySymbol dinero={price} />
{toUnit(perMonth, { digits: 0, round: up })}/month for 3 months
{toDecimal(transformScale(perMonth, 0, up))}/month for 3 months
</div>
);
};
4 changes: 2 additions & 2 deletions components/product-used-price.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Product } from '#/types/product';
import { dinero, toUnit, up, type DineroSnapshot } from 'dinero.js';
import { dinero, toDecimal, transformScale, up, type DineroSnapshot } from 'dinero.js';

export const ProductUsedPrice = ({
usedPrice: usedPriceRaw,
Expand All @@ -12,7 +12,7 @@ export const ProductUsedPrice = ({
<div className="text-sm">
<div className="text-gray-400">More buying choices</div>
<div className="text-gray-200">
${toUnit(usedPrice, { digits: 0, round: up })} (used)
${toDecimal(transformScale(usedPrice, 0, up))} (used)
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@heroicons/react": "2.1.5",
"clsx": "2.1.1",
"date-fns": "3.6.0",
"dinero.js": "2.0.0-alpha.8",
"dinero.js": "2.0.0",
"geist": "1.3.1",
"next": "15.6.0-canary.60",
"react": "19.0.0-rc-8b08e99e-20240713",
Expand Down
50 changes: 14 additions & 36 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.