bitburner-src/src/ui/React/Money.tsx

36 lines
1.1 KiB
TypeScript
Raw Normal View History

import * as React from "react";
2022-03-06 05:05:55 +01:00
import { numeralWrapper } from "../numeralFormat";
import { IPlayer } from "../../PersonObjects/IPlayer";
2021-10-01 19:08:37 +02:00
import { Theme } from "@mui/material/styles";
import makeStyles from "@mui/styles/makeStyles";
import createStyles from "@mui/styles/createStyles";
const useStyles = makeStyles((theme: Theme) =>
createStyles({
unbuyable: {
color: theme.palette.action.disabled,
},
money: {
color: theme.colors.money,
},
}),
);
interface IProps {
2021-09-05 01:09:30 +02:00
money: number | string;
player?: IPlayer;
}
2021-10-01 19:08:37 +02:00
export function Money(props: IProps): React.ReactElement {
const classes = useStyles();
2021-09-05 01:09:30 +02:00
if (props.player !== undefined) {
2021-09-09 05:47:34 +02:00
if (typeof props.money !== "number") throw new Error("if player if provided, money should be number, contact dev");
2021-09-05 01:09:30 +02:00
if (!props.player.canAfford(props.money))
2021-10-01 19:08:37 +02:00
return <span className={classes.unbuyable}>{numeralWrapper.formatMoney(props.money)}</span>;
2021-09-05 01:09:30 +02:00
}
return (
2021-10-01 19:08:37 +02:00
<span className={classes.money}>
2021-09-09 05:47:34 +02:00
{typeof props.money === "number" ? numeralWrapper.formatMoney(props.money) : props.money}
2021-09-05 01:09:30 +02:00
</span>
);
}