Honestly, we're as puzzled as you are. Leading theories include:
Leaky abstractions in our manabase
One too many floating-point rounding errors
Our newest user Robert');DROP TABLE Balances;--
We'd be happy to pay a bounty to anyone who can help us solve this
riddle! Oh wait...
)
}
// TODOs
// [ ] Expandable text for explainer
// [ ] Draw attention to leaderboard
// [ ] Restrict to at most buying one slot per user?
export default function Manaboards(props: {
topTraders: User[]
topCreators: User[]
}) {
props = usePropz(props, getStaticPropz) ?? {
topTraders: [],
topCreators: [],
}
const { topTraders, topCreators } = props
const slots = _.clone(topTraders)
const user = useUser()
const values = Array.from(Array(slots.length).keys())
.map((i) => i + 1)
.reverse()
const createdTimes = new Array(slots.length).fill(0)
// Find the most recent purchases of each slot, and replace the entries in slots
const txns = useTransactions() ?? []
// Iterate from oldest to newest transactions, so recent purchases overwrite older ones
const sortedTxns = _.sortBy(txns, 'createdTime')
for (const txn of sortedTxns) {
if (txn.category === 'BUY_LEADERBOARD_SLOT') {
const buyer = userFromBuy(txn)
const data = txn.data as SlotData
const slot = data.slot
slots[slot - 1] = buyer
values[slot - 1] = data.newValue
createdTimes[slot - 1] = txn.createdTime
// 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] = 50 - slot
createdTimes[slot - 1] = 0
}
}
}
function userFromBuy(txn: Transaction): User {
return {
id: txn.fromId,
// @ts-ignore
name: txn.data?.message ?? txn.fromName,
username: txn.fromUsername,
avatarUrl: txn.fromAvatarUrl,
// Dummy data which shouldn't be relied on
createdTime: 0,
creatorVolumeCached: 0,
totalPnLCached: 0,
balance: 0,
totalDeposits: 0,
}
}
const MANIFOLD_ID = 'IPTOzEqrpkWmEzh6hwvAyY9PqFb2'
if (user?.balance) {
saveFakeBalance(userProfits(user.id, txns) + user.balance)
}
const [expandInfo, setExpandInfo] = useState(false)
return (
}>
{/*
*/}
Manafold Markets is running out of mana... so we're selling our
leaderboard slots to recoup our losses. Buy one now to earn fleeting
glory and keep Manafold afloat!
Mana replenished: {formatMoney(userProfits(MANIFOLD_ID, txns))}
{expandInfo && }
{/* */}
{user && (
Your earnings: {formatMoney(userProfits(user.id, txns))}