Merge branch 'main' into resolve-prob
This commit is contained in:
commit
70088ec7bb
|
@ -17,7 +17,7 @@ import {
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
import { app } from './init'
|
import { app } from './init'
|
||||||
import { getValues, listenForValues } from './utils'
|
import { getValues, listenForValue, listenForValues } from './utils'
|
||||||
import { Contract } from '../../../common/contract'
|
import { Contract } from '../../../common/contract'
|
||||||
import { getProbability } from '../../../common/calculate'
|
import { getProbability } from '../../../common/calculate'
|
||||||
import { createRNG, shuffle } from '../../../common/util/random'
|
import { createRNG, shuffle } from '../../../common/util/random'
|
||||||
|
@ -126,9 +126,7 @@ export function listenForContract(
|
||||||
setContract: (contract: Contract | null) => void
|
setContract: (contract: Contract | null) => void
|
||||||
) {
|
) {
|
||||||
const contractRef = doc(contractCollection, contractId)
|
const contractRef = doc(contractCollection, contractId)
|
||||||
return onSnapshot(contractRef, (contractSnap) => {
|
return listenForValue<Contract>(contractRef, setContract)
|
||||||
setContract((contractSnap.data() ?? null) as Contract | null)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function chooseRandomSubset(contracts: Contract[], count: number) {
|
function chooseRandomSubset(contracts: Contract[], count: number) {
|
||||||
|
|
|
@ -23,6 +23,8 @@ export function listenForValue<T>(
|
||||||
setValue: (value: T | null) => void
|
setValue: (value: T | null) => void
|
||||||
) {
|
) {
|
||||||
return onSnapshot(docRef, (snapshot) => {
|
return onSnapshot(docRef, (snapshot) => {
|
||||||
|
if (snapshot.metadata.fromCache) return
|
||||||
|
|
||||||
const value = snapshot.exists() ? (snapshot.data() as T) : null
|
const value = snapshot.exists() ? (snapshot.data() as T) : null
|
||||||
setValue(value)
|
setValue(value)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user