From 06571a3657e0b9eb9472eb5d02bf321b8017b526 Mon Sep 17 00:00:00 2001 From: FRC Date: Mon, 3 Oct 2022 10:49:19 +0100 Subject: [PATCH] Flag incorrectly resolved markets, warn about unreliable creators (#945) * Flag incorrectly resolved markets, warn about unreliable creators * Address James' review nits * Added a loading state and some copy-changes * Fix missing refactor * Fix vercel error * Fix merging issues --- common/contract.ts | 1 + common/user.ts | 2 + functions/src/create-user.ts | 1 + functions/src/update-metrics.ts | 27 +++++++ web/components/confirmation-button.tsx | 12 ++- web/components/contract/contract-card.tsx | 22 +++--- web/components/contract/contract-details.tsx | 17 +++- web/components/contract/contract-overview.tsx | 20 ++++- .../contract/contract-report-resolution.tsx | 77 +++++++++++++++++++ 9 files changed, 162 insertions(+), 17 deletions(-) create mode 100644 web/components/contract/contract-report-resolution.tsx diff --git a/common/contract.ts b/common/contract.ts index 2e9d94c4..fb430067 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -62,6 +62,7 @@ export type Contract = { featuredOnHomeRank?: number likedByUserIds?: string[] likedByUserCount?: number + flaggedByUsernames?: string[] openCommentBounties?: number } & T diff --git a/common/user.ts b/common/user.ts index b1365929..233fe4cc 100644 --- a/common/user.ts +++ b/common/user.ts @@ -33,6 +33,8 @@ export type User = { allTime: number } + fractionResolvedCorrectly: number + nextLoanCached: number followerCountCached: number diff --git a/functions/src/create-user.ts b/functions/src/create-user.ts index ab70b4e6..c3b7ba1d 100644 --- a/functions/src/create-user.ts +++ b/functions/src/create-user.ts @@ -69,6 +69,7 @@ export const createuser = newEndpoint(opts, async (req, auth) => { followerCountCached: 0, followedCategories: DEFAULT_CATEGORIES, shouldShowWelcome: true, + fractionResolvedCorrectly: 1, } await firestore.collection('users').doc(auth.uid).create(user) diff --git a/functions/src/update-metrics.ts b/functions/src/update-metrics.ts index 12f41453..70c7c742 100644 --- a/functions/src/update-metrics.ts +++ b/functions/src/update-metrics.ts @@ -135,6 +135,28 @@ export async function updateMetricsCore() { lastPortfolio.investmentValue !== newPortfolio.investmentValue const newProfit = calculateNewProfit(portfolioHistory, newPortfolio) + const contractRatios = userContracts + .map((contract) => { + if ( + !contract.flaggedByUsernames || + contract.flaggedByUsernames?.length === 0 + ) { + return 0 + } + const contractRatio = + contract.flaggedByUsernames.length / (contract.uniqueBettorCount ?? 1) + + return contractRatio + }) + .filter((ratio) => ratio > 0) + const badResolutions = contractRatios.filter( + (ratio) => ratio > BAD_RESOLUTION_THRESHOLD + ) + let newFractionResolvedCorrectly = 0 + if (userContracts.length > 0) { + newFractionResolvedCorrectly = + (userContracts.length - badResolutions.length) / userContracts.length + } return { user, @@ -142,6 +164,7 @@ export async function updateMetricsCore() { newPortfolio, newProfit, didPortfolioChange, + newFractionResolvedCorrectly, } }) @@ -163,6 +186,7 @@ export async function updateMetricsCore() { newPortfolio, newProfit, didPortfolioChange, + newFractionResolvedCorrectly, }) => { const nextLoanCached = nextLoanByUser[user.id]?.payout ?? 0 return { @@ -172,6 +196,7 @@ export async function updateMetricsCore() { creatorVolumeCached: newCreatorVolume, profitCached: newProfit, nextLoanCached, + fractionResolvedCorrectly: newFractionResolvedCorrectly, }, }, @@ -243,3 +268,5 @@ const topUserScores = (scores: { [userId: string]: number }) => { } type GroupContractDoc = { contractId: string; createdTime: number } + +const BAD_RESOLUTION_THRESHOLD = 0.1 diff --git a/web/components/confirmation-button.tsx b/web/components/confirmation-button.tsx index 2ad0cb3d..87c98f0a 100644 --- a/web/components/confirmation-button.tsx +++ b/web/components/confirmation-button.tsx @@ -26,6 +26,7 @@ export function ConfirmationButton(props: { onSubmit?: () => void onOpenChanged?: (isOpen: boolean) => void onSubmitWithSuccess?: () => Promise + disabled?: boolean }) { const { openModalBtn, @@ -35,6 +36,7 @@ export function ConfirmationButton(props: { children, onOpenChanged, onSubmitWithSuccess, + disabled, } = props const [open, setOpen] = useState(false) @@ -72,9 +74,15 @@ export function ConfirmationButton(props: { +