diff --git a/web/components/manaboard.tsx b/web/components/manaboard.tsx
index e4791353..e230116b 100644
--- a/web/components/manaboard.tsx
+++ b/web/components/manaboard.tsx
@@ -5,7 +5,11 @@ import { User } from '../../common/user'
import { formatMoney } from '../../common/util/format'
import { useUser } from '../hooks/use-user'
import { buyLeaderboardSlot } from '../lib/firebase/api-call'
-import { Transaction, writeTransaction } from '../lib/firebase/transactions'
+import {
+ SlotData,
+ Transaction,
+ writeTransaction,
+} from '../lib/firebase/transactions'
import { AmountInput } from './amount-input'
import { Avatar } from './avatar'
import { Col } from './layout/col'
@@ -18,10 +22,11 @@ export function Manaboard(props: {
title: string
users: User[]
values: number[]
+ createdTimes: number[]
className?: string
}) {
// TODO: Ideally, highlight your own entry on the leaderboard
- let { title, users, className, values } = props
+ let { title, users, className, values, createdTimes } = props
const [expanded, setExpanded] = useState(false)
if (!expanded) {
@@ -67,6 +72,7 @@ export function Manaboard(props: {
title={`${title}`}
holder={user}
value={values[index]}
+ createdTime={createdTimes[index]}
/>
@@ -96,8 +102,9 @@ export function BuySlotModal(props: {
holder: User
slot: number
value: number
+ createdTime: number
}) {
- const { slot, title, holder, value } = props
+ const { slot, title, holder, value, createdTime } = props
const user = useUser()
const [open, setOpen] = useState(false)
@@ -109,10 +116,29 @@ export function BuySlotModal(props: {
}
}, [user])
- const onBuy = async () => {
- // Feel free to change this. - James
- const slotId = `${title}-${slot}`
- await buyLeaderboardSlot({ slotId, reassessValue: newValue })
+ // const onBuy = async () => {
+ // // Feel free to change this. - James
+ // const slotId = `${title}-${slot}`
+ // await buyLeaderboardSlot({ slotId, reassessValue: newValue })
+ // }
+
+ async function onBuy() {
+ if (user) {
+ // Start transactions, but don't block
+ const buyData = { slot, newValue, message }
+ const buyTxn = buyTransaction({
+ buyer: user,
+ holder,
+ amount: value,
+ buyData,
+ })
+ await Promise.all([
+ writeTransaction(buyTxn),
+ writeTransaction(taxTransaction({ holder, slot, value, createdTime })),
+ ])
+
+ setOpen(false)
+ }
}
return (
@@ -148,22 +174,7 @@ export function BuySlotModal(props: {
label={ENV_CONFIG.moneyMoniker}
/>
-
-
-
+
+
{/* */}
+
+
+
+
+
)
}
+
+function TransactionsTable(props: { txns: Transaction[] }) {
+ const { txns } = props
+ return (
+ (cell as SlotData).slot,
+ },
+ {
+ id: 'category',
+ name: 'Type',
+ formatter: (cell) =>
+ cell === 'BUY_LEADERBOARD_SLOT' ? 'Buy' : 'Tax',
+ },
+ {
+ id: 'amount',
+ name: 'Amount',
+ formatter: (cell) => formatMoney(cell as number),
+ },
+ {
+ id: 'fromUsername',
+ name: 'From',
+ },
+ { id: 'toUsername', name: 'To' },
+ {
+ id: 'createdTime',
+ name: 'Time',
+ formatter: (cell) =>
+ html(
+ `${dayjs(cell as number).format(
+ 'h:mma'
+ )}`
+ ),
+ },
+ ]}
+ />
+ )
+}