Address James' review nits
This commit is contained in:
parent
d9ccdce8d4
commit
b762a414a1
|
@ -62,7 +62,7 @@ export type Contract<T extends AnyContractType = AnyContractType> = {
|
|||
featuredOnHomeRank?: number
|
||||
likedByUserIds?: string[]
|
||||
likedByUserCount?: number
|
||||
resolutionReports?: string[]
|
||||
flaggedByUsernames?: string[]
|
||||
} & T
|
||||
|
||||
export type BinaryContract = Contract & Binary
|
||||
|
|
|
@ -33,7 +33,7 @@ export type User = {
|
|||
allTime: number
|
||||
}
|
||||
|
||||
correctResolutionPercentageCached: number
|
||||
fractionResolvedCorrectly: number
|
||||
|
||||
nextLoanCached: number
|
||||
followerCountCached: number
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -226,7 +226,6 @@ export function BinaryResolutionOrChance(props: {
|
|||
resolution={resolution}
|
||||
/>
|
||||
</div>
|
||||
<ContractReportResolution contract={contract} />
|
||||
</Row>
|
||||
) : (
|
||||
<>
|
||||
|
|
|
@ -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 }) => (
|
||||
<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} />
|
||||
<Row className="justify-between gap-4">
|
||||
<OverviewQuestion text={contract.question} />
|
||||
<BinaryResolutionOrChance
|
||||
className="flex items-end"
|
||||
contract={contract}
|
||||
large
|
||||
/>
|
||||
<Row>
|
||||
<BinaryResolutionOrChance
|
||||
className="flex items-end"
|
||||
contract={contract}
|
||||
large
|
||||
/>
|
||||
<ContractReportResolution contract={contract} />
|
||||
</Row>
|
||||
</Row>
|
||||
</Col>
|
||||
<ContractProbGraph contract={contract} bets={[...bets].reverse()} />
|
||||
|
@ -105,7 +109,13 @@ const ChoiceOverview = (props: {
|
|||
<ContractDetails contract={contract} />
|
||||
<OverviewQuestion text={question} />
|
||||
{resolution && (
|
||||
<FreeResponseResolutionOrChance contract={contract} truncate="none" />
|
||||
<Row>
|
||||
<FreeResponseResolutionOrChance
|
||||
contract={contract}
|
||||
truncate="none"
|
||||
/>
|
||||
<ContractReportResolution contract={contract} />
|
||||
</Row>
|
||||
)}
|
||||
</Col>
|
||||
<Col className={'mb-1 gap-y-2'}>
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user