From 68fb5b578c5ad3ea12947d02e93c2938a9bab5ab Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Fri, 1 Apr 2022 09:24:33 -0700 Subject: [PATCH] Restrict to buying 1 slot at a time --- web/components/manaboard.tsx | 20 +++++++++++++++++--- web/pages/leaderboards.tsx | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/web/components/manaboard.tsx b/web/components/manaboard.tsx index 08fa126c..2e7376c0 100644 --- a/web/components/manaboard.tsx +++ b/web/components/manaboard.tsx @@ -84,6 +84,7 @@ export function Manaboard(props: { holder={user} value={values[index]} createdTime={createdTimes[index]} + allSlots={users} /> @@ -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: { ) : ( -
diff --git a/web/pages/leaderboards.tsx b/web/pages/leaderboards.tsx index 09281bb3..c8989dd9 100644 --- a/web/pages/leaderboards.tsx +++ b/web/pages/leaderboards.tsx @@ -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 } }