diff --git a/common/contract.ts b/common/contract.ts index aeb1d1b4..9b9c7b95 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -62,7 +62,7 @@ export type Contract = { featuredOnHomeRank?: number likedByUserIds?: string[] likedByUserCount?: number - resolutionReports?: string[] + flaggedByUsernames?: string[] } & T export type BinaryContract = Contract & Binary diff --git a/common/user.ts b/common/user.ts index 55092586..233fe4cc 100644 --- a/common/user.ts +++ b/common/user.ts @@ -33,7 +33,7 @@ export type User = { allTime: number } - correctResolutionPercentageCached: number + fractionResolvedCorrectly: number nextLoanCached: number followerCountCached: number diff --git a/functions/src/create-user.ts b/functions/src/create-user.ts index cd3a7569..c3b7ba1d 100644 --- a/functions/src/create-user.ts +++ b/functions/src/create-user.ts @@ -69,7 +69,7 @@ export const createuser = newEndpoint(opts, async (req, auth) => { followerCountCached: 0, followedCategories: DEFAULT_CATEGORIES, shouldShowWelcome: true, - correctResolutionPercentageCached: 1, + 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 564fe518..b51c4217 100644 --- a/functions/src/update-metrics.ts +++ b/functions/src/update-metrics.ts @@ -119,13 +119,13 @@ export async function updateMetricsCore() { const contractRatios = userContracts .map((contract) => { if ( - !contract.resolutionReports || - contract.resolutionReports?.length === 0 + !contract.flaggedByUsernames || + contract.flaggedByUsernames?.length === 0 ) { return 0 } const contractRatio = - contract.resolutionReports.length / (contract.uniqueBettorCount ?? 1) + contract.flaggedByUsernames.length / (contract.uniqueBettorCount ?? 1) return contractRatio }) @@ -133,8 +133,11 @@ export async function updateMetricsCore() { const badResolutions = contractRatios.filter( (ratio) => ratio > BAD_RESOLUTION_THRESHOLD ) - const newCorrectResolutionPercentage = - (userContracts.length - badResolutions.length) / userContracts.length + let newFractionResolvedCorrectly = 0 + if (userContracts.length > 0) { + newFractionResolvedCorrectly = + (userContracts.length - badResolutions.length) / userContracts.length + } return { user, @@ -142,7 +145,7 @@ export async function updateMetricsCore() { newPortfolio, newProfit, didPortfolioChange, - newCorrectResolutionPercentage, + newFractionResolvedCorrectly, } }) @@ -164,7 +167,7 @@ export async function updateMetricsCore() { newPortfolio, newProfit, didPortfolioChange, - newCorrectResolutionPercentage, + newFractionResolvedCorrectly, }) => { const nextLoanCached = nextLoanByUser[user.id]?.payout ?? 0 return { @@ -174,7 +177,7 @@ export async function updateMetricsCore() { creatorVolumeCached: newCreatorVolume, profitCached: newProfit, nextLoanCached, - correctResolutionPercentageCached: newCorrectResolutionPercentage, + fractionResolvedCorrectly: newFractionResolvedCorrectly, }, }, diff --git a/web/components/contract/contract-card.tsx b/web/components/contract/contract-card.tsx index 4e3034c0..aa53f62f 100644 --- a/web/components/contract/contract-card.tsx +++ b/web/components/contract/contract-card.tsx @@ -226,7 +226,6 @@ export function BinaryResolutionOrChance(props: { resolution={resolution} /> - ) : ( <> diff --git a/web/components/contract/contract-overview.tsx b/web/components/contract/contract-overview.tsx index 139b30fe..f1977639 100644 --- a/web/components/contract/contract-overview.tsx +++ b/web/components/contract/contract-overview.tsx @@ -26,6 +26,7 @@ import { } from 'common/contract' import { ContractDetails } from './contract-details' import { NumericGraph } from './numeric-graph' +import { ContractReportResolution } from './contract-report-resolution' const OverviewQuestion = (props: { text: string }) => ( @@ -76,11 +77,14 @@ const BinaryOverview = (props: { contract: BinaryContract; bets: Bet[] }) => { - + + + + @@ -105,7 +109,13 @@ const ChoiceOverview = (props: { {resolution && ( - + + + + )} diff --git a/web/components/contract/contract-report-resolution.tsx b/web/components/contract/contract-report-resolution.tsx index bd6d3c7b..b4758886 100644 --- a/web/components/contract/contract-report-resolution.tsx +++ b/web/components/contract/contract-report-resolution.tsx @@ -6,6 +6,7 @@ import { Tooltip } from '../tooltip' import { ConfirmationButton } from '../confirmation-button' import { Row } from '../layout/row' import { FlagIcon } from '@heroicons/react/solid' +import { buildArray } from 'common/lib/util/array' export function ContractReportResolution(props: { contract: Contract }) { const { contract } = props @@ -13,14 +14,15 @@ export function ContractReportResolution(props: { contract: Contract }) { if (!user) { return <> } - const userReported = contract.resolutionReports?.includes(user.id) + const userReported = contract.flaggedByUsernames?.includes(user.id) const onSubmit = async () => { if (!user) { return true } + await updateContract(contract.id, { - resolutionReports: [...(contract.resolutionReports || []), user.id], + flaggedByUsernames: buildArray(contract.flaggedByUsernames, user.id), }) return true }