Skip to content

Commit

Permalink
CORPORATION: Remove non-empty-string condition in sell modals
Browse files Browse the repository at this point in the history
  • Loading branch information
catloversg committed Dec 13, 2024
1 parent d9dba2a commit 45b2480
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
16 changes: 16 additions & 0 deletions src/Corporation/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions src/Corporation/ui/modals/SellMaterialModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ export function SellMaterialModal(props: IProps): React.ReactElement {
}

function onAmtChange(event: React.ChangeEvent<HTMLInputElement>): void {
if (event.target.value === "") {
return;
}
setAmt(event.target.value);
}

function onPriceChange(event: React.ChangeEvent<HTMLInputElement>): void {
if (event.target.value === "") {
return;
}
setPrice(event.target.value);
}

Expand Down
6 changes: 0 additions & 6 deletions src/Corporation/ui/modals/SellProductModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ export function SellProductModal(props: IProps): React.ReactElement {
}

function onAmtChange(event: React.ChangeEvent<HTMLInputElement>): void {
if (event.target.value === "") {
return;
}
setAmt(event.target.value);
}

function onPriceChange(event: React.ChangeEvent<HTMLInputElement>): void {
if (event.target.value === "") {
return;
}
setPrice(event.target.value);
}

Expand Down

0 comments on commit 45b2480

Please sign in to comment.