Filter out resolved markets from daily movers
This commit is contained in:
parent
546b0231e7
commit
9e4f41253f
|
@ -12,8 +12,9 @@ import { formatNumericProbability } from 'common/pseudo-numeric'
|
|||
export function ProfitChangeTable(props: {
|
||||
contracts: CPMMBinaryContract[]
|
||||
metrics: ContractMetrics[]
|
||||
maxRows?: number
|
||||
}) {
|
||||
const { contracts, metrics } = props
|
||||
const { contracts, metrics, maxRows } = props
|
||||
|
||||
const contractProfit = metrics.map(
|
||||
(m) => [m.contractId, m.from?.day.profit ?? 0] as const
|
||||
|
@ -27,7 +28,7 @@ export function ProfitChangeTable(props: {
|
|||
positiveProfit.map(([contractId]) =>
|
||||
contracts.find((c) => c.id === contractId)
|
||||
)
|
||||
)
|
||||
).slice(0, maxRows)
|
||||
|
||||
const negativeProfit = sortBy(
|
||||
contractProfit.filter(([, profit]) => profit < 0),
|
||||
|
@ -37,7 +38,7 @@ export function ProfitChangeTable(props: {
|
|||
negativeProfit.map(([contractId]) =>
|
||||
contracts.find((c) => c.id === contractId)
|
||||
)
|
||||
)
|
||||
).slice(0, maxRows)
|
||||
|
||||
if (positive.length === 0 && negative.length === 0)
|
||||
return <div className="px-4 text-gray-500">None</div>
|
||||
|
|
|
@ -47,10 +47,7 @@ export const usePrefetchUsers = (userIds: string[]) => {
|
|||
)
|
||||
}
|
||||
|
||||
export const useUserContractMetricsByProfit = (
|
||||
userId: string,
|
||||
count: number
|
||||
) => {
|
||||
export const useUserContractMetricsByProfit = (userId: string, count = 50) => {
|
||||
const positiveResult = useFirestoreQueryData<ContractMetrics>(
|
||||
['contract-metrics-descending', userId, count],
|
||||
getUserContractMetricsQuery(userId, count, 'desc')
|
||||
|
@ -71,10 +68,13 @@ export const useUserContractMetricsByProfit = (
|
|||
if (!positiveResult.data || !negativeResult.data || !contracts)
|
||||
return undefined
|
||||
|
||||
const filteredContracts = filterDefined(contracts) as CPMMBinaryContract[]
|
||||
const filteredMetrics = metrics.filter(
|
||||
(m) => m.from && Math.abs(m.from.day.profit) >= 0.5
|
||||
)
|
||||
const filteredContracts = filterDefined(contracts).filter(
|
||||
(c) => !c.isResolved
|
||||
) as CPMMBinaryContract[]
|
||||
const filteredMetrics = metrics
|
||||
.filter((m) => m.from && Math.abs(m.from.day.profit) >= 0.5)
|
||||
.filter((m) => filteredContracts.find((c) => c.id === m.contractId))
|
||||
|
||||
return { contracts: filteredContracts, metrics: filteredMetrics }
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ export default function DailyMovers() {
|
|||
function ProbChangesWrapper(props: { userId: string }) {
|
||||
const { userId } = props
|
||||
|
||||
const data = useUserContractMetricsByProfit(userId, 50)
|
||||
const data = useUserContractMetricsByProfit(userId)
|
||||
|
||||
if (!data) return <LoadingIndicator />
|
||||
|
||||
|
|
|
@ -95,8 +95,7 @@ export default function Home() {
|
|||
}, [user, sections])
|
||||
|
||||
const contractMetricsByProfit = useUserContractMetricsByProfit(
|
||||
user?.id ?? '_',
|
||||
3
|
||||
user?.id ?? '_'
|
||||
)
|
||||
|
||||
const trendingContracts = useTrendingContracts(6)
|
||||
|
@ -494,7 +493,7 @@ function DailyMoversSection(props: {
|
|||
return (
|
||||
<Col className="gap-2">
|
||||
<SectionHeader label="Daily movers" href="/daily-movers" />
|
||||
<ProfitChangeTable contracts={contracts} metrics={metrics} />
|
||||
<ProfitChangeTable contracts={contracts} metrics={metrics} maxRows={3} />
|
||||
</Col>
|
||||
)
|
||||
}
|
||||
|
@ -530,8 +529,7 @@ export function DailyProfit(props: { user: User | null | undefined }) {
|
|||
const { user } = props
|
||||
|
||||
const contractMetricsByProfit = useUserContractMetricsByProfit(
|
||||
user?.id ?? '_',
|
||||
100
|
||||
user?.id ?? '_'
|
||||
)
|
||||
const profit = sum(
|
||||
contractMetricsByProfit?.metrics.map((m) =>
|
||||
|
|
Loading…
Reference in New Issue
Block a user