From 9b50d6731375b6aa10b3c401a72e2c169ade9e0b Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 10 Feb 2022 14:36:15 -0600 Subject: [PATCH 1/6] Render graph with bets from static props immediately --- web/components/contract-overview.tsx | 2 +- web/components/contract-prob-graph.tsx | 22 +++++++++++----------- web/hooks/use-bets.ts | 20 +++++++++++++++++++- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/web/components/contract-overview.tsx b/web/components/contract-overview.tsx index 3528a727..abee76f2 100644 --- a/web/components/contract-overview.tsx +++ b/web/components/contract-overview.tsx @@ -86,7 +86,7 @@ export const ContractOverview = (props: { - + {folds.length === 0 ? ( diff --git a/web/components/contract-prob-graph.tsx b/web/components/contract-prob-graph.tsx index fceffd97..13e6c48d 100644 --- a/web/components/contract-prob-graph.tsx +++ b/web/components/contract-prob-graph.tsx @@ -1,26 +1,26 @@ import { DatumValue } from '@nivo/core' import { ResponsiveLine } from '@nivo/line' import dayjs from 'dayjs' +import { Bet } from '../../common/bet' import { getProbability } from '../../common/calculate' -import { useBets } from '../hooks/use-bets' +import { useBetsWithoutAntes } from '../hooks/use-bets' import { useWindowSize } from '../hooks/use-window-size' -import { withoutAnteBets } from '../lib/firebase/bets' import { Contract } from '../lib/firebase/contracts' -export function ContractProbGraph(props: { contract: Contract }) { +export function ContractProbGraph(props: { contract: Contract; bets: Bet[] }) { const { contract } = props - const { id, phantomShares, resolutionTime, closeTime } = contract + const { phantomShares, resolutionTime, closeTime } = contract - let bets = useBets(id) ?? [] - bets = withoutAnteBets(contract, bets) + const bets = useBetsWithoutAntes(contract, props.bets) const startProb = getProbability(phantomShares) - const times = [ - contract.createdTime, - ...bets.map((bet) => bet.createdTime), - ].map((time) => new Date(time)) - const probs = [startProb, ...bets.map((bet) => bet.probAfter)] + const times = bets + ? [contract.createdTime, ...bets.map((bet) => bet.createdTime)].map( + (time) => new Date(time) + ) + : [] + const probs = bets ? [startProb, ...bets.map((bet) => bet.probAfter)] : [] const isClosed = !!closeTime && Date.now() > closeTime const latestTime = dayjs( diff --git a/web/hooks/use-bets.ts b/web/hooks/use-bets.ts index 6ab9eb21..4d892ff6 100644 --- a/web/hooks/use-bets.ts +++ b/web/hooks/use-bets.ts @@ -1,5 +1,6 @@ import { useEffect, useState } from 'react' -import { Bet, listenForBets } from '../lib/firebase/bets' +import { Contract } from '../../common/contract' +import { Bet, listenForBets, withoutAnteBets } from '../lib/firebase/bets' export const useBets = (contractId: string) => { const [bets, setBets] = useState() @@ -10,3 +11,20 @@ export const useBets = (contractId: string) => { return bets } + +export const useBetsWithoutAntes = ( + contract: Contract, + initialBets?: Bet[] +) => { + const [bets, setBets] = useState( + withoutAnteBets(contract, initialBets) + ) + + useEffect(() => { + return listenForBets(contract.id, (bets) => { + setBets(withoutAnteBets(contract, bets)) + }) + }, [contract]) + + return bets +} From 00fbe711e5cd7602268b1fbfd4ecb171dd857bc6 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 10 Feb 2022 14:51:14 -0600 Subject: [PATCH 2/6] Only show leaderboard scores that round up to M$ 1 or more --- web/pages/fold/[...slugs]/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/pages/fold/[...slugs]/index.tsx b/web/pages/fold/[...slugs]/index.tsx index b086efe6..f6d53c2c 100644 --- a/web/pages/fold/[...slugs]/index.tsx +++ b/web/pages/fold/[...slugs]/index.tsx @@ -116,7 +116,7 @@ async function toTopUsers(userScores: { [userId: string]: number }) { const topUserPairs = _.take( _.sortBy(Object.entries(userScores), ([_, score]) => -1 * score), 10 - ).filter(([_, score]) => score > 0) + ).filter(([_, score]) => score >= 0.5) const topUsers = await Promise.all( topUserPairs.map(([userId]) => getUser(userId)) From 4150479aa39c7caeadbeaa63fc0a0a848bf14d7e Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 10 Feb 2022 14:57:41 -0600 Subject: [PATCH 3/6] Break words and linkify fold about text --- web/pages/fold/[...slugs]/index.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/pages/fold/[...slugs]/index.tsx b/web/pages/fold/[...slugs]/index.tsx index f6d53c2c..245c5dcb 100644 --- a/web/pages/fold/[...slugs]/index.tsx +++ b/web/pages/fold/[...slugs]/index.tsx @@ -39,6 +39,7 @@ import { FollowFoldButton } from '../../../components/follow-fold-button' import FeedCreate from '../../../components/feed-create' import { SEO } from '../../../components/SEO' import { useTaggedContracts } from '../../../hooks/use-contracts' +import { Linkify } from '../../../components/linkify' export async function getStaticProps(props: { params: { slugs: string[] } }) { const { slugs } = props.params @@ -204,7 +205,7 @@ export default function FoldPage(props: { username={curator.username} /> -
{fold.about}
+ @@ -329,7 +330,9 @@ function FoldOverview(props: { fold: Fold; curator: User }) { {about && ( <> -
{about}
+
+ +
)} From d02611a37ab8f8fb247a203ee73e255cfcfb5727 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 10 Feb 2022 16:35:20 -0600 Subject: [PATCH 4/6] Add id field to markets api endpoint --- functions/src/markets.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions/src/markets.ts b/functions/src/markets.ts index 6d6380c1..f9188987 100644 --- a/functions/src/markets.ts +++ b/functions/src/markets.ts @@ -25,6 +25,7 @@ export const markets = functions }) const getContractInfo = ({ + id, creatorUsername, creatorName, createdTime, @@ -40,6 +41,7 @@ const getContractInfo = ({ resolution, }: Contract) => { return { + id, creatorUsername, creatorName, createdTime, From dc0c9cf1d441984b0cca64729e85fd927a935cbf Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 10 Feb 2022 17:06:27 -0600 Subject: [PATCH 5/6] Filter undefined contracts --- web/pages/activity.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web/pages/activity.tsx b/web/pages/activity.tsx index be5a9809..c118b9ee 100644 --- a/web/pages/activity.tsx +++ b/web/pages/activity.tsx @@ -5,6 +5,7 @@ import { Contract } from '../lib/firebase/contracts' import { Comment } from '../lib/firebase/comments' import { Col } from '../components/layout/col' import { Bet } from '../../common/bet' +import { filterDefined } from '../../common/util/array' const MAX_ACTIVE_CONTRACTS = 75 const MAX_HOT_MARKETS = 10 @@ -64,12 +65,13 @@ export function findActiveContracts( const contractTotalBets = _.mapValues(contractBets, (bets) => _.sumBy(bets, (bet) => bet.amount) ) - const topTradedContracts = _.sortBy( + const sortedPairs = _.sortBy( _.toPairs(contractTotalBets), ([_, total]) => -1 * total ) - .map(([id]) => contractsById.get(id) as Contract) - .slice(0, MAX_HOT_MARKETS) + const topTradedContracts = filterDefined( + sortedPairs.map(([id]) => contractsById.get(id)) + ).slice(0, MAX_HOT_MARKETS) for (const contract of topTradedContracts) { const bet = recentBets.find((bet) => bet.contractId === contract.id) From 7338bdd47aae4b37f76c71d6eccbdf30410693c7 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Fri, 11 Feb 2022 10:40:22 -0800 Subject: [PATCH 6/6] Automatically sort Tailwind classes with Prettier (#45) * Add Prettier Tailwind plugin * Autoformat Tailwind classes with Prettier --- web/components/add-funds-button.tsx | 12 +++++----- web/components/advanced-panel.tsx | 8 +++---- web/components/amount-input.tsx | 8 +++---- web/components/avatar.tsx | 4 ++-- web/components/bet-panel.tsx | 8 +++---- web/components/bet-row.tsx | 12 +++++----- web/components/bets-list.tsx | 22 ++++++++--------- web/components/contract-card.tsx | 16 ++++++------- web/components/contract-feed.tsx | 26 ++++++++++---------- web/components/contract-overview.tsx | 12 +++++----- web/components/contracts-list.tsx | 6 ++--- web/components/create-fold-button.tsx | 4 ++-- web/components/datetime-tooltip.tsx | 2 +- web/components/edit-fold-button.tsx | 6 ++--- web/components/feed-create.tsx | 8 +++---- web/components/fold-tag.tsx | 2 +- web/components/leaderboard.tsx | 4 ++-- web/components/loading-indicator.tsx | 4 ++-- web/components/manifold-logo.tsx | 8 +++---- web/components/menu.tsx | 6 ++--- web/components/nav-bar.tsx | 32 ++++++++++++------------- web/components/page.tsx | 2 +- web/components/profile-menu.tsx | 6 ++--- web/components/resolution-panel.tsx | 2 +- web/components/site-link.tsx | 4 ++-- web/components/tags-input.tsx | 2 +- web/components/tags-list.tsx | 16 ++++++------- web/components/title.tsx | 2 +- web/components/tweet-button.tsx | 2 +- web/components/yes-no-selector.tsx | 20 ++++++++-------- web/package.json | 1 + web/pages/404.tsx | 2 +- web/pages/[username]/[contractSlug].tsx | 4 ++-- web/pages/_document.tsx | 2 +- web/pages/account.tsx | 6 ++--- web/pages/activity.tsx | 2 +- web/pages/add-funds.tsx | 10 ++++---- web/pages/create.tsx | 22 ++++++++--------- web/pages/fold/[...slugs]/index.tsx | 22 ++++++++--------- web/pages/folds.tsx | 14 +++++------ web/pages/home.tsx | 10 ++++---- web/pages/landing-page.tsx | 32 ++++++++++++------------- web/pages/leaderboards.tsx | 2 +- web/pages/make-predictions.tsx | 26 ++++++++++---------- web/pages/markets.tsx | 4 ++-- web/pages/profile.tsx | 8 +++---- web/pages/simulator.tsx | 12 +++++----- yarn.lock | 5 ++++ 48 files changed, 228 insertions(+), 222 deletions(-) diff --git a/web/components/add-funds-button.tsx b/web/components/add-funds-button.tsx index 3903f079..d17d89ce 100644 --- a/web/components/add-funds-button.tsx +++ b/web/components/add-funds-button.tsx @@ -20,7 +20,7 @@ export function AddFundsButton(props: { className?: string }) {