From 6dc5990b630b3afd958f0a9b458c4da59bf79399 Mon Sep 17 00:00:00 2001
From: G4mingJon4s <40526179+G4mingJon4s@users.noreply.github.com>
Date: Mon, 24 Oct 2022 22:09:53 +0200
Subject: [PATCH] CORPORATION: Added check to buy amount (#149)
---
src/Corporation/ui/MaterialElem.tsx | 9 ++++++---
src/NetscriptFunctions/Corporation.ts | 3 ++-
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/Corporation/ui/MaterialElem.tsx b/src/Corporation/ui/MaterialElem.tsx
index cd72d29e6..67f250a7b 100644
--- a/src/Corporation/ui/MaterialElem.tsx
+++ b/src/Corporation/ui/MaterialElem.tsx
@@ -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 {
- Buy: {numeralWrapper.format(mat.buy, nfB)}
+ Buy: {mat.buy >= 1e33 ? mat.buy.toExponential(3) : numeralWrapper.format(mat.buy, nfB)}
Prod: {numeralWrapper.format(mat.prd, nfB)}
Sell: {numeralWrapper.format(mat.sll, nfB)}
Export: {numeralWrapper.format(mat.totalExp, nfB)}
@@ -138,7 +140,8 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement {
}
>
- {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)
{
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);
},