CORPORATION: Remove non-empty-string condition in sell modals (#1847)

This commit is contained in:
catloversg 2024-12-18 18:15:13 +07:00 committed by GitHub
parent 8aea99e5cd
commit cffd6d75a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 12 deletions

@ -208,6 +208,14 @@ export function acceptInvestmentOffer(corporation: Corporation): void {
} }
export function convertPriceString(price: string): string { 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: * Replace invalid characters. Only accepts:
* - Digit characters * - Digit characters
@ -239,6 +247,14 @@ export function convertPriceString(price: string): string {
} }
export function convertAmountString(amount: 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: * Replace invalid characters. Only accepts:
* - Digit characters * - Digit characters

@ -31,16 +31,10 @@ export function SellMaterialModal(props: IProps): React.ReactElement {
} }
function onAmtChange(event: React.ChangeEvent<HTMLInputElement>): void { function onAmtChange(event: React.ChangeEvent<HTMLInputElement>): void {
if (event.target.value === "") {
return;
}
setAmt(event.target.value); setAmt(event.target.value);
} }
function onPriceChange(event: React.ChangeEvent<HTMLInputElement>): void { function onPriceChange(event: React.ChangeEvent<HTMLInputElement>): void {
if (event.target.value === "") {
return;
}
setPrice(event.target.value); setPrice(event.target.value);
} }

@ -39,16 +39,10 @@ export function SellProductModal(props: IProps): React.ReactElement {
} }
function onAmtChange(event: React.ChangeEvent<HTMLInputElement>): void { function onAmtChange(event: React.ChangeEvent<HTMLInputElement>): void {
if (event.target.value === "") {
return;
}
setAmt(event.target.value); setAmt(event.target.value);
} }
function onPriceChange(event: React.ChangeEvent<HTMLInputElement>): void { function onPriceChange(event: React.ChangeEvent<HTMLInputElement>): void {
if (event.target.value === "") {
return;
}
setPrice(event.target.value); setPrice(event.target.value);
} }