From de043de5896dfe02cad5fc2ba05e2437dc5dd06b Mon Sep 17 00:00:00 2001 From: jahooma Date: Wed, 12 Jan 2022 19:53:50 -0600 Subject: [PATCH] Add visibility field to contracts. Hot contracts & activity feed show only visibility 'public'. --- common/contract.ts | 1 + common/new-contract.ts | 1 + .../src/scripts/make-contracts-public.ts | 32 +++++++++++++++++++ web/lib/firebase/contracts.ts | 1 + web/pages/activity.tsx | 1 + 5 files changed, 36 insertions(+) create mode 100644 functions/src/scripts/make-contracts-public.ts diff --git a/common/contract.ts b/common/contract.ts index 385820df..419e279d 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -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 } diff --git a/common/new-contract.ts b/common/new-contract.ts index eef7b392..3cd0823a 100644 --- a/common/new-contract.ts +++ b/common/new-contract.ts @@ -27,6 +27,7 @@ export function getNewContract( question: question.trim(), description: description.trim(), + visibility: 'public', mechanism: 'dpm-2', phantomShares: { YES: phantomYes, NO: phantomNo }, diff --git a/functions/src/scripts/make-contracts-public.ts b/functions/src/scripts/make-contracts-public.ts new file mode 100644 index 00000000..2ebc5d61 --- /dev/null +++ b/functions/src/scripts/make-contracts-public.ts @@ -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()) diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 8556015a..9dc3e2bc 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -133,6 +133,7 @@ export function listenForContract( const hotContractsQuery = query( contractCollection, where('isResolved', '==', false), + where('visibility', '==', 'public'), orderBy('volume24Hours', 'desc'), limit(4) ) diff --git a/web/pages/activity.tsx b/web/pages/activity.tsx index 69a04f3e..4d4d1766 100644 --- a/web/pages/activity.tsx +++ b/web/pages/activity.tsx @@ -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 }