()
return (
<>
{orderedGroups.map((group) => {
const contracts = groupContracts[group.slug].filter(
(c) =>
Math.abs(c.probChanges.day) >= 0.01 &&
!previouslySeenContracts.has(c.id)
)
if (contracts.length === 0) return null
contracts.forEach((c) => previouslySeenContracts.add(c.id))
return (
)
})}
>
)
}
function SectionHeader(props: {
label: string
href: string
children?: ReactNode
}) {
const { label, href, children } = props
return (
track('home click section header', { section: href })}
>
{label}{' '}
{children}
)
}
function SearchSection(props: {
label: string
contracts: CPMMBinaryContract[]
sort: Sort
pill?: string
showProbChange?: boolean
}) {
const { label, contracts, sort, pill, showProbChange } = props
return (
)
}
function GroupSection(props: {
group: Group
user: User
contracts: CPMMBinaryContract[]
}) {
const { group, user, contracts } = props
return (
)
}
function DailyMoversSection(props: {
contracts: CPMMBinaryContract[]
metrics: ContractMetrics[]
}) {
const { contracts, metrics } = props
if (contracts.length === 0) {
return null
}
return (
)
}
function DailyStats(props: { user: User | null | undefined }) {
const { user } = props
const privateUser = usePrivateUser()
const streaks = privateUser?.notificationPreferences?.betting_streaks ?? []
const streaksHidden = streaks.length === 0
return (
{!streaksHidden && (
Streak
🔥 {user?.currentBettingStreak ?? 0}
)}
)
}
export function DailyProfit(props: { user: User | null | undefined }) {
const { user } = props
const contractMetricsByProfit = useUserContractMetricsByProfit(
user?.id ?? '_',
100
)
const profit = sum(
contractMetricsByProfit?.metrics.map((m) =>
m.from ? m.from.day.profit : 0
) ?? []
)
const metrics = usePortfolioHistory(user?.id ?? '', 'daily') ?? []
const [first, last] = [metrics[0], metrics[metrics.length - 1]]
let profitPercent = 0
if (first && last) {
// profit = calculatePortfolioProfit(last) - calculatePortfolioProfit(first)
profitPercent = profit / first.investmentValue
}
return (
Daily profit
{formatMoney(profit)}{' '}
)
}
export function TrendingGroupsSection(props: {
user: User
myGroups: Group[]
trendingGroups: Group[]
className?: string
}) {
const { user, myGroups, trendingGroups, className } = props
const myGroupIds = new Set(myGroups.map((g) => g.id))
const groups = trendingGroups.filter((g) => !myGroupIds.has(g.id))
const count = 20
const chosenGroups = groups.slice(0, count)
if (chosenGroups.length === 0) {
return null
}
return (
Follow groups you are interested in.
{chosenGroups.map((g) => (
{
if (myGroupIds.has(g.id)) leaveGroup(g, user.id)
else {
const homeSections = (user.homeSections ?? [])
.filter((id) => id !== g.id)
.concat(g.id)
updateUser(user.id, { homeSections })
toast.promise(joinGroup(g, user.id), {
loading: 'Following group...',
success: `Followed ${g.name}`,
error: "Couldn't follow group, try again?",
})
track('home follow group', { group: g.slug })
}
}}
>
{g.name}
))}
)
}
function CustomizeButton(props: { justIcon?: boolean; className?: string }) {
const { justIcon, className } = props
return (
)
}