From 45b24805105bff6b9b79f79ac769ca99183d372f Mon Sep 17 00:00:00 2001 From: CatLover <152669316+catloversg@users.noreply.github.com> Date: Fri, 13 Dec 2024 20:31:11 +0700 Subject: [PATCH] CORPORATION: Remove non-empty-string condition in sell modals --- src/Corporation/Actions.ts | 16 ++++++++++++++++ src/Corporation/ui/modals/SellMaterialModal.tsx | 6 ------ src/Corporation/ui/modals/SellProductModal.tsx | 6 ------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts index 89a08ca233..8d35b2f183 100644 --- a/src/Corporation/Actions.ts +++ b/src/Corporation/Actions.ts @@ -208,6 +208,14 @@ export function acceptInvestmentOffer(corporation: Corporation): void { } export function convertPriceString(price: string): string { + /** + * This is a common error. We should check it to get a "user-friendly" error message. If we pass an empty string to + * eval(), it will return undefined, and the "is-it-a-valid-number" following check will throw an unhelpful error + * message. + */ + if (price === "") { + throw new Error("Price cannot be an empty string."); + } /** * Replace invalid characters. Only accepts: * - Digit characters @@ -239,6 +247,14 @@ export function convertPriceString(price: string): string { } export function convertAmountString(amount: string): string { + /** + * This is a common error. We should check it to get a "user-friendly" error message. If we pass an empty string to + * eval(), it will return undefined, and the "is-it-a-valid-number" following check will throw an unhelpful error + * message. + */ + if (amount === "") { + throw new Error("Amount cannot be an empty string."); + } /** * Replace invalid characters. Only accepts: * - Digit characters diff --git a/src/Corporation/ui/modals/SellMaterialModal.tsx b/src/Corporation/ui/modals/SellMaterialModal.tsx index c911d5c1a5..0c12b682e7 100644 --- a/src/Corporation/ui/modals/SellMaterialModal.tsx +++ b/src/Corporation/ui/modals/SellMaterialModal.tsx @@ -31,16 +31,10 @@ export function SellMaterialModal(props: IProps): React.ReactElement { } function onAmtChange(event: React.ChangeEvent): void { - if (event.target.value === "") { - return; - } setAmt(event.target.value); } function onPriceChange(event: React.ChangeEvent): void { - if (event.target.value === "") { - return; - } setPrice(event.target.value); } diff --git a/src/Corporation/ui/modals/SellProductModal.tsx b/src/Corporation/ui/modals/SellProductModal.tsx index 0e12ff6589..8726dd8455 100644 --- a/src/Corporation/ui/modals/SellProductModal.tsx +++ b/src/Corporation/ui/modals/SellProductModal.tsx @@ -39,16 +39,10 @@ export function SellProductModal(props: IProps): React.ReactElement { } function onAmtChange(event: React.ChangeEvent): void { - if (event.target.value === "") { - return; - } setAmt(event.target.value); } function onPriceChange(event: React.ChangeEvent): void { - if (event.target.value === "") { - return; - } setPrice(event.target.value); }