Update limit to 3 slots at a time

This commit is contained in:
Austin Chen 2022-04-01 10:59:54 -07:00
parent d2ed6f745e
commit aa37d3afde

View File

@ -135,14 +135,18 @@ export function BuySlotModal(props: {
// await buyLeaderboardSlot({ slotId, reassessValue: newValue }) // await buyLeaderboardSlot({ slotId, reassessValue: newValue })
// } // }
// If the user already exists in a different slot, forbid them from buying this one // Find all slots the user currently owns
const userExists = allSlots.find( const existingSlots = []
(u, index) => u.id === user?.id && index + 1 !== slot for (let i = 0; i < allSlots.length; i++) {
) if (allSlots[i].id === user?.id) {
// Hm, existing leaderboard users may not be able to participate atm. existingSlots.push(i + 1)
const errorMsg = userExists }
? 'Sell your other slot first (by revaluing it to M$ 0)' }
: '' // Prevent them from holding more than three slots at once
let errorMsg = ''
if (existingSlots.length >= 3 && !existingSlots.includes(slot)) {
errorMsg = 'Sell another slot first (by re-valuing it to M$ 0)'
}
async function onBuy() { async function onBuy() {
if (user) { if (user) {