Address James' review nits

This commit is contained in:
Pico2x 2022-10-03 09:37:51 +01:00
parent d9ccdce8d4
commit b762a414a1
7 changed files with 34 additions and 20 deletions

View File

@ -62,7 +62,7 @@ export type Contract<T extends AnyContractType = AnyContractType> = {
featuredOnHomeRank?: number featuredOnHomeRank?: number
likedByUserIds?: string[] likedByUserIds?: string[]
likedByUserCount?: number likedByUserCount?: number
resolutionReports?: string[] flaggedByUsernames?: string[]
} & T } & T
export type BinaryContract = Contract & Binary export type BinaryContract = Contract & Binary

View File

@ -33,7 +33,7 @@ export type User = {
allTime: number allTime: number
} }
correctResolutionPercentageCached: number fractionResolvedCorrectly: number
nextLoanCached: number nextLoanCached: number
followerCountCached: number followerCountCached: number

View File

@ -69,7 +69,7 @@ export const createuser = newEndpoint(opts, async (req, auth) => {
followerCountCached: 0, followerCountCached: 0,
followedCategories: DEFAULT_CATEGORIES, followedCategories: DEFAULT_CATEGORIES,
shouldShowWelcome: true, shouldShowWelcome: true,
correctResolutionPercentageCached: 1, fractionResolvedCorrectly: 1,
} }
await firestore.collection('users').doc(auth.uid).create(user) await firestore.collection('users').doc(auth.uid).create(user)

View File

@ -119,13 +119,13 @@ export async function updateMetricsCore() {
const contractRatios = userContracts const contractRatios = userContracts
.map((contract) => { .map((contract) => {
if ( if (
!contract.resolutionReports || !contract.flaggedByUsernames ||
contract.resolutionReports?.length === 0 contract.flaggedByUsernames?.length === 0
) { ) {
return 0 return 0
} }
const contractRatio = const contractRatio =
contract.resolutionReports.length / (contract.uniqueBettorCount ?? 1) contract.flaggedByUsernames.length / (contract.uniqueBettorCount ?? 1)
return contractRatio return contractRatio
}) })
@ -133,8 +133,11 @@ export async function updateMetricsCore() {
const badResolutions = contractRatios.filter( const badResolutions = contractRatios.filter(
(ratio) => ratio > BAD_RESOLUTION_THRESHOLD (ratio) => ratio > BAD_RESOLUTION_THRESHOLD
) )
const newCorrectResolutionPercentage = let newFractionResolvedCorrectly = 0
(userContracts.length - badResolutions.length) / userContracts.length if (userContracts.length > 0) {
newFractionResolvedCorrectly =
(userContracts.length - badResolutions.length) / userContracts.length
}
return { return {
user, user,
@ -142,7 +145,7 @@ export async function updateMetricsCore() {
newPortfolio, newPortfolio,
newProfit, newProfit,
didPortfolioChange, didPortfolioChange,
newCorrectResolutionPercentage, newFractionResolvedCorrectly,
} }
}) })
@ -164,7 +167,7 @@ export async function updateMetricsCore() {
newPortfolio, newPortfolio,
newProfit, newProfit,
didPortfolioChange, didPortfolioChange,
newCorrectResolutionPercentage, newFractionResolvedCorrectly,
}) => { }) => {
const nextLoanCached = nextLoanByUser[user.id]?.payout ?? 0 const nextLoanCached = nextLoanByUser[user.id]?.payout ?? 0
return { return {
@ -174,7 +177,7 @@ export async function updateMetricsCore() {
creatorVolumeCached: newCreatorVolume, creatorVolumeCached: newCreatorVolume,
profitCached: newProfit, profitCached: newProfit,
nextLoanCached, nextLoanCached,
correctResolutionPercentageCached: newCorrectResolutionPercentage, fractionResolvedCorrectly: newFractionResolvedCorrectly,
}, },
}, },

View File

@ -226,7 +226,6 @@ export function BinaryResolutionOrChance(props: {
resolution={resolution} resolution={resolution}
/> />
</div> </div>
<ContractReportResolution contract={contract} />
</Row> </Row>
) : ( ) : (
<> <>

View File

@ -26,6 +26,7 @@ import {
} from 'common/contract' } from 'common/contract'
import { ContractDetails } from './contract-details' import { ContractDetails } from './contract-details'
import { NumericGraph } from './numeric-graph' import { NumericGraph } from './numeric-graph'
import { ContractReportResolution } from './contract-report-resolution'
const OverviewQuestion = (props: { text: string }) => ( const OverviewQuestion = (props: { text: string }) => (
<Linkify className="text-lg text-indigo-700 sm:text-2xl" text={props.text} /> <Linkify className="text-lg text-indigo-700 sm:text-2xl" text={props.text} />
@ -76,11 +77,14 @@ const BinaryOverview = (props: { contract: BinaryContract; bets: Bet[] }) => {
<ContractDetails contract={contract} /> <ContractDetails contract={contract} />
<Row className="justify-between gap-4"> <Row className="justify-between gap-4">
<OverviewQuestion text={contract.question} /> <OverviewQuestion text={contract.question} />
<BinaryResolutionOrChance <Row>
className="flex items-end" <BinaryResolutionOrChance
contract={contract} className="flex items-end"
large contract={contract}
/> large
/>
<ContractReportResolution contract={contract} />
</Row>
</Row> </Row>
</Col> </Col>
<ContractProbGraph contract={contract} bets={[...bets].reverse()} /> <ContractProbGraph contract={contract} bets={[...bets].reverse()} />
@ -105,7 +109,13 @@ const ChoiceOverview = (props: {
<ContractDetails contract={contract} /> <ContractDetails contract={contract} />
<OverviewQuestion text={question} /> <OverviewQuestion text={question} />
{resolution && ( {resolution && (
<FreeResponseResolutionOrChance contract={contract} truncate="none" /> <Row>
<FreeResponseResolutionOrChance
contract={contract}
truncate="none"
/>
<ContractReportResolution contract={contract} />
</Row>
)} )}
</Col> </Col>
<Col className={'mb-1 gap-y-2'}> <Col className={'mb-1 gap-y-2'}>

View File

@ -6,6 +6,7 @@ import { Tooltip } from '../tooltip'
import { ConfirmationButton } from '../confirmation-button' import { ConfirmationButton } from '../confirmation-button'
import { Row } from '../layout/row' import { Row } from '../layout/row'
import { FlagIcon } from '@heroicons/react/solid' import { FlagIcon } from '@heroicons/react/solid'
import { buildArray } from 'common/lib/util/array'
export function ContractReportResolution(props: { contract: Contract }) { export function ContractReportResolution(props: { contract: Contract }) {
const { contract } = props const { contract } = props
@ -13,14 +14,15 @@ export function ContractReportResolution(props: { contract: Contract }) {
if (!user) { if (!user) {
return <></> return <></>
} }
const userReported = contract.resolutionReports?.includes(user.id) const userReported = contract.flaggedByUsernames?.includes(user.id)
const onSubmit = async () => { const onSubmit = async () => {
if (!user) { if (!user) {
return true return true
} }
await updateContract(contract.id, { await updateContract(contract.id, {
resolutionReports: [...(contract.resolutionReports || []), user.id], flaggedByUsernames: buildArray(contract.flaggedByUsernames, user.id),
}) })
return true return true
} }