Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
115 lines
4.1 KiB
TypeScript
115 lines
4.1 KiB
TypeScript
import { Contract } from 'common/contract'
|
|
import { getContractFromSlug } from 'common/supabase/contracts'
|
|
import { initSupabaseAdmin } from 'web/lib/supabase/admin-db'
|
|
import {
|
|
ElectionsPageProps,
|
|
MapContractsDictionary,
|
|
MIDTERMS_2026,
|
|
PRESIDENT_2028_SLUG,
|
|
PRESIDENT_2028_PARTY_SLUG,
|
|
PRIMARIES_2026,
|
|
REDISTRICTING_2026,
|
|
StateElectionMarket,
|
|
} from 'web/public/data/elections-data'
|
|
import {
|
|
governors2026,
|
|
governorCandidates2026,
|
|
} from 'web/public/data/governors-data'
|
|
import {
|
|
senate2026,
|
|
senateCandidates2026,
|
|
} from 'web/public/data/senate-state-data'
|
|
import { api } from 'web/lib/api/api'
|
|
import { getDashboardProps } from 'web/lib/politics/news-dashboard'
|
|
|
|
export async function getElectionsPageProps(): Promise<ElectionsPageProps> {
|
|
const adminDb = await initSupabaseAdmin()
|
|
const getContractFromSlugFunction = (slug: string) =>
|
|
getContractFromSlug(adminDb, slug)
|
|
|
|
const [
|
|
senateStateContracts,
|
|
governorStateContracts,
|
|
senateCandidateContracts,
|
|
governorCandidateContracts,
|
|
headlines,
|
|
balanceOfPowerContract,
|
|
houseControlContract,
|
|
senateControlContract,
|
|
houseDistrictsContract,
|
|
presidency2028Contract,
|
|
presidency2028PartyContract,
|
|
primaryContractsRaw,
|
|
redistrictingContractsRaw,
|
|
] = await Promise.all([
|
|
getStateContracts(getContractFromSlugFunction, senate2026),
|
|
getStateContracts(getContractFromSlugFunction, governors2026),
|
|
getStateContracts(getContractFromSlugFunction, senateCandidates2026),
|
|
getStateContracts(getContractFromSlugFunction, governorCandidates2026),
|
|
api('headlines', { slug: 'politics' }),
|
|
getContractFromSlugFunction(MIDTERMS_2026.balanceOfPower),
|
|
getContractFromSlugFunction(MIDTERMS_2026.houseControl),
|
|
getContractFromSlugFunction(MIDTERMS_2026.senateControl),
|
|
getContractFromSlugFunction(MIDTERMS_2026.houseDistricts),
|
|
getContractFromSlugFunction(PRESIDENT_2028_SLUG),
|
|
getContractFromSlugFunction(PRESIDENT_2028_PARTY_SLUG),
|
|
Promise.all(PRIMARIES_2026.map(getContractFromSlugFunction)),
|
|
Promise.all(REDISTRICTING_2026.map(getContractFromSlugFunction)),
|
|
])
|
|
|
|
// Keep only primaries that still exist and are open (so the watch-list shrinks
|
|
// gracefully as races resolve, rather than showing stale/settled markets).
|
|
const primaryContracts = primaryContractsRaw.filter(
|
|
(c): c is Contract => !!c && !c.isResolved && !c.resolution
|
|
)
|
|
|
|
// Same for redistricting markets — open only, so settled questions drop off.
|
|
const redistrictingContracts = redistrictingContractsRaw.filter(
|
|
(c): c is Contract => !!c && !c.isResolved && !c.resolution
|
|
)
|
|
|
|
const newsDashboards = await Promise.all(
|
|
headlines.map(async (headline) => getDashboardProps(headline.slug))
|
|
)
|
|
|
|
const trendingDashboard = await getDashboardProps('politicsheadline')
|
|
|
|
return {
|
|
presidency2028Contract,
|
|
presidency2028PartyContract,
|
|
rawSenateStateContracts: senateStateContracts,
|
|
rawGovernorStateContracts: governorStateContracts,
|
|
rawSenateCandidateContracts: senateCandidateContracts,
|
|
rawGovernorCandidateContracts: governorCandidateContracts,
|
|
balanceOfPowerContract,
|
|
houseControlContract,
|
|
senateControlContract,
|
|
houseDistrictsContract,
|
|
primaryContracts,
|
|
redistrictingContracts,
|
|
newsDashboards,
|
|
headlines,
|
|
trendingDashboard,
|
|
}
|
|
}
|
|
|
|
async function getStateContracts(
|
|
getContract: (slug: string) => Promise<Contract | null>,
|
|
stateSlugs: StateElectionMarket[]
|
|
): Promise<MapContractsDictionary> {
|
|
const mapContractsPromises = stateSlugs.map(async (m) => {
|
|
const contract = await getContract(m.slug)
|
|
return { state: m.state, contract: contract }
|
|
})
|
|
|
|
const mapContractsArray = await Promise.all(mapContractsPromises)
|
|
|
|
// Convert array to dictionary, dropping states whose community market has
|
|
// gone missing (deleted/renamed). The map renders those states uncolored
|
|
// rather than crashing on a null contract in useLiveContract.
|
|
return mapContractsArray.reduce((acc, mapContract) => {
|
|
if (mapContract.contract) acc[mapContract.state] = mapContract.contract
|
|
return acc
|
|
}, {} as MapContractsDictionary)
|
|
}
|