fix text for sell shares modal text

This commit is contained in:
phyzical 2022-04-02 10:47:21 +08:00
parent 4224c7defd
commit 9e39ca32a5

@ -33,22 +33,23 @@ export function SellSharesModal(props: IProps): React.ReactElement {
function ProfitIndicator(props: { shares: number | null; corp: ICorporation }): React.ReactElement { function ProfitIndicator(props: { shares: number | null; corp: ICorporation }): React.ReactElement {
if (props.shares === null) return <></>; if (props.shares === null) return <></>;
let text = "";
if (isNaN(props.shares) || props.shares <= 0) { if (isNaN(props.shares) || props.shares <= 0) {
return <Typography>ERROR: Invalid value entered for number of shares to sell </Typography>; text = `ERROR: Invalid value entered for number of shares to sell`;
} else if (props.shares > corp.numShares) { } else if (props.shares > corp.numShares) {
return <Typography>You don't have this many shares to sell! </Typography>; text = `You don't have this many shares to sell!`;
} else { } else {
const stockSaleResults = corp.calculateShareSale(props.shares); const stockSaleResults = corp.calculateShareSale(props.shares);
const profit = stockSaleResults[0]; const profit = stockSaleResults[0];
text = `Sell ${props.shares} shares for a total of ${numeralWrapper.formatMoney(profit)}`;
}
return ( return (
<Typography> <Typography>
<small> <small>{text}</small>
Sell {props.shares} shares for a total of {numeralWrapper.formatMoney(profit)}
</small>
</Typography> </Typography>
); );
} }
}
function sell(): void { function sell(): void {
if (disabled) return; if (disabled) return;
@ -86,7 +87,6 @@ export function SellSharesModal(props: IProps): React.ReactElement {
<br /> <br />
The current price of your company's stock is {numeralWrapper.formatMoney(corp.sharePrice)} The current price of your company's stock is {numeralWrapper.formatMoney(corp.sharePrice)}
</Typography> </Typography>
<ProfitIndicator shares={shares} corp={corp} />
<br /> <br />
<TextField <TextField
variant="standard" variant="standard"
@ -99,6 +99,7 @@ export function SellSharesModal(props: IProps): React.ReactElement {
<Button disabled={disabled} onClick={sell} sx={{ mx: 1 }}> <Button disabled={disabled} onClick={sell} sx={{ mx: 1 }}>
Sell shares Sell shares
</Button> </Button>
<ProfitIndicator shares={shares} corp={corp} />
</Modal> </Modal>
); );
} }