Store values as well
This commit is contained in:
parent
709ddfa7a9
commit
37d5d5fc93
|
@ -17,10 +17,11 @@ import { Title } from './title'
|
||||||
export function Manaboard(props: {
|
export function Manaboard(props: {
|
||||||
title: string
|
title: string
|
||||||
users: User[]
|
users: User[]
|
||||||
|
values: number[]
|
||||||
className?: string
|
className?: string
|
||||||
}) {
|
}) {
|
||||||
// TODO: Ideally, highlight your own entry on the leaderboard
|
// TODO: Ideally, highlight your own entry on the leaderboard
|
||||||
const { title, users, className } = props
|
const { title, users, className, values } = props
|
||||||
return (
|
return (
|
||||||
<div className={clsx('w-full px-1', className)}>
|
<div className={clsx('w-full px-1', className)}>
|
||||||
<Title text={title} className="!mt-0" />
|
<Title text={title} className="!mt-0" />
|
||||||
|
@ -53,12 +54,12 @@ export function Manaboard(props: {
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<Row className="items-center gap-4">
|
<Row className="items-center gap-4">
|
||||||
{formatMoney(100 - 5 * index)}
|
{formatMoney(values[index])}
|
||||||
<BuySlotModal
|
<BuySlotModal
|
||||||
slot={index + 1}
|
slot={index + 1}
|
||||||
title={`${title}`}
|
title={`${title}`}
|
||||||
holder={user}
|
holder={user}
|
||||||
value={100 - 5 * index}
|
value={values[index]}
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
</td>
|
</td>
|
||||||
|
@ -138,7 +139,14 @@ export function BuySlotModal(props: {
|
||||||
className="btn btn-primary"
|
className="btn btn-primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (user) {
|
if (user) {
|
||||||
buySlot({ holder, buyer: user, amount: value, slot, message })
|
buySlot({
|
||||||
|
holder,
|
||||||
|
buyer: user,
|
||||||
|
amount: value,
|
||||||
|
slot,
|
||||||
|
message,
|
||||||
|
newValue,
|
||||||
|
})
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@ -166,8 +174,9 @@ async function buySlot(options: {
|
||||||
amount: number
|
amount: number
|
||||||
slot: number
|
slot: number
|
||||||
message: string
|
message: string
|
||||||
|
newValue: number
|
||||||
}) {
|
}) {
|
||||||
const { holder, buyer, amount, slot, message } = options
|
const { holder, buyer, amount, slot, message, newValue } = options
|
||||||
const createdTime = Date.now()
|
const createdTime = Date.now()
|
||||||
const buyTransaction: Transaction = {
|
const buyTransaction: Transaction = {
|
||||||
id: '',
|
id: '',
|
||||||
|
@ -190,6 +199,7 @@ async function buySlot(options: {
|
||||||
data: {
|
data: {
|
||||||
slot,
|
slot,
|
||||||
message,
|
message,
|
||||||
|
newValue,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,13 @@ export type Transaction = {
|
||||||
data?: SlotData | TaxData
|
data?: SlotData | TaxData
|
||||||
}
|
}
|
||||||
|
|
||||||
type SlotData = {
|
export type SlotData = {
|
||||||
slot: number
|
slot: number
|
||||||
|
newValue: number
|
||||||
message: string
|
message: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaxData = {
|
export type TaxData = {
|
||||||
slot: number
|
slot: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { fromPropz, usePropz } from '../hooks/use-propz'
|
||||||
import { Manaboard } from '../components/manaboard'
|
import { Manaboard } from '../components/manaboard'
|
||||||
import { Title } from '../components/title'
|
import { Title } from '../components/title'
|
||||||
import { useTransactions } from '../hooks/use-transactions'
|
import { useTransactions } from '../hooks/use-transactions'
|
||||||
import { Transaction } from '../lib/firebase/transactions'
|
import { SlotData, Transaction } from '../lib/firebase/transactions'
|
||||||
|
|
||||||
export const getStaticProps = fromPropz(getStaticPropz)
|
export const getStaticProps = fromPropz(getStaticPropz)
|
||||||
export async function getStaticPropz() {
|
export async function getStaticPropz() {
|
||||||
|
@ -110,6 +110,10 @@ export default function Manaboards(props: {
|
||||||
}
|
}
|
||||||
const { topTraders, topCreators } = props
|
const { topTraders, topCreators } = props
|
||||||
|
|
||||||
|
const values = Array.from(Array(topTraders.length).keys())
|
||||||
|
.map((i) => i + 1)
|
||||||
|
.reverse()
|
||||||
|
|
||||||
// Find the most recent purchases of each slot, and replace the entries in topTraders
|
// Find the most recent purchases of each slot, and replace the entries in topTraders
|
||||||
const transactions = useTransactions() ?? []
|
const transactions = useTransactions() ?? []
|
||||||
// Iterate from oldest to newest transactions, so recent purchases overwrite older ones
|
// Iterate from oldest to newest transactions, so recent purchases overwrite older ones
|
||||||
|
@ -117,13 +121,13 @@ export default function Manaboards(props: {
|
||||||
for (const txn of sortedTxns) {
|
for (const txn of sortedTxns) {
|
||||||
if (txn.category === 'BUY_LEADERBOARD_SLOT') {
|
if (txn.category === 'BUY_LEADERBOARD_SLOT') {
|
||||||
const buyer = userFromBuy(txn)
|
const buyer = userFromBuy(txn)
|
||||||
const slot = txn.data?.slot ?? 0
|
const data = txn.data as SlotData
|
||||||
|
const slot = data.slot
|
||||||
topTraders[slot - 1] = buyer
|
topTraders[slot - 1] = buyer
|
||||||
|
values[slot - 1] = data.newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('sorted txn', sortedTxns)
|
|
||||||
|
|
||||||
function userFromBuy(txn: Transaction): User {
|
function userFromBuy(txn: Transaction): User {
|
||||||
return {
|
return {
|
||||||
id: txn.fromId,
|
id: txn.fromId,
|
||||||
|
@ -159,7 +163,7 @@ export default function Manaboards(props: {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Col className="mt-6 items-center gap-10">
|
<Col className="mt-6 items-center gap-10">
|
||||||
<Manaboard title="" users={topTraders} />
|
<Manaboard title="" users={topTraders} values={values} />
|
||||||
{/* <Manaboard title="🏅 Top creators" users={topCreators} /> */}
|
{/* <Manaboard title="🏅 Top creators" users={topCreators} /> */}
|
||||||
</Col>
|
</Col>
|
||||||
</Page>
|
</Page>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user