([])
const posts = useAllPosts()
const globalConfig = useGlobalConfig()
useEffect(() => {
const pinnedItems = globalConfig?.pinnedItems
async function getPinned() {
if (pinnedItems == null) {
if (globalConfig != null) {
updateGlobalConfig(globalConfig, { pinnedItems: [] })
}
} else {
const itemComponents = await Promise.all(
pinnedItems.map(async (element) => {
if (element.type === 'post') {
const post = await getPost(element.itemId)
if (post) {
return
}
} else if (element.type === 'contract') {
const contract = await getContractFromId(element.itemId)
if (contract) {
return
}
}
})
)
setPinned(
itemComponents.filter(
(element) => element != undefined
) as JSX.Element[]
)
}
}
getPinned()
}, [globalConfig])
async function onSubmit(selectedItems: { itemId: string; type: string }[]) {
if (globalConfig == null) return
await updateGlobalConfig(globalConfig, {
pinnedItems: [
...(globalConfig?.pinnedItems ?? []),
...(selectedItems as { itemId: string; type: 'contract' | 'post' }[]),
],
})
}
function onDeleteClicked(index: number) {
if (globalConfig == null) return
const newPinned = globalConfig.pinnedItems.filter((item) => {
return item.itemId !== globalConfig.pinnedItems[index].itemId
})
updateGlobalConfig(globalConfig, { pinnedItems: newPinned })
}
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 (
)
}