Restrict to buying 1 slot at a time

This commit is contained in:
Austin Chen 2022-04-01 09:24:33 -07:00
parent ee3102d092
commit 68fb5b578c
2 changed files with 18 additions and 4 deletions

View File

@ -84,6 +84,7 @@ export function Manaboard(props: {
holder={user}
value={values[index]}
createdTime={createdTimes[index]}
allSlots={users}
/>
</Row>
</td>
@ -114,8 +115,9 @@ export function BuySlotModal(props: {
slot: number
value: number
createdTime: number
allSlots: User[]
}) {
const { slot, title, holder, value, createdTime } = props
const { slot, allSlots, holder, value, createdTime } = props
const user = useUser()
const [open, setOpen] = useState(false)
@ -133,6 +135,14 @@ export function BuySlotModal(props: {
// await buyLeaderboardSlot({ slotId, reassessValue: newValue })
// }
// If the user already exists in a different slot, forbid them from buying this one
const userExists = allSlots.find(
(u, index) => u.id === user?.id && index + 1 !== slot
)
const errorMsg = userExists
? 'Sell your other slot first (by revaluing it to M$ 0)'
: ''
async function onBuy() {
if (user) {
// Start transactions, but don't block
@ -187,7 +197,7 @@ export function BuySlotModal(props: {
onChange={(amount) =>
setNewValue(amount && amount >= 1 ? amount : 0)
}
error=""
error={errorMsg}
label={ENV_CONFIG.moneyMoniker}
/>
@ -200,7 +210,11 @@ export function BuySlotModal(props: {
</div>
) : (
<Col>
<button className="btn btn-primary" onClick={onBuy}>
<button
className="btn btn-primary"
onClick={onBuy}
disabled={!!errorMsg}
>
Buy Slot ({formatMoney(value)})
</button>
<div className="mt-2 text-sm">

View File

@ -156,7 +156,7 @@ export default function Manaboards(props: {
// If new value is 0, that's a sell; reset to topTrader
if (data.newValue === 0) {
slots[slot - 1] = topTraders[slot - 1]
values[slot - 1] = slot
values[slot - 1] = 50 - slot
createdTimes[slot - 1] = 0
}
}