Set limits on bets and contracts loaded for portfolio page. Show warning if limit is hit
This commit is contained in:
parent
9e289146af
commit
8f56ccad22
|
@ -4,7 +4,7 @@ import dayjs from 'dayjs'
|
||||||
import { useMemo, useState } from 'react'
|
import { useMemo, useState } from 'react'
|
||||||
import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/solid'
|
import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/solid'
|
||||||
|
|
||||||
import { Bet } from 'web/lib/firebase/bets'
|
import { Bet, MAX_USER_BETS_LOADED } from 'web/lib/firebase/bets'
|
||||||
import { User } from 'web/lib/firebase/users'
|
import { User } from 'web/lib/firebase/users'
|
||||||
import {
|
import {
|
||||||
formatMoney,
|
formatMoney,
|
||||||
|
@ -17,6 +17,7 @@ import {
|
||||||
Contract,
|
Contract,
|
||||||
contractPath,
|
contractPath,
|
||||||
getBinaryProbPercent,
|
getBinaryProbPercent,
|
||||||
|
MAX_USER_BET_CONTRACTS_LOADED,
|
||||||
} from 'web/lib/firebase/contracts'
|
} from 'web/lib/firebase/contracts'
|
||||||
import { Row } from './layout/row'
|
import { Row } from './layout/row'
|
||||||
import { sellBet } from 'web/lib/firebase/api'
|
import { sellBet } from 'web/lib/firebase/api'
|
||||||
|
@ -50,6 +51,7 @@ import {
|
||||||
usePersistentState,
|
usePersistentState,
|
||||||
} from 'web/hooks/use-persistent-state'
|
} from 'web/hooks/use-persistent-state'
|
||||||
import { safeLocalStorage } from 'web/lib/util/local'
|
import { safeLocalStorage } from 'web/lib/util/local'
|
||||||
|
import { ExclamationIcon } from '@heroicons/react/outline'
|
||||||
|
|
||||||
type BetSort = 'newest' | 'profit' | 'closeTime' | 'value'
|
type BetSort = 'newest' | 'profit' | 'closeTime' | 'value'
|
||||||
type BetFilter = 'open' | 'limit_bet' | 'sold' | 'closed' | 'resolved' | 'all'
|
type BetFilter = 'open' | 'limit_bet' | 'sold' | 'closed' | 'resolved' | 'all'
|
||||||
|
@ -80,6 +82,10 @@ export function BetsList(props: { user: User }) {
|
||||||
return contractList ? keyBy(contractList, 'id') : undefined
|
return contractList ? keyBy(contractList, 'id') : undefined
|
||||||
}, [contractList])
|
}, [contractList])
|
||||||
|
|
||||||
|
const loadedPartialData =
|
||||||
|
userBets?.length === MAX_USER_BETS_LOADED ||
|
||||||
|
contractList?.length === MAX_USER_BET_CONTRACTS_LOADED
|
||||||
|
|
||||||
const [sort, setSort] = usePersistentState<BetSort>('newest', {
|
const [sort, setSort] = usePersistentState<BetSort>('newest', {
|
||||||
key: 'bets-list-sort',
|
key: 'bets-list-sort',
|
||||||
store: storageStore(safeLocalStorage()),
|
store: storageStore(safeLocalStorage()),
|
||||||
|
@ -167,6 +173,13 @@ export function BetsList(props: { user: User }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col>
|
<Col>
|
||||||
|
{loadedPartialData && (
|
||||||
|
<Row className="my-4 items-center gap-2 self-start rounded bg-yellow-50 p-4">
|
||||||
|
<ExclamationIcon className="h-5 w-5" />
|
||||||
|
<div>Partial trade data only</div>
|
||||||
|
</Row>
|
||||||
|
)}
|
||||||
|
|
||||||
<Col className="justify-between gap-4 sm:flex-row">
|
<Col className="justify-between gap-4 sm:flex-row">
|
||||||
<Row className="gap-4">
|
<Row className="gap-4">
|
||||||
<Col>
|
<Col>
|
||||||
|
|
|
@ -74,11 +74,13 @@ export async function getUserBets(userId: string) {
|
||||||
return getValues<Bet>(getUserBetsQuery(userId))
|
return getValues<Bet>(getUserBetsQuery(userId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const MAX_USER_BETS_LOADED = 10000
|
||||||
export function getUserBetsQuery(userId: string) {
|
export function getUserBetsQuery(userId: string) {
|
||||||
return query(
|
return query(
|
||||||
collectionGroup(db, 'bets'),
|
collectionGroup(db, 'bets'),
|
||||||
where('userId', '==', userId),
|
where('userId', '==', userId),
|
||||||
orderBy('createdTime', 'desc')
|
orderBy('createdTime', 'desc'),
|
||||||
|
limit(MAX_USER_BETS_LOADED)
|
||||||
) as Query<Bet>
|
) as Query<Bet>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,10 +168,12 @@ export function getUserBetContracts(userId: string) {
|
||||||
return getValues<Contract>(getUserBetContractsQuery(userId))
|
return getValues<Contract>(getUserBetContractsQuery(userId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const MAX_USER_BET_CONTRACTS_LOADED = 1000
|
||||||
export function getUserBetContractsQuery(userId: string) {
|
export function getUserBetContractsQuery(userId: string) {
|
||||||
return query(
|
return query(
|
||||||
contracts,
|
contracts,
|
||||||
where('uniqueBettorIds', 'array-contains', userId)
|
where('uniqueBettorIds', 'array-contains', userId),
|
||||||
|
limit(MAX_USER_BET_CONTRACTS_LOADED)
|
||||||
) as Query<Contract>
|
) as Query<Contract>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user