Add visibility field to contracts. Hot contracts & activity feed show only visibility 'public'.

This commit is contained in:
jahooma 2022-01-12 19:53:50 -06:00
parent 1fbde3646f
commit de043de589
5 changed files with 36 additions and 0 deletions

View File

@ -10,6 +10,7 @@ export type Contract = {
description: string // More info about what the contract is about
outcomeType: 'BINARY' // | 'MULTI' | 'interval' | 'date'
// outcomes: ['YES', 'NO']
visibility: 'public' | 'unlisted'
mechanism: 'dpm-2'
phantomShares: { YES: number; NO: number }

View File

@ -27,6 +27,7 @@ export function getNewContract(
question: question.trim(),
description: description.trim(),
visibility: 'public',
mechanism: 'dpm-2',
phantomShares: { YES: phantomYes, NO: phantomNo },

View File

@ -0,0 +1,32 @@
import * as admin from 'firebase-admin'
import * as _ from 'lodash'
import { Contract } from '../../../common/contract'
// Generate your own private key, and set the path below:
// https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk
// const serviceAccount = require('../../../../Downloads/dev-mantic-markets-firebase-adminsdk-sir5m-b2d27f8970.json')
const serviceAccount = require('../../../../../../Downloads/mantic-markets-firebase-adminsdk-1ep46-820891bb87.json')
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
})
const firestore = admin.firestore()
async function makeContractsPublic() {
console.log('Updating contracts to be public')
const snapshot = await firestore.collection('contracts').get()
const contracts = snapshot.docs.map((doc) => doc.data() as Contract)
console.log('Loaded', contracts.length, 'contracts')
for (const contract of contracts) {
const contractRef = firestore.doc(`contracts/${contract.id}`)
console.log('Updating', contract.question)
await contractRef.update({ visibility: 'public' })
}
}
if (require.main === module) makeContractsPublic().then(() => process.exit())

View File

@ -133,6 +133,7 @@ export function listenForContract(
const hotContractsQuery = query(
contractCollection,
where('isResolved', '==', false),
where('visibility', '==', 'public'),
orderBy('volume24Hours', 'desc'),
limit(4)
)

View File

@ -61,6 +61,7 @@ function findActiveContracts(
}
contracts = _.uniqBy(contracts, (c) => c.id)
contracts = contracts.filter((contract) => contract.visibility === 'public')
contracts = _.sortBy(contracts, (c) => -(idToActivityTime.get(c.id) ?? 0))
return contracts
}