Add minimum unique bettors for proven correct
This commit is contained in:
parent
7fa1d14443
commit
bc8a3a8e3c
|
@ -1,10 +1,5 @@
|
|||
import { User } from './user'
|
||||
|
||||
export type Achievement = {
|
||||
totalBadges: number
|
||||
badges: Badge[]
|
||||
}
|
||||
|
||||
export type Badge = {
|
||||
type: BadgeTypes
|
||||
createdTime: number
|
||||
|
@ -42,6 +37,7 @@ export type ProvenCorrectBadge = Badge & ProvenCorrectBadgeData
|
|||
export type StreakerBadge = Badge & StreakerBadgeData
|
||||
export type MarketCreatorBadge = Badge & MarketCreatorBadgeData
|
||||
|
||||
export const MINIMUM_UNIQUE_BETTORS_FOR_PROVEN_CORRECT_BADGE = 5
|
||||
export const provenCorrectRarityThresholds = [1, 1000, 10000]
|
||||
const calculateProvenCorrectBadgeRarity = (badge: ProvenCorrectBadge) => {
|
||||
const { betAmount } = badge.data
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { notification_preferences } from './user-notification-preferences'
|
||||
import { ENV_CONFIG } from './envs/constants'
|
||||
import { Achievement } from './badge'
|
||||
import { MarketCreatorBadge, ProvenCorrectBadge, StreakerBadge } from './badge'
|
||||
|
||||
export type User = {
|
||||
id: string
|
||||
|
@ -52,9 +52,18 @@ export type User = {
|
|||
isBannedFromPosting?: boolean
|
||||
|
||||
achievements?: {
|
||||
provenCorrect?: Achievement
|
||||
marketCreator?: Achievement
|
||||
streaker?: Achievement
|
||||
provenCorrect?: {
|
||||
totalBadges: number
|
||||
badges: ProvenCorrectBadge[]
|
||||
}
|
||||
marketCreator?: {
|
||||
totalBadges: number
|
||||
badges: MarketCreatorBadge[]
|
||||
}
|
||||
streaker?: {
|
||||
totalBadges: number
|
||||
badges: StreakerBadge[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,10 @@ import { Bet } from '../../common/bet'
|
|||
import * as admin from 'firebase-admin'
|
||||
import { ContractComment } from '../../common/comment'
|
||||
import { scoreCommentorsAndBettors } from '../../common/scoring'
|
||||
import { ProvenCorrectBadge } from '../../common/badge'
|
||||
import {
|
||||
MINIMUM_UNIQUE_BETTORS_FOR_PROVEN_CORRECT_BADGE,
|
||||
ProvenCorrectBadge,
|
||||
} from '../../common/badge'
|
||||
|
||||
export const onUpdateContract = functions.firestore
|
||||
.document('contracts/{contractId}')
|
||||
|
@ -51,6 +54,12 @@ export const onUpdateContract = functions.firestore
|
|||
const firestore = admin.firestore()
|
||||
|
||||
async function handleResolvedContract(contract: Contract) {
|
||||
if (
|
||||
(contract.uniqueBettorCount ?? 0) <
|
||||
MINIMUM_UNIQUE_BETTORS_FOR_PROVEN_CORRECT_BADGE
|
||||
)
|
||||
return
|
||||
|
||||
// get all bets on this contract
|
||||
const bets = await getValues<Bet>(
|
||||
firestore.collection(`contracts/${contract.id}/bets`)
|
||||
|
|
Loading…
Reference in New Issue
Block a user