diff --git a/src/components/MobileOffsetOrder.tsx b/src/components/MobileOffsetOrder.tsx index 22bc21e..03de30b 100644 --- a/src/components/MobileOffsetOrder.tsx +++ b/src/components/MobileOffsetOrder.tsx @@ -73,8 +73,13 @@ export function MobileOffsetOrder({ tons, monetaryAmount, onBack }: Props) { savedState?.offsetPercentage ?? 100 // Default to 100% or use saved value ); + // Calculate price per ton (rounded up) + const roundedPricePerTon = portfolio ? Math.ceil(portfolio.pricePerTon || 18) : 18; + // Calculate the actual tons to offset based on percentage - const actualOffsetTons = (tons * offsetPercentage) / 100; + // If monetaryAmount is provided (custom amount), calculate tons from the monetary amount + const baseTons = monetaryAmount ? (monetaryAmount / roundedPricePerTon) : tons; + const actualOffsetTons = (baseTons * offsetPercentage) / 100; // Format tons for display const formatTons = (tons: number): string => { @@ -214,7 +219,6 @@ export function MobileOffsetOrder({ tons, monetaryAmount, onBack }: Props) { }; // Calculate offset cost using the portfolio price (rounded UP to match display) - const roundedPricePerTon = portfolio ? Math.ceil(portfolio.pricePerTon || 18) : 18; const offsetCost = monetaryAmount || (portfolio ? actualOffsetTons * roundedPricePerTon : 0); const handleInputChange = (field: keyof typeof formData, value: string) => { diff --git a/src/components/OffsetOrder.tsx b/src/components/OffsetOrder.tsx index 6368e38..8032af6 100644 --- a/src/components/OffsetOrder.tsx +++ b/src/components/OffsetOrder.tsx @@ -77,8 +77,13 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr savedState?.offsetPercentage ?? 100 // Default to 100% or use saved value ); + // Calculate price per ton (rounded up) + const roundedPricePerTon = portfolio ? Math.ceil(portfolio.pricePerTon || 18) : 18; + // Calculate the actual tons to offset based on percentage - const actualOffsetTons = (tons * offsetPercentage) / 100; + // If monetaryAmount is provided (custom amount), calculate tons from the monetary amount + const baseTons = monetaryAmount ? (monetaryAmount / roundedPricePerTon) : tons; + const actualOffsetTons = (baseTons * offsetPercentage) / 100; // Format tons for display const formatTons = (tons: number): string => { @@ -193,7 +198,6 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr }; // Calculate offset cost using the portfolio price (rounded UP to match display) - const roundedPricePerTon = portfolio ? Math.ceil(portfolio.pricePerTon || 18) : 18; const offsetCost = monetaryAmount || (portfolio ? actualOffsetTons * roundedPricePerTon : 0); return (