CORPORATION: Added check to buy amount (#149)

This commit is contained in:
G4mingJon4s 2022-10-24 22:09:53 +02:00 committed by GitHub
parent d22d0a25ef
commit 6dc5990b63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

@ -61,7 +61,9 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement {
division.newInd && Object.keys(division.reqMats).includes(mat.name) && mat.buy === 0 && mat.imp === 0;
// Purchase material button
const purchaseButtonText = `Buy (${numeralWrapper.format(mat.buy, nfB)})`;
const purchaseButtonText = `Buy (${
mat.buy >= 1e33 ? mat.buy.toExponential(3) : numeralWrapper.format(mat.buy, nfB)
})`;
// Sell material button
let sellButtonText: JSX.Element;
@ -125,7 +127,7 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement {
<Tooltip
title={
<Typography>
Buy: {numeralWrapper.format(mat.buy, nfB)} <br />
Buy: {mat.buy >= 1e33 ? mat.buy.toExponential(3) : numeralWrapper.format(mat.buy, nfB)} <br />
Prod: {numeralWrapper.format(mat.prd, nfB)} <br />
Sell: {numeralWrapper.format(mat.sll, nfB)} <br />
Export: {numeralWrapper.format(mat.totalExp, nfB)} <br />
@ -138,7 +140,8 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement {
}
>
<Typography>
{mat.name}: {numeralWrapper.format(mat.qty, nfB)} ({numeralWrapper.format(totalGain, nfB)}/s)
{mat.name}: {numeralWrapper.format(mat.qty, nfB)} (
{totalGain >= 1e33 ? totalGain.toExponential(3) : numeralWrapper.format(totalGain, nfB)}/s)
</Typography>
</Tooltip>
<Tooltip

@ -457,7 +457,8 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
const cityName = helpers.city(ctx, "cityName", _cityName);
const materialName = helpers.string(ctx, "materialName", _materialName);
const amt = helpers.number(ctx, "amt", _amt);
if (amt < 0) throw new Error("Invalid value for amount field! Must be numeric and greater than 0");
if (amt < 0 || !Number.isFinite(amt))
throw new Error("Invalid value for amount field! Must be numeric and greater than 0");
const material = getMaterial(divisionName, cityName, materialName);
BuyMaterial(material, amt);
},