diff --git a/src/app/components/Summary/Summary.tsx b/src/app/components/Summary/Summary.tsx index 962d8a2..b4dc3ac 100644 --- a/src/app/components/Summary/Summary.tsx +++ b/src/app/components/Summary/Summary.tsx @@ -1,3 +1,4 @@ +import { SessionContext } from "@/app/context/Context"; import { PI_TYPES_MAP } from "@/const"; import { planetCalculations } from "@/planets"; import { AccessToken } from "@/types"; @@ -15,6 +16,7 @@ import { Stack, styled, } from "@mui/material"; +import { useContext } from "react"; const StackItem = styled(Stack)(({ theme }) => ({ ...theme.typography.body2, @@ -28,7 +30,13 @@ interface Grouped { [key: number]: number; } +const displayValue = (valueInMillions: number): string => + valueInMillions >= 1000 + ? `${(valueInMillions / 1000).toFixed(2)} B` + : `${valueInMillions.toFixed(2)} M`; + export const Summary = ({ characters }: { characters: AccessToken[] }) => { + const { piPrices, alertMode } = useContext(SessionContext); const exports = characters.flatMap((char) => { return char.planets.flatMap((planet) => { const { localExports } = planetCalculations(planet); @@ -46,11 +54,20 @@ export const Summary = ({ characters }: { characters: AccessToken[] }) => { const withProductNameAndPrice = Object.keys(groupedByMaterial).map( (typeIdString) => { const typeId = parseInt(typeIdString); + const amount = groupedByMaterial[typeId]; + const valueInMillions = + (((piPrices?.appraisal.items.find((a) => a.typeID === typeId)?.prices + .sell.min ?? 0) * + amount) / + 1000000) * + 24 * + 30; + return { typeId, - amount: groupedByMaterial[typeId], + amount, materialName: PI_TYPES_MAP[typeId].name, - price: 0, + price: valueInMillions, }; }, ); @@ -93,6 +110,13 @@ export const Summary = ({ characters }: { characters: AccessToken[] }) => { price={product.price} /> ))} + amount + p.price, + 0, + )} + /> @@ -106,7 +130,7 @@ const SummaryRow = ({ price, }: { material: string; - amount: number; + amount?: number; price: number; }) => ( @@ -114,6 +138,6 @@ const SummaryRow = ({ {material} {amount} - {price} + {displayValue(price)} );