From 9258cf0f3daaa14eeb9b3726cd789638fee23efe Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Sat, 26 Feb 2022 22:15:47 -0800 Subject: [PATCH 01/23] Add dev target for TheoremOne --- web/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/web/package.json b/web/package.json index 6a7caecf..7922f346 100644 --- a/web/package.json +++ b/web/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "concurrently -n NEXT,TS -c magenta,cyan \"next dev -p 3000\" \"yarn ts --watch\"", "devdev": "NEXT_PUBLIC_FIREBASE_ENV=DEV concurrently -n NEXT,TS -c magenta,cyan \"FIREBASE_ENV=DEV next dev -p 3000\" \"FIREBASE_ENV=DEV yarn ts --watch\"", + "dev:the": "NEXT_PUBLIC_FIREBASE_ENV=THEOREMONE concurrently -n NEXT,TS -c magenta,cyan \"FIREBASE_ENV=THEOREMONE next dev -p 3000\" \"FIREBASE_ENV=THEOREMONE yarn ts --watch\"", "ts": "tsc --noEmit --incremental --preserveWatchOutput --pretty", "build": "next build", "start": "next start", From bfefa61d3586f125bb908a6cacc321a62405cf31 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 28 Feb 2022 16:05:31 -0800 Subject: [PATCH 02/23] Restrict signups to theoremone.co emails --- common/access.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/access.ts b/common/access.ts index acd894b1..4a128108 100644 --- a/common/access.ts +++ b/common/access.ts @@ -1,6 +1,5 @@ export function isWhitelisted(email?: string) { - return true - // e.g. return email.endsWith('@theoremone.co') || isAdmin(email) + return email && (email.endsWith('@theoremone.co') || isAdmin(email)) } export function isAdmin(email: string) { From a722de09d001ed2ccc7e976f11719f933a7a88d7 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 28 Feb 2022 18:09:43 -0800 Subject: [PATCH 03/23] Add new indices --- firestore.indexes.json | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/firestore.indexes.json b/firestore.indexes.json index 0576f860..ac88ccf6 100644 --- a/firestore.indexes.json +++ b/firestore.indexes.json @@ -46,6 +46,46 @@ } ] }, + { + "collectionGroup": "contracts", + "queryScope": "COLLECTION", + "fields": [ + { + "fieldPath": "isResolved", + "order": "ASCENDING" + }, + { + "fieldPath": "visibility", + "order": "ASCENDING" + }, + { + "fieldPath": "volume24Hours", + "order": "ASCENDING" + } + ] + }, + { + "collectionGroup": "contracts", + "queryScope": "COLLECTION", + "fields": [ + { + "fieldPath": "isResolved", + "order": "ASCENDING" + }, + { + "fieldPath": "visibility", + "order": "ASCENDING" + }, + { + "fieldPath": "volume24Hours", + "order": "ASCENDING" + }, + { + "fieldPath": "closeTime", + "order": "ASCENDING" + } + ] + }, { "collectionGroup": "contracts", "queryScope": "COLLECTION", @@ -94,6 +134,28 @@ } ], "fieldOverrides": [ + { + "collectionGroup": "answers", + "fieldPath": "isAnte", + "indexes": [ + { + "order": "ASCENDING", + "queryScope": "COLLECTION" + }, + { + "order": "DESCENDING", + "queryScope": "COLLECTION" + }, + { + "arrayConfig": "CONTAINS", + "queryScope": "COLLECTION" + }, + { + "order": "ASCENDING", + "queryScope": "COLLECTION_GROUP" + } + ] + }, { "collectionGroup": "answers", "fieldPath": "username", From eef35cd7d0710eadec955f090e21e4efb1fe5b7c Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 1 Mar 2022 16:31:03 -0800 Subject: [PATCH 04/23] Forbid reads from unauthenticated users --- firestore.rules | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/firestore.rules b/firestore.rules index 8c419b01..6c447fa3 100644 --- a/firestore.rules +++ b/firestore.rules @@ -5,14 +5,16 @@ service cloud.firestore { match /databases/{database}/documents { function isAdmin() { - return request.auth.uid == 'igi2zGXsfxYPgB0DJTXVJVmwCOr2' // Austin - || request.auth.uid == '5LZ4LgYuySdL1huCWe7bti02ghx2' // James - || request.auth.uid == 'tlmGNz9kjXc2EteizMORes4qvWl2' // Stephen - || request.auth.uid == 'IPTOzEqrpkWmEzh6hwvAyY9PqFb2' // Manifold + return request.auth.uid == 'OTd2JFY7LOdvQg2ZQGYLUqrXAiD2' // Austin + || request.auth.uid == 'czxKSN1Z03Mzu7UqIio3ppM0eDt2' // David + } + + function isAuthed() { + return request.auth != null } match /users/{userId} { - allow read; + allow read: if isAuthed(); allow update: if resource.data.id == request.auth.uid && request.resource.data.diff(resource.data).affectedKeys() .hasOnly(['bio', 'bannerUrl', 'website', 'twitterHandle', 'discordHandle']); @@ -23,7 +25,7 @@ service cloud.firestore { } match /contracts/{contractId} { - allow read; + allow read: if isAuthed(); allow update: if request.resource.data.diff(resource.data).affectedKeys() .hasOnly(['description', 'closeTime', 'tags', 'lowercaseTags']); allow update: if isAdmin(); @@ -31,25 +33,25 @@ service cloud.firestore { } match /{somePath=**}/bets/{betId} { - allow read; + allow read: if isAuthed(); } match /{somePath=**}/comments/{commentId} { - allow read; + allow read: if isAuthed(); allow create: if request.auth != null; } match /{somePath=**}/answers/{answerId} { - allow read; + allow read: if isAuthed(); } match /folds/{foldId} { - allow read; + allow read: if isAuthed(); allow update, delete: if request.auth.uid == resource.data.curatorId; } match /{somePath=**}/followers/{userId} { - allow read; + allow read: if isAuthed(); allow write: if request.auth.uid == userId; } } From 20d18f3588978d32c833d5f82e344a46da19fcf2 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 1 Mar 2022 16:32:31 -0800 Subject: [PATCH 05/23] Client-side render pages that need auth These pages are now client-side rendered: - /home - /leaderboards - /market/... - /fold/... --- web/hooks/use-contract.ts | 2 +- web/hooks/use-propz.ts | 30 +++++++++++++++++++++++++ web/pages/[username]/[contractSlug].tsx | 15 +++++++++++-- web/pages/fold/[...slugs]/index.tsx | 20 ++++++++++++++--- web/pages/home.tsx | 8 ++++++- web/pages/leaderboards.tsx | 7 +++++- 6 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 web/hooks/use-propz.ts diff --git a/web/hooks/use-contract.ts b/web/hooks/use-contract.ts index d48cd26a..ceaa125b 100644 --- a/web/hooks/use-contract.ts +++ b/web/hooks/use-contract.ts @@ -29,7 +29,7 @@ export const useContractWithPreload = ( useEffect(() => { if (contractId) return listenForContract(contractId, setContract) - if (contractId !== null) + if (contractId !== null && slug) getContractFromSlug(slug).then((c) => setContractId(c?.id || null)) }, [contractId, slug]) diff --git a/web/hooks/use-propz.ts b/web/hooks/use-propz.ts new file mode 100644 index 00000000..3687c725 --- /dev/null +++ b/web/hooks/use-propz.ts @@ -0,0 +1,30 @@ +import _ from 'lodash' +import { useRouter } from 'next/router' +import { useState, useEffect } from 'react' + +type PropzProps = { + params: any +} + +// getStaticPropz should exactly match getStaticProps +// This allows us to client-side render the page for authenticated users. +// TODO: Could cache the result using stale-while-revalidate: https://swr.vercel.app/ +export function usePropz( + getStaticPropz: (props?: PropzProps) => Promise, + // Dynamic routes will need the query params from the router + needParams?: boolean +) { + // Get params from router + const router = useRouter() + const params = router.query + + const [propz, setPropz] = useState(undefined) + useEffect(() => { + if (needParams && _.isEmpty(params)) { + return + } + // @ts-ignore + getStaticPropz({ params }).then((result) => setPropz(result.props)) + }, [params]) + return propz +} diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index 72cacd3f..f90da12e 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -29,8 +29,9 @@ import { useFoldsWithTags } from '../../hooks/use-fold' import { listAllAnswers } from '../../lib/firebase/answers' import { Answer } from '../../../common/answer' import { AnswersPanel } from '../../components/answers/answers-panel' +import { usePropz } from '../../hooks/use-propz' -export async function getStaticProps(props: { +export async function getStaticPropz(props: { params: { username: string; contractSlug: string } }) { const { username, contractSlug } = props.params @@ -64,7 +65,7 @@ export async function getStaticProps(props: { } } -export async function getStaticPaths() { +export async function getStaticPathz() { return { paths: [], fallback: 'blocking' } } @@ -77,6 +78,16 @@ export default function ContractPage(props: { slug: string folds: Fold[] }) { + // @ts-ignore + props = usePropz(getStaticPropz, true) ?? { + contract: null, + username: '', + comments: [], + answers: [], + bets: [], + slug: '', + folds: [], + } const user = useUser() const contract = useContractWithPreload(props.slug, props.contract) diff --git a/web/pages/fold/[...slugs]/index.tsx b/web/pages/fold/[...slugs]/index.tsx index 39c0845b..9040a3b7 100644 --- a/web/pages/fold/[...slugs]/index.tsx +++ b/web/pages/fold/[...slugs]/index.tsx @@ -40,8 +40,9 @@ import FeedCreate from '../../../components/feed-create' import { SEO } from '../../../components/SEO' import { useTaggedContracts } from '../../../hooks/use-contracts' import { Linkify } from '../../../components/linkify' +import { usePropz } from '../../../hooks/use-propz' -export async function getStaticProps(props: { params: { slugs: string[] } }) { +export async function getStaticPropz(props: { params: { slugs: string[] } }) { const { slugs } = props.params const fold = await getFoldBySlug(slugs[0]) @@ -124,7 +125,7 @@ async function toTopUsers(userScores: { [userId: string]: number }) { return topUsers.filter((user) => user) } -export async function getStaticPaths() { +export async function getStaticPathz() { return { paths: [], fallback: 'blocking' } } const foldSubpages = [undefined, 'activity', 'markets', 'leaderboards'] as const @@ -141,6 +142,19 @@ export default function FoldPage(props: { creatorScores: { [userId: string]: number } topCreators: User[] }) { + // @ts-ignore + props = usePropz(getStaticPropz, true) ?? { + fold: null, + curator: null, + contracts: [], + activeContracts: [], + activeContractBets: [], + activeContractComments: [], + traderScores: {}, + topTraders: [], + creatorScores: {}, + topCreators: [], + } const { curator, activeContractBets, @@ -154,7 +168,7 @@ export default function FoldPage(props: { const router = useRouter() const { slugs } = router.query as { slugs: string[] } - const page = (slugs[1] ?? 'activity') as typeof foldSubpages[number] + const page = (slugs?.[1] ?? 'activity') as typeof foldSubpages[number] const fold = useFold(props.fold?.id) ?? props.fold diff --git a/web/pages/home.tsx b/web/pages/home.tsx index 7bd305df..64543e67 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -20,8 +20,9 @@ import { useFindActiveContracts, } from '../hooks/use-active-contracts' import { useGetRecentBets } from '../hooks/use-bets' +import { usePropz } from '../hooks/use-propz' -export async function getStaticProps() { +export async function getStaticPropz() { const contractInfo = await getAllContractInfo() return { @@ -36,6 +37,11 @@ const Home = (props: { recentBets: Bet[] recentComments: Comment[] }) => { + props = usePropz(getStaticPropz) ?? { + contracts: [], + folds: [], + recentComments: [], + } const { contracts, folds, recentComments } = props const user = useUser() diff --git a/web/pages/leaderboards.tsx b/web/pages/leaderboards.tsx index fd2b8114..3e7caed2 100644 --- a/web/pages/leaderboards.tsx +++ b/web/pages/leaderboards.tsx @@ -5,8 +5,9 @@ import { Leaderboard } from '../components/leaderboard' import { Page } from '../components/page' import { getTopCreators, getTopTraders, User } from '../lib/firebase/users' import { formatMoney } from '../../common/util/format' +import { usePropz } from '../hooks/use-propz' -export async function getStaticProps() { +export async function getStaticPropz() { const [topTraders, topCreators] = await Promise.all([ getTopTraders().catch((_) => {}), getTopCreators().catch((_) => {}), @@ -26,6 +27,10 @@ export default function Leaderboards(props: { topTraders: User[] topCreators: User[] }) { + props = usePropz(getStaticPropz) ?? { + topTraders: [], + topCreators: [], + } const { topTraders, topCreators } = props return ( From c8add8ea51319b3ded044a4979e7656ecc4bf6eb Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 1 Mar 2022 16:36:52 -0800 Subject: [PATCH 06/23] Hide 404 for private Manifolds --- web/lib/firebase/init.ts | 1 + web/pages/404.tsx | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/web/lib/firebase/init.ts b/web/lib/firebase/init.ts index 145d67c5..f183d094 100644 --- a/web/lib/firebase/init.ts +++ b/web/lib/firebase/init.ts @@ -34,6 +34,7 @@ const FIREBASE_CONFIGS = { }, } const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' +export const IS_PRIVATE_MANIFOLD = !['PROD', 'DEV'].includes(ENV) // @ts-ignore const firebaseConfig = FIREBASE_CONFIGS[ENV] // Initialize Firebase diff --git a/web/pages/404.tsx b/web/pages/404.tsx index 7e9c9e27..3908a051 100644 --- a/web/pages/404.tsx +++ b/web/pages/404.tsx @@ -1,8 +1,14 @@ import { useEffect } from 'gridjs' import { Page } from '../components/page' import { Title } from '../components/title' +import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' export default function Custom404() { + if (IS_PRIVATE_MANIFOLD) { + // Since private Manifolds are client-side rendered, they'll blink the 404 + // So we just show a blank page here: + return + } return (
From c1fd17aba14d70c053782566c21a64f1ef80b9f8 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 1 Mar 2022 17:18:46 -0800 Subject: [PATCH 07/23] Brand instance for TheoremOne --- web/components/manifold-logo.tsx | 19 +----------------- web/pages/_document.tsx | 2 +- web/public/theoremone/Th1-Icon-Round.svg | 5 +++++ web/public/theoremone/Th1-Icon-Square.svg | 5 +++++ .../theoremone/TheoremOne-Logo-White.svg | 12 +++++++++++ web/public/theoremone/TheoremOne-Logo.svg | 12 +++++++++++ web/public/theoremone/logo.ico | Bin 0 -> 16958 bytes 7 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 web/public/theoremone/Th1-Icon-Round.svg create mode 100644 web/public/theoremone/Th1-Icon-Square.svg create mode 100644 web/public/theoremone/TheoremOne-Logo-White.svg create mode 100644 web/public/theoremone/TheoremOne-Logo.svg create mode 100644 web/public/theoremone/logo.ico diff --git a/web/components/manifold-logo.tsx b/web/components/manifold-logo.tsx index 75134ef8..ff57f5da 100644 --- a/web/components/manifold-logo.tsx +++ b/web/components/manifold-logo.tsx @@ -20,24 +20,7 @@ export function ManifoldLogo(props: { width={45} height={45} /> -
- Manifold -
- Markets -
- + ) diff --git a/web/pages/_document.tsx b/web/pages/_document.tsx index 2388a222..5e8e262e 100644 --- a/web/pages/_document.tsx +++ b/web/pages/_document.tsx @@ -4,7 +4,7 @@ export default function Document() { return ( - + + + + + diff --git a/web/public/theoremone/Th1-Icon-Square.svg b/web/public/theoremone/Th1-Icon-Square.svg new file mode 100644 index 00000000..5914165f --- /dev/null +++ b/web/public/theoremone/Th1-Icon-Square.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/web/public/theoremone/TheoremOne-Logo-White.svg b/web/public/theoremone/TheoremOne-Logo-White.svg new file mode 100644 index 00000000..fd91d9ee --- /dev/null +++ b/web/public/theoremone/TheoremOne-Logo-White.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/web/public/theoremone/TheoremOne-Logo.svg b/web/public/theoremone/TheoremOne-Logo.svg new file mode 100644 index 00000000..76c3156d --- /dev/null +++ b/web/public/theoremone/TheoremOne-Logo.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/web/public/theoremone/logo.ico b/web/public/theoremone/logo.ico new file mode 100644 index 0000000000000000000000000000000000000000..658adfd0d371bd07a47785b0dc0f279e70d646d8 GIT binary patch literal 16958 zcmeHPeN0wW7{65JGVv=?LB0ii6$Dd6162H&h{eyPB)eL>Le*ZCd1Z|{BI7c&ZcS?98cd+)i=J@@&Y z^Lw82JckWUa}z&tahmw;ubF0O+E7i?OhQDHwp9q*?fax41E|BscWw%-eo(V2S45iqrLh$?Mv6Ox8Z)>2M&1vtDjH8!To!YpLG;xPUhou zVV+fZf8zL;_&no7ER2uFlEmrwV&5JV=4DxRs9%tiDRk1YaCS6iMw#&GM?3LNezrlU zFgHuSyL8@61Ppd_nf=;v0Yfl-LNHdPK7)$VORzo8es=~-=g-2lCq^R7+Z|y(?(#Y# zeTS_YGSc6}l!yR?diR&}PW__?_ZxKf?S8+bAD;m(gPpu12RI)-?i$|Qve9aDYikRZ zCnd;sIbTAL`hEj6Bua?_2@a$953_7~5 ztDOA?YQh(iar^ddY4h*b>m`@%xypO;rT*I04!z&%F>BIj1E;AIN1eJ_sbg+#lD^?T z=&vzy72LWV#J^(ET(q~fNt>_MR0&S|8*ovV*kZ=|qNeh))T^tl#?*0v20d~r%H)ZP zvJQWe_(lA1W&HjEe~R$+o2{)9SJmZmJQ?bZK!H~uBc6$ElF18~%SxnPZPgXThWk0- zA3xFqMHhaSI=uqF;O63|r&)cL_=uBu?eRy33`6OqUnRC`!GoAEUkCgV{)6$$Pe1f3 z{K*MZU@@De&E=)Vh#EEADgFt;Ls3$6;ST-^M2Gnpc)~FY_Zx)sKc4MX_><v!FKO*@jhg8zzh{!bJ!qU=(U1AgYmFD_2RTU%enu6MU%=N(Dk@dn=6wi)ZvQe>`W zA9q|8e{FT8i2weEwT*Mj9I)~V&pzITTesS!&Z&Z2EL#|l8Id8P zj_7NMx!sMO{daZ#+uCko|K6Q4R{Tp4y&m8Z-C%ciGc|_JooL|bG58js8`HMMH-1r~^Hu9T3QeIMw z)|M79_UhxO+teLr+QypKzVEK$uewq$`M+_^3K{Qnjvq$$(L-ozY_Q@#d|;o$H;F$| ztfR~$SSPS{>~8%0CUd$i8`e1ZSXc2^SBm%->LYC@$Mdp|py9?JxYgb+*OJ2AOfmPt zhPmh1Tk#k79DZ4s2p)cY;6xsjMi&rnM`@~UNEo)W@%AmYNJxl^tAAL9~n26Nv_JlBQmH)Azp zdT01;vD#lV_RO4ULVR=>xEI9OXt9`k#Q%w(`!rm0cyQdAqZZ_Rh5YPe`2O3|(r@{! zN#HwGkRyGC{-VoCvG=9FPd#VzZ;x5OCl|uR{?E3}>*V*CAGNo)i8#?i`vcgr=?=U>g8bUrtq5i7lqIDcH8qSFTH^6udPS+u|tvrtpDumA02OJXRbl4 z4`)vfMcUH&czx4axu;<3L!G_*U$oQr=%4>an4_hoEI`Jt9ny!K`T5;!r9Sy6 Date: Tue, 1 Mar 2022 17:19:20 -0800 Subject: [PATCH 08/23] Hide "Add Funds" and "Personalize your feed" --- web/components/profile-menu.tsx | 14 ++++++++++---- web/pages/home.tsx | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/web/components/profile-menu.tsx b/web/components/profile-menu.tsx index 7cc00e6a..919a2031 100644 --- a/web/components/profile-menu.tsx +++ b/web/components/profile-menu.tsx @@ -3,6 +3,7 @@ import { formatMoney } from '../../common/util/format' import { Avatar } from './avatar' import { Col } from './layout/col' import { MenuButton } from './menu' +import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' export function ProfileMenu(props: { user: User | undefined }) { const { user } = props @@ -54,10 +55,15 @@ function getNavigationOptions( name: 'Your trades', href: '/trades', }, - { - name: 'Add funds', - href: '/add-funds', - }, + // Disable "Add Funds" for teams + ...(IS_PRIVATE_MANIFOLD + ? [] + : [ + { + name: 'Add funds', + href: '/add-funds', + }, + ]), { name: 'Leaderboards', href: '/leaderboards', diff --git a/web/pages/home.tsx b/web/pages/home.tsx index 664489e6..6a7ceccb 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -26,6 +26,7 @@ import { import { useGetRecentBets } from '../hooks/use-bets' import { usePropz } from '../hooks/use-propz' import { useActiveContracts } from '../hooks/use-contracts' +import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' export async function getStaticPropz() { const contractInfo = await getAllContractInfo() @@ -82,7 +83,8 @@ const Home = (props: { {initialFollowedFoldSlugs !== undefined && - initialFollowedFoldSlugs.length === 0 && ( + initialFollowedFoldSlugs.length === 0 && + !IS_PRIVATE_MANIFOLD && ( Date: Tue, 1 Mar 2022 17:19:40 -0800 Subject: [PATCH 09/23] "M$" => "T$" --- common/util/format.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/util/format.ts b/common/util/format.ts index 9b202d25..00fb6077 100644 --- a/common/util/format.ts +++ b/common/util/format.ts @@ -6,7 +6,7 @@ const formatter = new Intl.NumberFormat('en-US', { }) export function formatMoney(amount: number) { - return 'M$ ' + formatter.format(amount).replace('$', '') + return 'T$ ' + formatter.format(amount).replace('$', '') } export function formatWithCommas(amount: number) { From 5e4a205025d96eaf0771a93b9484e4045d8d2dd2 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 1 Mar 2022 17:30:49 -0800 Subject: [PATCH 10/23] Hide Discord & About Page too --- web/components/profile-menu.tsx | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/web/components/profile-menu.tsx b/web/components/profile-menu.tsx index 919a2031..342b20f4 100644 --- a/web/components/profile-menu.tsx +++ b/web/components/profile-menu.tsx @@ -55,27 +55,32 @@ function getNavigationOptions( name: 'Your trades', href: '/trades', }, - // Disable "Add Funds" for teams + // Disable irrelevant menu options for teams. ...(IS_PRIVATE_MANIFOLD - ? [] + ? [ + { + name: 'Leaderboards', + href: '/leaderboards', + }, + ] : [ { name: 'Add funds', href: '/add-funds', }, + { + name: 'Leaderboards', + href: '/leaderboards', + }, + { + name: 'Discord', + href: 'https://discord.gg/eHQBNBqXuh', + }, + { + name: 'About', + href: '/about', + }, ]), - { - name: 'Leaderboards', - href: '/leaderboards', - }, - { - name: 'Discord', - href: 'https://discord.gg/eHQBNBqXuh', - }, - { - name: 'About', - href: '/about', - }, { name: 'Sign out', href: '#', From a3bcbd0518b3e8486387ced1fae34d84b4333939 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 13:42:25 -0800 Subject: [PATCH 11/23] Update placeholders for teams --- web/components/feed-create.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/web/components/feed-create.tsx b/web/components/feed-create.tsx index 3dfeb175..c8d838ca 100644 --- a/web/components/feed-create.tsx +++ b/web/components/feed-create.tsx @@ -73,10 +73,14 @@ export default function FeedCreate(props: { const inputRef = useRef() const placeholders = [ - 'Will anyone I know get engaged this year?', - 'Will humans set foot on Mars by the end of 2030?', - 'Will any cryptocurrency eclipse Bitcoin by market cap this year?', - 'Will the Democrats win the 2024 presidential election?', + // 'Will anyone I know get engaged this year?', + // 'Will humans set foot on Mars by the end of 2030?', + // 'Will any cryptocurrency eclipse Bitcoin by market cap this year?', + // 'Will the Democrats win the 2024 presidential election?', + 'Will we have at least 5 new team members by the end of this quarter?', + 'Will we meet or exceed our goals this sprint?', + 'Will we sign on 3 or more new clients this month?', + 'Will Paul shave his beard by the end of the month?', ] // Rotate through a new placeholder each day // Easter egg idea: click your own name to shuffle the placeholder From 0fcfee6d779d7ed1fdf52eae11e57d8fab562512 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 14:19:55 -0800 Subject: [PATCH 12/23] Update firestore.indexes.json --- firestore.indexes.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/firestore.indexes.json b/firestore.indexes.json index ac88ccf6..e611f18a 100644 --- a/firestore.indexes.json +++ b/firestore.indexes.json @@ -242,6 +242,10 @@ "arrayConfig": "CONTAINS", "queryScope": "COLLECTION" }, + { + "order": "ASCENDING", + "queryScope": "COLLECTION_GROUP" + }, { "order": "DESCENDING", "queryScope": "COLLECTION_GROUP" From 95e24e9b87c5fb1e58c6a30ee8d5f53b923cba58 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 14:20:15 -0800 Subject: [PATCH 13/23] Switch /analytics to propz --- web/pages/analytics.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/web/pages/analytics.tsx b/web/pages/analytics.tsx index 268c0d51..cbd7b725 100644 --- a/web/pages/analytics.tsx +++ b/web/pages/analytics.tsx @@ -5,11 +5,13 @@ import { Col } from '../components/layout/col' import { Spacer } from '../components/layout/spacer' import { Page } from '../components/page' import { Title } from '../components/title' +import { usePropz } from '../hooks/use-propz' import { getDailyBets } from '../lib/firebase/bets' import { getDailyComments } from '../lib/firebase/comments' import { getDailyContracts } from '../lib/firebase/contracts' +import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' -export async function getStaticProps() { +export async function getStaticPropz() { const numberOfDays = 80 const today = dayjs(dayjs().format('YYYY-MM-DD')) const startDate = today.subtract(numberOfDays, 'day') @@ -54,11 +56,18 @@ export default function Analytics(props: { dailyContractCounts: number[] dailyCommentCounts: number[] }) { + props = usePropz(getStaticPropz) ?? { + startDate: 0, + dailyActiveUsers: [], + dailyBetCounts: [], + dailyContractCounts: [], + dailyCommentCounts: [], + } return ( - + {!IS_PRIVATE_MANIFOLD && } ) } From 4b216b682e3723040859be8fc1bdd2af09779340 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 15:43:26 -0800 Subject: [PATCH 14/23] Migrate per-env code into common/ --- common/access.ts | 43 +++++++++++++++++++++++++++++++++++++++ functions/src/emails.ts | 11 +++++----- web/lib/firebase/init.ts | 31 ++-------------------------- web/lib/service/stripe.ts | 6 ++---- 4 files changed, 53 insertions(+), 38 deletions(-) diff --git a/common/access.ts b/common/access.ts index 4a128108..8b630f39 100644 --- a/common/access.ts +++ b/common/access.ts @@ -11,3 +11,46 @@ export function isAdmin(email: string) { ] return ADMINS.includes(email) } + +const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' + +export const DOMAINS = { + PROD: 'manifold.markets', + DEV: 'manifold.markets', + THEOREMONE: 'theoremone.manifold.markets', +} + +export const FIREBASE_CONFIGS = { + PROD: { + apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw', + authDomain: 'mantic-markets.firebaseapp.com', + projectId: 'mantic-markets', + storageBucket: 'mantic-markets.appspot.com', + messagingSenderId: '128925704902', + appId: '1:128925704902:web:f61f86944d8ffa2a642dc7', + measurementId: 'G-SSFK1Q138D', + }, + DEV: { + apiKey: 'AIzaSyBoq3rzUa8Ekyo3ZaTnlycQYPRCA26VpOw', + authDomain: 'dev-mantic-markets.firebaseapp.com', + projectId: 'dev-mantic-markets', + storageBucket: 'dev-mantic-markets.appspot.com', + messagingSenderId: '134303100058', + appId: '1:134303100058:web:27f9ea8b83347251f80323', + measurementId: 'G-YJC9E37P37', + }, + THEOREMONE: { + apiKey: 'AIzaSyBSXL6Ys7InNHnCKSy-_E_luhh4Fkj4Z6M', + authDomain: 'theoremone-manifold.firebaseapp.com', + projectId: 'theoremone-manifold', + storageBucket: 'theoremone-manifold.appspot.com', + messagingSenderId: '698012149198', + appId: '1:698012149198:web:b342af75662831aa84b79f', + measurementId: 'G-Y3EZ1WNT6E', + }, +} + +// @ts-ignore +export const DOMAIN = DOMAINS[ENV] +// @ts-ignore +export const PROJECT_ID = FIREBASE_CONFIGS[ENV].projectId diff --git a/functions/src/emails.ts b/functions/src/emails.ts index 0ded7b7d..f8e77221 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -1,4 +1,5 @@ import _ = require('lodash') +import { DOMAIN } from '../../common/access' import { Answer } from '../../common/answer' import { Bet } from '../../common/bet' import { getProbability } from '../../common/calculate' @@ -73,7 +74,7 @@ export const sendMarketResolutionEmail = async ( outcome, investment: `${Math.round(investment)}`, payout: `${Math.round(payout)}`, - url: `https://manifold.markets/${creator.username}/${contract.slug}`, + url: `https://${DOMAIN}/${creator.username}/${contract.slug}`, } // Modify template here: @@ -107,7 +108,7 @@ Or come chat with us on Discord: https://discord.gg/eHQBNBqXuh Best, Austin from Manifold -https://manifold.markets/` +https://${DOMAIN}/` ) } @@ -128,7 +129,7 @@ export const sendMarketCloseEmail = async ( const { question, pool: pools, slug } = contract const pool = formatMoney(_.sum(_.values(pools))) - const url = `https://manifold.markets/${username}/${slug}` + const url = `https://${DOMAIN}/${username}/${slug}` await sendTemplateEmail( privateUser.email, @@ -162,7 +163,7 @@ export const sendNewCommentEmail = async ( return const { question, creatorUsername, slug } = contract - const marketUrl = `https://manifold.markets/${creatorUsername}/${slug}` + const marketUrl = `https://${DOMAIN}/${creatorUsername}/${slug}` const unsubscribeUrl = `https://us-central1-${ isProd ? 'mantic-markets' : 'dev-mantic-markets' @@ -238,7 +239,7 @@ export const sendNewAnswerEmail = async ( const { question, creatorUsername, slug } = contract const { name, avatarUrl, text } = answer - const marketUrl = `https://manifold.markets/${creatorUsername}/${slug}` + const marketUrl = `https://${DOMAIN}/${creatorUsername}/${slug}` const unsubscribeUrl = `https://us-central1-${ isProd ? 'mantic-markets' : 'dev-mantic-markets' }.cloudfunctions.net/unsubscribe?id=${userId}&type=market-answer` diff --git a/web/lib/firebase/init.ts b/web/lib/firebase/init.ts index f183d094..26466e8f 100644 --- a/web/lib/firebase/init.ts +++ b/web/lib/firebase/init.ts @@ -1,39 +1,12 @@ import { getFirestore } from '@firebase/firestore' import { initializeApp, getApps, getApp } from 'firebase/app' +import { FIREBASE_CONFIGS } from '../../../common/access' // Used to decide which Stripe instance to point to export const isProd = process.env.NEXT_PUBLIC_FIREBASE_ENV !== 'DEV' -const FIREBASE_CONFIGS = { - PROD: { - apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw', - authDomain: 'mantic-markets.firebaseapp.com', - projectId: 'mantic-markets', - storageBucket: 'mantic-markets.appspot.com', - messagingSenderId: '128925704902', - appId: '1:128925704902:web:f61f86944d8ffa2a642dc7', - measurementId: 'G-SSFK1Q138D', - }, - DEV: { - apiKey: 'AIzaSyBoq3rzUa8Ekyo3ZaTnlycQYPRCA26VpOw', - authDomain: 'dev-mantic-markets.firebaseapp.com', - projectId: 'dev-mantic-markets', - storageBucket: 'dev-mantic-markets.appspot.com', - messagingSenderId: '134303100058', - appId: '1:134303100058:web:27f9ea8b83347251f80323', - measurementId: 'G-YJC9E37P37', - }, - THEOREMONE: { - apiKey: 'AIzaSyBSXL6Ys7InNHnCKSy-_E_luhh4Fkj4Z6M', - authDomain: 'theoremone-manifold.firebaseapp.com', - projectId: 'theoremone-manifold', - storageBucket: 'theoremone-manifold.appspot.com', - messagingSenderId: '698012149198', - appId: '1:698012149198:web:b342af75662831aa84b79f', - measurementId: 'G-Y3EZ1WNT6E', - }, -} const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' +// TODO: Move this to access.ts export const IS_PRIVATE_MANIFOLD = !['PROD', 'DEV'].includes(ENV) // @ts-ignore const firebaseConfig = FIREBASE_CONFIGS[ENV] diff --git a/web/lib/service/stripe.ts b/web/lib/service/stripe.ts index 3d69c284..84c07d07 100644 --- a/web/lib/service/stripe.ts +++ b/web/lib/service/stripe.ts @@ -1,13 +1,11 @@ -import { isProd } from '../firebase/init' +import { PROJECT_ID } from '../../../common/access' export const checkoutURL = ( userId: string, manticDollarQuantity: number, referer = '' ) => { - const endpoint = isProd - ? 'https://us-central1-mantic-markets.cloudfunctions.net/createCheckoutSession' - : 'https://us-central1-dev-mantic-markets.cloudfunctions.net/createCheckoutSession' + const endpoint = `https://us-central1-${PROJECT_ID}.cloudfunctions.net/createCheckoutSession` return `${endpoint}?userId=${userId}&manticDollarQuantity=${manticDollarQuantity}&referer=${encodeURIComponent( referer From ae63f70a30216d1ee7427870cb1ebf116ee3fbb2 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 15:52:13 -0800 Subject: [PATCH 15/23] More migrations to PROJECT_ID --- functions/src/emails.ts | 12 ++++-------- web/lib/firebase/init.ts | 3 --- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/functions/src/emails.ts b/functions/src/emails.ts index f8e77221..1fdb6f73 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -1,5 +1,5 @@ import _ = require('lodash') -import { DOMAIN } from '../../common/access' +import { DOMAIN, PROJECT_ID } from '../../common/access' import { Answer } from '../../common/answer' import { Bet } from '../../common/bet' import { getProbability } from '../../common/calculate' @@ -9,7 +9,7 @@ import { CREATOR_FEE } from '../../common/fees' import { PrivateUser, User } from '../../common/user' import { formatMoney, formatPercent } from '../../common/util/format' import { sendTemplateEmail, sendTextEmail } from './send-email' -import { getPrivateUser, getUser, isProd } from './utils' +import { getPrivateUser, getUser } from './utils' type market_resolved_template = { userId: string @@ -165,9 +165,7 @@ export const sendNewCommentEmail = async ( const { question, creatorUsername, slug } = contract const marketUrl = `https://${DOMAIN}/${creatorUsername}/${slug}` - const unsubscribeUrl = `https://us-central1-${ - isProd ? 'mantic-markets' : 'dev-mantic-markets' - }.cloudfunctions.net/unsubscribe?id=${userId}&type=market-comment` + const unsubscribeUrl = `https://us-central1-${PROJECT_ID}.cloudfunctions.net/unsubscribe?id=${userId}&type=market-comment` const { name: commentorName, avatarUrl: commentorAvatarUrl } = commentCreator const { text } = comment @@ -240,9 +238,7 @@ export const sendNewAnswerEmail = async ( const { name, avatarUrl, text } = answer const marketUrl = `https://${DOMAIN}/${creatorUsername}/${slug}` - const unsubscribeUrl = `https://us-central1-${ - isProd ? 'mantic-markets' : 'dev-mantic-markets' - }.cloudfunctions.net/unsubscribe?id=${userId}&type=market-answer` + const unsubscribeUrl = `https://us-central1-${PROJECT_ID}.cloudfunctions.net/unsubscribe?id=${userId}&type=market-answer` const subject = `New answer on ${question}` const from = `${name} ` diff --git a/web/lib/firebase/init.ts b/web/lib/firebase/init.ts index 26466e8f..c82e72d6 100644 --- a/web/lib/firebase/init.ts +++ b/web/lib/firebase/init.ts @@ -2,9 +2,6 @@ import { getFirestore } from '@firebase/firestore' import { initializeApp, getApps, getApp } from 'firebase/app' import { FIREBASE_CONFIGS } from '../../../common/access' -// Used to decide which Stripe instance to point to -export const isProd = process.env.NEXT_PUBLIC_FIREBASE_ENV !== 'DEV' - const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' // TODO: Move this to access.ts export const IS_PRIVATE_MANIFOLD = !['PROD', 'DEV'].includes(ENV) From dc29ca531c1a200d1d979d3d33bd293bf622c2d1 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 16:20:06 -0800 Subject: [PATCH 16/23] Conditionally use SSG depending on public vs private instance --- web/hooks/use-propz.ts | 8 ++++++-- web/pages/[username]/[contractSlug].tsx | 25 +++++++++++++------------ web/pages/home.tsx | 14 ++++++++------ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/web/hooks/use-propz.ts b/web/hooks/use-propz.ts index 3687c725..60b6b142 100644 --- a/web/hooks/use-propz.ts +++ b/web/hooks/use-propz.ts @@ -1,6 +1,7 @@ import _ from 'lodash' import { useRouter } from 'next/router' import { useState, useEffect } from 'react' +import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' type PropzProps = { params: any @@ -10,7 +11,7 @@ type PropzProps = { // This allows us to client-side render the page for authenticated users. // TODO: Could cache the result using stale-while-revalidate: https://swr.vercel.app/ export function usePropz( - getStaticPropz: (props?: PropzProps) => Promise, + getStaticPropz: (props: PropzProps) => Promise, // Dynamic routes will need the query params from the router needParams?: boolean ) { @@ -23,8 +24,11 @@ export function usePropz( if (needParams && _.isEmpty(params)) { return } - // @ts-ignore getStaticPropz({ params }).then((result) => setPropz(result.props)) }, [params]) return propz } + +export function fromPropz(getStaticPropz: (props: PropzProps) => Promise) { + return IS_PRIVATE_MANIFOLD ? async () => {} : getStaticPropz +} diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index c7baff55..59d68899 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -29,8 +29,9 @@ import { useFoldsWithTags } from '../../hooks/use-fold' import { listAllAnswers } from '../../lib/firebase/answers' import { Answer } from '../../../common/answer' import { AnswersPanel } from '../../components/answers/answers-panel' -import { usePropz } from '../../hooks/use-propz' +import { fromPropz, usePropz } from '../../hooks/use-propz' +export const getStaticProps = fromPropz(getStaticPropz) export async function getStaticPropz(props: { params: { username: string; contractSlug: string } }) { @@ -65,7 +66,7 @@ export async function getStaticPropz(props: { } } -export async function getStaticPathz() { +export async function getStaticPaths() { return { paths: [], fallback: 'blocking' } } @@ -78,16 +79,16 @@ export default function ContractPage(props: { slug: string folds: Fold[] }) { - // @ts-ignore - props = usePropz(getStaticPropz, true) ?? { - contract: null, - username: '', - comments: [], - answers: [], - bets: [], - slug: '', - folds: [], - } + props = props ?? + usePropz(getStaticPropz, true) ?? { + contract: null, + username: '', + comments: [], + answers: [], + bets: [], + slug: '', + folds: [], + } const user = useUser() const contract = useContractWithPreload(props.slug, props.contract) diff --git a/web/pages/home.tsx b/web/pages/home.tsx index 6ebe500b..0cec2756 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -22,12 +22,13 @@ import { useFilterYourContracts, useFindActiveContracts, } from '../hooks/use-find-active-contracts' -import { usePropz } from '../hooks/use-propz' +import { fromPropz, usePropz } from '../hooks/use-propz' import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' import { useGetRecentBets, useRecentBets } from '../hooks/use-bets' import { useActiveContracts } from '../hooks/use-contracts' import { useRecentComments } from '../hooks/use-comments' +export const getStaticProps = fromPropz(getStaticPropz) export async function getStaticPropz() { const contractInfo = await getAllContractInfo() @@ -42,11 +43,12 @@ const Home = (props: { folds: Fold[] recentComments: Comment[] }) => { - props = usePropz(getStaticPropz) ?? { - contracts: [], - folds: [], - recentComments: [], - } + props = props ?? + usePropz(getStaticPropz) ?? { + contracts: [], + folds: [], + recentComments: [], + } const { folds } = props const user = useUser() From bb897a0a0fdfb5e9c89f81bfbc1a9bde9a5cec85 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 17:14:51 -0800 Subject: [PATCH 17/23] Fix props to be empty object --- web/hooks/use-propz.ts | 11 +++++++++-- web/pages/[username]/[contractSlug].tsx | 19 +++++++++---------- web/pages/analytics.tsx | 5 +++-- web/pages/fold/[...slugs]/index.tsx | 8 ++++---- web/pages/home.tsx | 11 +++++------ web/pages/leaderboards.tsx | 5 +++-- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/web/hooks/use-propz.ts b/web/hooks/use-propz.ts index 60b6b142..1b3e61b1 100644 --- a/web/hooks/use-propz.ts +++ b/web/hooks/use-propz.ts @@ -11,11 +11,17 @@ type PropzProps = { // This allows us to client-side render the page for authenticated users. // TODO: Could cache the result using stale-while-revalidate: https://swr.vercel.app/ export function usePropz( + initialProps: Object, getStaticPropz: (props: PropzProps) => Promise, // Dynamic routes will need the query params from the router needParams?: boolean ) { - // Get params from router + // If props were successfully server-side generated, just use those + if (!_.isEmpty(initialProps)) { + return initialProps + } + + // Otherwise, get params from router const router = useRouter() const params = router.query @@ -29,6 +35,7 @@ export function usePropz( return propz } +// Conditionally disable SSG for private Manifold instances export function fromPropz(getStaticPropz: (props: PropzProps) => Promise) { - return IS_PRIVATE_MANIFOLD ? async () => {} : getStaticPropz + return IS_PRIVATE_MANIFOLD ? async () => ({ props: {} }) : getStaticPropz } diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index 59d68899..39142378 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -79,16 +79,15 @@ export default function ContractPage(props: { slug: string folds: Fold[] }) { - props = props ?? - usePropz(getStaticPropz, true) ?? { - contract: null, - username: '', - comments: [], - answers: [], - bets: [], - slug: '', - folds: [], - } + props = usePropz(props, getStaticPropz, true) ?? { + contract: null, + username: '', + comments: [], + answers: [], + bets: [], + slug: '', + folds: [], + } const user = useUser() const contract = useContractWithPreload(props.slug, props.contract) diff --git a/web/pages/analytics.tsx b/web/pages/analytics.tsx index cbd7b725..f9f92591 100644 --- a/web/pages/analytics.tsx +++ b/web/pages/analytics.tsx @@ -5,12 +5,13 @@ import { Col } from '../components/layout/col' import { Spacer } from '../components/layout/spacer' import { Page } from '../components/page' import { Title } from '../components/title' -import { usePropz } from '../hooks/use-propz' +import { fromPropz, usePropz } from '../hooks/use-propz' import { getDailyBets } from '../lib/firebase/bets' import { getDailyComments } from '../lib/firebase/comments' import { getDailyContracts } from '../lib/firebase/contracts' import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' +export const getStaticProps = fromPropz(getStaticPropz) export async function getStaticPropz() { const numberOfDays = 80 const today = dayjs(dayjs().format('YYYY-MM-DD')) @@ -56,7 +57,7 @@ export default function Analytics(props: { dailyContractCounts: number[] dailyCommentCounts: number[] }) { - props = usePropz(getStaticPropz) ?? { + props = usePropz(props, getStaticPropz) ?? { startDate: 0, dailyActiveUsers: [], dailyBetCounts: [], diff --git a/web/pages/fold/[...slugs]/index.tsx b/web/pages/fold/[...slugs]/index.tsx index 9b82e1d8..6f27c3de 100644 --- a/web/pages/fold/[...slugs]/index.tsx +++ b/web/pages/fold/[...slugs]/index.tsx @@ -38,12 +38,13 @@ import FeedCreate from '../../../components/feed-create' import { SEO } from '../../../components/SEO' import { useTaggedContracts } from '../../../hooks/use-contracts' import { Linkify } from '../../../components/linkify' -import { usePropz } from '../../../hooks/use-propz' +import { fromPropz, usePropz } from '../../../hooks/use-propz' import { filterDefined } from '../../../../common/util/array' import { useRecentBets } from '../../../hooks/use-bets' import { useRecentComments } from '../../../hooks/use-comments' import { LoadingIndicator } from '../../../components/loading-indicator' +export const getStaticProps = fromPropz(getStaticPropz) export async function getStaticPropz(props: { params: { slugs: string[] } }) { const { slugs } = props.params @@ -100,7 +101,7 @@ async function toTopUsers(userScores: { [userId: string]: number }) { return topUsers.filter((user) => user) } -export async function getStaticPathz() { +export async function getStaticPaths() { return { paths: [], fallback: 'blocking' } } const foldSubpages = [undefined, 'activity', 'markets', 'leaderboards'] as const @@ -117,8 +118,7 @@ export default function FoldPage(props: { creatorScores: { [userId: string]: number } topCreators: User[] }) { - // @ts-ignore - props = usePropz(getStaticPropz, true) ?? { + props = usePropz(props, getStaticPropz, true) ?? { fold: null, curator: null, contracts: [], diff --git a/web/pages/home.tsx b/web/pages/home.tsx index 0cec2756..fb9a4a9c 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -43,12 +43,11 @@ const Home = (props: { folds: Fold[] recentComments: Comment[] }) => { - props = props ?? - usePropz(getStaticPropz) ?? { - contracts: [], - folds: [], - recentComments: [], - } + props = usePropz(props, getStaticPropz) ?? { + contracts: [], + folds: [], + recentComments: [], + } const { folds } = props const user = useUser() diff --git a/web/pages/leaderboards.tsx b/web/pages/leaderboards.tsx index 3e7caed2..bf202b6f 100644 --- a/web/pages/leaderboards.tsx +++ b/web/pages/leaderboards.tsx @@ -5,8 +5,9 @@ import { Leaderboard } from '../components/leaderboard' import { Page } from '../components/page' import { getTopCreators, getTopTraders, User } from '../lib/firebase/users' import { formatMoney } from '../../common/util/format' -import { usePropz } from '../hooks/use-propz' +import { fromPropz, usePropz } from '../hooks/use-propz' +export const getStaticProps = fromPropz(getStaticPropz) export async function getStaticPropz() { const [topTraders, topCreators] = await Promise.all([ getTopTraders().catch((_) => {}), @@ -27,7 +28,7 @@ export default function Leaderboards(props: { topTraders: User[] topCreators: User[] }) { - props = usePropz(getStaticPropz) ?? { + props = usePropz(props, getStaticPropz) ?? { topTraders: [], topCreators: [], } From 21180c2ff01c2fbc19e10b8682884fdd5476f23a Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 17:43:23 -0800 Subject: [PATCH 18/23] Move more logic into access --- common/access.ts | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/common/access.ts b/common/access.ts index 8b630f39..68fddd0f 100644 --- a/common/access.ts +++ b/common/access.ts @@ -1,7 +1,17 @@ +const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' + export function isWhitelisted(email?: string) { - return email && (email.endsWith('@theoremone.co') || isAdmin(email)) + switch (ENV) { + case 'THEOREMONE': + return email && (email.endsWith('@theoremone.co') || isAdmin(email)) + case 'PROD': + case 'DEV': + default: + return true + } } +// TODO: Before open sourcing, we should turn these into env vars export function isAdmin(email: string) { const ADMINS = [ 'akrolsmir@gmail.com', // Austin @@ -9,17 +19,12 @@ export function isAdmin(email: string) { 'taowell@gmail.com', // Stephen 'manticmarkets@gmail.com', // Manifold ] + if (ENV === 'THEOREMONE') { + ADMINS.push('david.glidden@theoremone.co') + } return ADMINS.includes(email) } -const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' - -export const DOMAINS = { - PROD: 'manifold.markets', - DEV: 'manifold.markets', - THEOREMONE: 'theoremone.manifold.markets', -} - export const FIREBASE_CONFIGS = { PROD: { apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw', @@ -50,6 +55,11 @@ export const FIREBASE_CONFIGS = { }, } +const DOMAINS = { + PROD: 'manifold.markets', + DEV: 'manifold.markets', + THEOREMONE: 'theoremone.manifold.markets', +} // @ts-ignore export const DOMAIN = DOMAINS[ENV] // @ts-ignore From deed8426f1e4a887fe7766cf67b2f68c44415b6c Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 18:19:36 -0800 Subject: [PATCH 19/23] Spin out config files for each environment --- common/access.ts | 75 ++++++++++----------------------------- common/envs/dev.ts | 14 ++++++++ common/envs/prod.ts | 47 ++++++++++++++++++++++++ common/envs/theoremone.ts | 19 ++++++++++ 4 files changed, 99 insertions(+), 56 deletions(-) create mode 100644 common/envs/dev.ts create mode 100644 common/envs/prod.ts create mode 100644 common/envs/theoremone.ts diff --git a/common/access.ts b/common/access.ts index 68fddd0f..f828b5c8 100644 --- a/common/access.ts +++ b/common/access.ts @@ -1,66 +1,29 @@ +import { DEV_CONFIG } from './envs/dev' +import { EnvConfig, PROD_CONFIG } from './envs/prod' +import { THEOREMONE_CONFIG } from './envs/theoremone' + const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' +const CONFIGS = { + PROD: PROD_CONFIG, + DEV: DEV_CONFIG, + THEOREMONE: THEOREMONE_CONFIG, +} +// @ts-ignore +export const ENV_CONFIG: EnvConfig = CONFIGS[ENV] + export function isWhitelisted(email?: string) { - switch (ENV) { - case 'THEOREMONE': - return email && (email.endsWith('@theoremone.co') || isAdmin(email)) - case 'PROD': - case 'DEV': - default: - return true + if (!ENV_CONFIG.whitelistEmail) { + return true } + return email && (email.endsWith(ENV_CONFIG.whitelistEmail) || isAdmin(email)) } // TODO: Before open sourcing, we should turn these into env vars export function isAdmin(email: string) { - const ADMINS = [ - 'akrolsmir@gmail.com', // Austin - 'jahooma@gmail.com', // James - 'taowell@gmail.com', // Stephen - 'manticmarkets@gmail.com', // Manifold - ] - if (ENV === 'THEOREMONE') { - ADMINS.push('david.glidden@theoremone.co') - } - return ADMINS.includes(email) + return ENV_CONFIG.adminEmails.includes(email) } -export const FIREBASE_CONFIGS = { - PROD: { - apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw', - authDomain: 'mantic-markets.firebaseapp.com', - projectId: 'mantic-markets', - storageBucket: 'mantic-markets.appspot.com', - messagingSenderId: '128925704902', - appId: '1:128925704902:web:f61f86944d8ffa2a642dc7', - measurementId: 'G-SSFK1Q138D', - }, - DEV: { - apiKey: 'AIzaSyBoq3rzUa8Ekyo3ZaTnlycQYPRCA26VpOw', - authDomain: 'dev-mantic-markets.firebaseapp.com', - projectId: 'dev-mantic-markets', - storageBucket: 'dev-mantic-markets.appspot.com', - messagingSenderId: '134303100058', - appId: '1:134303100058:web:27f9ea8b83347251f80323', - measurementId: 'G-YJC9E37P37', - }, - THEOREMONE: { - apiKey: 'AIzaSyBSXL6Ys7InNHnCKSy-_E_luhh4Fkj4Z6M', - authDomain: 'theoremone-manifold.firebaseapp.com', - projectId: 'theoremone-manifold', - storageBucket: 'theoremone-manifold.appspot.com', - messagingSenderId: '698012149198', - appId: '1:698012149198:web:b342af75662831aa84b79f', - measurementId: 'G-Y3EZ1WNT6E', - }, -} - -const DOMAINS = { - PROD: 'manifold.markets', - DEV: 'manifold.markets', - THEOREMONE: 'theoremone.manifold.markets', -} -// @ts-ignore -export const DOMAIN = DOMAINS[ENV] -// @ts-ignore -export const PROJECT_ID = FIREBASE_CONFIGS[ENV].projectId +export const DOMAIN = ENV_CONFIG.domain +export const FIREBASE_CONFIG = ENV_CONFIG.firebaseConfig +export const PROJECT_ID = ENV_CONFIG.firebaseConfig.projectId diff --git a/common/envs/dev.ts b/common/envs/dev.ts new file mode 100644 index 00000000..9b82f3c0 --- /dev/null +++ b/common/envs/dev.ts @@ -0,0 +1,14 @@ +import { EnvConfig, PROD_CONFIG } from './prod' + +export const DEV_CONFIG: EnvConfig = { + ...PROD_CONFIG, + firebaseConfig: { + apiKey: 'AIzaSyBoq3rzUa8Ekyo3ZaTnlycQYPRCA26VpOw', + authDomain: 'dev-mantic-markets.firebaseapp.com', + projectId: 'dev-mantic-markets', + storageBucket: 'dev-mantic-markets.appspot.com', + messagingSenderId: '134303100058', + appId: '1:134303100058:web:27f9ea8b83347251f80323', + measurementId: 'G-YJC9E37P37', + }, +} diff --git a/common/envs/prod.ts b/common/envs/prod.ts new file mode 100644 index 00000000..e25c2661 --- /dev/null +++ b/common/envs/prod.ts @@ -0,0 +1,47 @@ +export type EnvConfig = { + domain: string + firebaseConfig: FirebaseConfig + + // Access controls + adminEmails: string[] + whitelistEmail?: string // e.g. '@theoremone.co'. If not provided, all emails are whitelisted + visibility: 'PRIVATE' | 'PUBLIC' + + // Branding + moneyMoniker: string // e.g. 'M$' + faviconPath?: string // Should be a file in /public + navbarLogoPath?: string +} + +type FirebaseConfig = { + apiKey: string + authDomain: string + projectId: string + storageBucket: string + messagingSenderId: string + appId: string + measurementId: string +} + +export const PROD_CONFIG: EnvConfig = { + domain: 'manifold.markets', + firebaseConfig: { + apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw', + authDomain: 'mantic-markets.firebaseapp.com', + projectId: 'mantic-markets', + storageBucket: 'mantic-markets.appspot.com', + messagingSenderId: '128925704902', + appId: '1:128925704902:web:f61f86944d8ffa2a642dc7', + measurementId: 'G-SSFK1Q138D', + }, + adminEmails: [ + 'akrolsmir@gmail.com', // Austin + 'jahooma@gmail.com', // James + 'taowell@gmail.com', // Stephen + 'manticmarkets@gmail.com', // Manifold + ], + moneyMoniker: 'M$', + visibility: 'PUBLIC', + navbarLogoPath: '', + faviconPath: '/favicon.ico', +} diff --git a/common/envs/theoremone.ts b/common/envs/theoremone.ts new file mode 100644 index 00000000..3cd9d0d8 --- /dev/null +++ b/common/envs/theoremone.ts @@ -0,0 +1,19 @@ +import { EnvConfig, PROD_CONFIG } from './prod' + +export const THEOREMONE_CONFIG: EnvConfig = { + domain: 'theoremone.manifold.markets', + firebaseConfig: { + apiKey: 'AIzaSyBSXL6Ys7InNHnCKSy-_E_luhh4Fkj4Z6M', + authDomain: 'theoremone-manifold.firebaseapp.com', + projectId: 'theoremone-manifold', + storageBucket: 'theoremone-manifold.appspot.com', + messagingSenderId: '698012149198', + appId: '1:698012149198:web:b342af75662831aa84b79f', + measurementId: 'G-Y3EZ1WNT6E', + }, + adminEmails: [...PROD_CONFIG.adminEmails, 'david.glidden@theoremone.co'], + whitelistEmail: '@theoremone.co', + moneyMoniker: 'T$', + visibility: 'PRIVATE', + faviconPath: '/theoremone/logo.ico', +} From cb071fc9b3a23649c0048118ca930cc9f1098b54 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 18:34:49 -0800 Subject: [PATCH 20/23] Generify most of the customizable brand stuff --- common/envs/prod.ts | 10 +++++++++- common/envs/theoremone.ts | 7 +++++++ common/util/format.ts | 6 +++++- web/components/feed-create.tsx | 13 ++----------- web/components/manifold-logo.tsx | 26 +++++++++++++++++++++++++- web/lib/firebase/init.ts | 6 ++---- web/pages/_document.tsx | 3 ++- 7 files changed, 52 insertions(+), 19 deletions(-) diff --git a/common/envs/prod.ts b/common/envs/prod.ts index e25c2661..20866429 100644 --- a/common/envs/prod.ts +++ b/common/envs/prod.ts @@ -11,6 +11,7 @@ export type EnvConfig = { moneyMoniker: string // e.g. 'M$' faviconPath?: string // Should be a file in /public navbarLogoPath?: string + newQuestionPlaceholders: string[] } type FirebaseConfig = { @@ -40,8 +41,15 @@ export const PROD_CONFIG: EnvConfig = { 'taowell@gmail.com', // Stephen 'manticmarkets@gmail.com', // Manifold ], - moneyMoniker: 'M$', visibility: 'PUBLIC', + + moneyMoniker: 'M$', navbarLogoPath: '', faviconPath: '/favicon.ico', + newQuestionPlaceholders: [ + 'Will anyone I know get engaged this year?', + 'Will humans set foot on Mars by the end of 2030?', + 'Will any cryptocurrency eclipse Bitcoin by market cap this year?', + 'Will the Democrats win the 2024 presidential election?', + ], } diff --git a/common/envs/theoremone.ts b/common/envs/theoremone.ts index 3cd9d0d8..ebe504d9 100644 --- a/common/envs/theoremone.ts +++ b/common/envs/theoremone.ts @@ -16,4 +16,11 @@ export const THEOREMONE_CONFIG: EnvConfig = { moneyMoniker: 'T$', visibility: 'PRIVATE', faviconPath: '/theoremone/logo.ico', + navbarLogoPath: '/theoremone/TheoremOne-Logo.svg', + newQuestionPlaceholders: [ + 'Will we have at least 5 new team members by the end of this quarter?', + 'Will we meet or exceed our goals this sprint?', + 'Will we sign on 3 or more new clients this month?', + 'Will Paul shave his beard by the end of the month?', + ], } diff --git a/common/util/format.ts b/common/util/format.ts index 00fb6077..5a9a3208 100644 --- a/common/util/format.ts +++ b/common/util/format.ts @@ -1,3 +1,5 @@ +import { ENV_CONFIG } from '../access' + const formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', @@ -6,7 +8,9 @@ const formatter = new Intl.NumberFormat('en-US', { }) export function formatMoney(amount: number) { - return 'T$ ' + formatter.format(amount).replace('$', '') + return ( + ENV_CONFIG.moneyMoniker + ' ' + formatter.format(amount).replace('$', '') + ) } export function formatWithCommas(amount: number) { diff --git a/web/components/feed-create.tsx b/web/components/feed-create.tsx index c8d838ca..90b99837 100644 --- a/web/components/feed-create.tsx +++ b/web/components/feed-create.tsx @@ -9,6 +9,7 @@ import { Contract } from '../../common/contract' import { Col } from './layout/col' import clsx from 'clsx' import { Row } from './layout/row' +import { ENV_CONFIG } from '../../common/access' export function FeedPromo(props: { hotContracts: Contract[] }) { const { hotContracts } = props @@ -72,20 +73,10 @@ export default function FeedCreate(props: { const [isExpanded, setIsExpanded] = useState(false) const inputRef = useRef() - const placeholders = [ - // 'Will anyone I know get engaged this year?', - // 'Will humans set foot on Mars by the end of 2030?', - // 'Will any cryptocurrency eclipse Bitcoin by market cap this year?', - // 'Will the Democrats win the 2024 presidential election?', - 'Will we have at least 5 new team members by the end of this quarter?', - 'Will we meet or exceed our goals this sprint?', - 'Will we sign on 3 or more new clients this month?', - 'Will Paul shave his beard by the end of the month?', - ] + const placeholders = ENV_CONFIG.newQuestionPlaceholders // Rotate through a new placeholder each day // Easter egg idea: click your own name to shuffle the placeholder // const daysSinceEpoch = Math.floor(Date.now() / 1000 / 60 / 60 / 24) - const [randIndex] = useState( Math.floor(Math.random() * 1e10) % placeholders.length ) diff --git a/web/components/manifold-logo.tsx b/web/components/manifold-logo.tsx index ff57f5da..8654e269 100644 --- a/web/components/manifold-logo.tsx +++ b/web/components/manifold-logo.tsx @@ -2,6 +2,7 @@ import Link from 'next/link' import clsx from 'clsx' import { useUser } from '../hooks/use-user' +import { ENV_CONFIG } from '../../common/access' export function ManifoldLogo(props: { className?: string @@ -20,7 +21,30 @@ export function ManifoldLogo(props: { width={45} height={45} /> - + {ENV_CONFIG.navbarLogoPath ? ( + + ) : ( + <> +
+ Manifold +
+ Markets +
+ + + )} ) diff --git a/web/lib/firebase/init.ts b/web/lib/firebase/init.ts index c82e72d6..7b2e7862 100644 --- a/web/lib/firebase/init.ts +++ b/web/lib/firebase/init.ts @@ -1,13 +1,11 @@ import { getFirestore } from '@firebase/firestore' import { initializeApp, getApps, getApp } from 'firebase/app' -import { FIREBASE_CONFIGS } from '../../../common/access' +import { FIREBASE_CONFIG } from '../../../common/access' const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' // TODO: Move this to access.ts export const IS_PRIVATE_MANIFOLD = !['PROD', 'DEV'].includes(ENV) -// @ts-ignore -const firebaseConfig = FIREBASE_CONFIGS[ENV] // Initialize Firebase -export const app = getApps().length ? getApp() : initializeApp(firebaseConfig) +export const app = getApps().length ? getApp() : initializeApp(FIREBASE_CONFIG) export const db = getFirestore(app) diff --git a/web/pages/_document.tsx b/web/pages/_document.tsx index 5e8e262e..5cae7052 100644 --- a/web/pages/_document.tsx +++ b/web/pages/_document.tsx @@ -1,10 +1,11 @@ import { Html, Head, Main, NextScript } from 'next/document' +import { ENV_CONFIG } from '../../common/access' export default function Document() { return ( - + Date: Mon, 7 Mar 2022 20:47:50 -0800 Subject: [PATCH 21/23] Move IS_PRIVATE_MANIFOLD to access.ts --- common/access.ts | 1 + web/components/profile-menu.tsx | 2 +- web/hooks/use-propz.ts | 2 +- web/lib/firebase/init.ts | 3 --- web/pages/404.tsx | 3 +-- web/pages/analytics.tsx | 2 +- web/pages/home.tsx | 2 +- 7 files changed, 6 insertions(+), 9 deletions(-) diff --git a/common/access.ts b/common/access.ts index f828b5c8..c0b67094 100644 --- a/common/access.ts +++ b/common/access.ts @@ -27,3 +27,4 @@ export function isAdmin(email: string) { export const DOMAIN = ENV_CONFIG.domain export const FIREBASE_CONFIG = ENV_CONFIG.firebaseConfig export const PROJECT_ID = ENV_CONFIG.firebaseConfig.projectId +export const IS_PRIVATE_MANIFOLD = ENV_CONFIG.visibility === 'PRIVATE' diff --git a/web/components/profile-menu.tsx b/web/components/profile-menu.tsx index 342b20f4..bfc69fdb 100644 --- a/web/components/profile-menu.tsx +++ b/web/components/profile-menu.tsx @@ -3,7 +3,7 @@ import { formatMoney } from '../../common/util/format' import { Avatar } from './avatar' import { Col } from './layout/col' import { MenuButton } from './menu' -import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' +import { IS_PRIVATE_MANIFOLD } from '../../common/access' export function ProfileMenu(props: { user: User | undefined }) { const { user } = props diff --git a/web/hooks/use-propz.ts b/web/hooks/use-propz.ts index 1b3e61b1..bf4046d3 100644 --- a/web/hooks/use-propz.ts +++ b/web/hooks/use-propz.ts @@ -1,7 +1,7 @@ import _ from 'lodash' import { useRouter } from 'next/router' import { useState, useEffect } from 'react' -import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' +import { IS_PRIVATE_MANIFOLD } from '../../common/access' type PropzProps = { params: any diff --git a/web/lib/firebase/init.ts b/web/lib/firebase/init.ts index 7b2e7862..aec2a4c0 100644 --- a/web/lib/firebase/init.ts +++ b/web/lib/firebase/init.ts @@ -2,9 +2,6 @@ import { getFirestore } from '@firebase/firestore' import { initializeApp, getApps, getApp } from 'firebase/app' import { FIREBASE_CONFIG } from '../../../common/access' -const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' -// TODO: Move this to access.ts -export const IS_PRIVATE_MANIFOLD = !['PROD', 'DEV'].includes(ENV) // Initialize Firebase export const app = getApps().length ? getApp() : initializeApp(FIREBASE_CONFIG) diff --git a/web/pages/404.tsx b/web/pages/404.tsx index 3908a051..d3f10c83 100644 --- a/web/pages/404.tsx +++ b/web/pages/404.tsx @@ -1,7 +1,6 @@ -import { useEffect } from 'gridjs' +import { IS_PRIVATE_MANIFOLD } from '../../common/access' import { Page } from '../components/page' import { Title } from '../components/title' -import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' export default function Custom404() { if (IS_PRIVATE_MANIFOLD) { diff --git a/web/pages/analytics.tsx b/web/pages/analytics.tsx index f9f92591..76e09c06 100644 --- a/web/pages/analytics.tsx +++ b/web/pages/analytics.tsx @@ -1,5 +1,6 @@ import dayjs from 'dayjs' import _ from 'lodash' +import { IS_PRIVATE_MANIFOLD } from '../../common/access' import { DailyCountChart } from '../components/analytics/charts' import { Col } from '../components/layout/col' import { Spacer } from '../components/layout/spacer' @@ -9,7 +10,6 @@ import { fromPropz, usePropz } from '../hooks/use-propz' import { getDailyBets } from '../lib/firebase/bets' import { getDailyComments } from '../lib/firebase/comments' import { getDailyContracts } from '../lib/firebase/contracts' -import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' export const getStaticProps = fromPropz(getStaticPropz) export async function getStaticPropz() { diff --git a/web/pages/home.tsx b/web/pages/home.tsx index fb9a4a9c..c5b6e804 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -23,10 +23,10 @@ import { useFindActiveContracts, } from '../hooks/use-find-active-contracts' import { fromPropz, usePropz } from '../hooks/use-propz' -import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init' import { useGetRecentBets, useRecentBets } from '../hooks/use-bets' import { useActiveContracts } from '../hooks/use-contracts' import { useRecentComments } from '../hooks/use-comments' +import { IS_PRIVATE_MANIFOLD } from '../../common/access' export const getStaticProps = fromPropz(getStaticPropz) export async function getStaticPropz() { From 22799d1c3ca298f4b2ed0e4e657cb0112d233a76 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 20:52:10 -0800 Subject: [PATCH 22/23] Rename access.ts to envs/constants.ts --- common/{access.ts => envs/constants.ts} | 6 +++--- common/util/format.ts | 2 +- functions/src/create-user.ts | 2 +- functions/src/emails.ts | 2 +- web/components/feed-create.tsx | 2 +- web/components/manifold-logo.tsx | 2 +- web/components/profile-menu.tsx | 2 +- web/hooks/use-admin.ts | 2 +- web/hooks/use-propz.ts | 2 +- web/lib/firebase/init.ts | 2 +- web/lib/service/stripe.ts | 2 +- web/pages/404.tsx | 2 +- web/pages/_document.tsx | 2 +- web/pages/analytics.tsx | 2 +- web/pages/home.tsx | 2 +- 15 files changed, 17 insertions(+), 17 deletions(-) rename common/{access.ts => envs/constants.ts} (84%) diff --git a/common/access.ts b/common/envs/constants.ts similarity index 84% rename from common/access.ts rename to common/envs/constants.ts index c0b67094..b87948a7 100644 --- a/common/access.ts +++ b/common/envs/constants.ts @@ -1,6 +1,6 @@ -import { DEV_CONFIG } from './envs/dev' -import { EnvConfig, PROD_CONFIG } from './envs/prod' -import { THEOREMONE_CONFIG } from './envs/theoremone' +import { DEV_CONFIG } from './dev' +import { EnvConfig, PROD_CONFIG } from './prod' +import { THEOREMONE_CONFIG } from './theoremone' const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' diff --git a/common/util/format.ts b/common/util/format.ts index 5a9a3208..a8e6f58a 100644 --- a/common/util/format.ts +++ b/common/util/format.ts @@ -1,4 +1,4 @@ -import { ENV_CONFIG } from '../access' +import { ENV_CONFIG } from '../envs/constants' const formatter = new Intl.NumberFormat('en-US', { style: 'currency', diff --git a/functions/src/create-user.ts b/functions/src/create-user.ts index f583abe4..f73b868b 100644 --- a/functions/src/create-user.ts +++ b/functions/src/create-user.ts @@ -14,7 +14,7 @@ import { cleanUsername, } from '../../common/util/clean-username' import { sendWelcomeEmail } from './emails' -import { isWhitelisted } from '../../common/access' +import { isWhitelisted } from '../../common/envs/constants' export const createUser = functions .runWith({ minInstances: 1 }) diff --git a/functions/src/emails.ts b/functions/src/emails.ts index 1fdb6f73..3d37ba2b 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -1,5 +1,5 @@ import _ = require('lodash') -import { DOMAIN, PROJECT_ID } from '../../common/access' +import { DOMAIN, PROJECT_ID } from '../../common/envs/constants' import { Answer } from '../../common/answer' import { Bet } from '../../common/bet' import { getProbability } from '../../common/calculate' diff --git a/web/components/feed-create.tsx b/web/components/feed-create.tsx index 90b99837..00bbc31f 100644 --- a/web/components/feed-create.tsx +++ b/web/components/feed-create.tsx @@ -9,7 +9,7 @@ import { Contract } from '../../common/contract' import { Col } from './layout/col' import clsx from 'clsx' import { Row } from './layout/row' -import { ENV_CONFIG } from '../../common/access' +import { ENV_CONFIG } from '../../common/envs/constants' export function FeedPromo(props: { hotContracts: Contract[] }) { const { hotContracts } = props diff --git a/web/components/manifold-logo.tsx b/web/components/manifold-logo.tsx index 8654e269..26344bf3 100644 --- a/web/components/manifold-logo.tsx +++ b/web/components/manifold-logo.tsx @@ -2,7 +2,7 @@ import Link from 'next/link' import clsx from 'clsx' import { useUser } from '../hooks/use-user' -import { ENV_CONFIG } from '../../common/access' +import { ENV_CONFIG } from '../../common/envs/constants' export function ManifoldLogo(props: { className?: string diff --git a/web/components/profile-menu.tsx b/web/components/profile-menu.tsx index bfc69fdb..a01614b1 100644 --- a/web/components/profile-menu.tsx +++ b/web/components/profile-menu.tsx @@ -3,7 +3,7 @@ import { formatMoney } from '../../common/util/format' import { Avatar } from './avatar' import { Col } from './layout/col' import { MenuButton } from './menu' -import { IS_PRIVATE_MANIFOLD } from '../../common/access' +import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants' export function ProfileMenu(props: { user: User | undefined }) { const { user } = props diff --git a/web/hooks/use-admin.ts b/web/hooks/use-admin.ts index bbeaf59c..7c8b8449 100644 --- a/web/hooks/use-admin.ts +++ b/web/hooks/use-admin.ts @@ -1,4 +1,4 @@ -import { isAdmin } from '../../common/access' +import { isAdmin } from '../../common/envs/constants' import { usePrivateUser, useUser } from './use-user' export const useAdmin = () => { diff --git a/web/hooks/use-propz.ts b/web/hooks/use-propz.ts index bf4046d3..16315929 100644 --- a/web/hooks/use-propz.ts +++ b/web/hooks/use-propz.ts @@ -1,7 +1,7 @@ import _ from 'lodash' import { useRouter } from 'next/router' import { useState, useEffect } from 'react' -import { IS_PRIVATE_MANIFOLD } from '../../common/access' +import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants' type PropzProps = { params: any diff --git a/web/lib/firebase/init.ts b/web/lib/firebase/init.ts index aec2a4c0..b11ad355 100644 --- a/web/lib/firebase/init.ts +++ b/web/lib/firebase/init.ts @@ -1,6 +1,6 @@ import { getFirestore } from '@firebase/firestore' import { initializeApp, getApps, getApp } from 'firebase/app' -import { FIREBASE_CONFIG } from '../../../common/access' +import { FIREBASE_CONFIG } from '../../../common/envs/constants' // Initialize Firebase export const app = getApps().length ? getApp() : initializeApp(FIREBASE_CONFIG) diff --git a/web/lib/service/stripe.ts b/web/lib/service/stripe.ts index 84c07d07..6c093483 100644 --- a/web/lib/service/stripe.ts +++ b/web/lib/service/stripe.ts @@ -1,4 +1,4 @@ -import { PROJECT_ID } from '../../../common/access' +import { PROJECT_ID } from '../../../common/envs/constants' export const checkoutURL = ( userId: string, diff --git a/web/pages/404.tsx b/web/pages/404.tsx index d3f10c83..f710263d 100644 --- a/web/pages/404.tsx +++ b/web/pages/404.tsx @@ -1,4 +1,4 @@ -import { IS_PRIVATE_MANIFOLD } from '../../common/access' +import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants' import { Page } from '../components/page' import { Title } from '../components/title' diff --git a/web/pages/_document.tsx b/web/pages/_document.tsx index 5cae7052..18329b12 100644 --- a/web/pages/_document.tsx +++ b/web/pages/_document.tsx @@ -1,5 +1,5 @@ import { Html, Head, Main, NextScript } from 'next/document' -import { ENV_CONFIG } from '../../common/access' +import { ENV_CONFIG } from '../../common/envs/constants' export default function Document() { return ( diff --git a/web/pages/analytics.tsx b/web/pages/analytics.tsx index 76e09c06..c2e0ac99 100644 --- a/web/pages/analytics.tsx +++ b/web/pages/analytics.tsx @@ -1,6 +1,6 @@ import dayjs from 'dayjs' import _ from 'lodash' -import { IS_PRIVATE_MANIFOLD } from '../../common/access' +import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants' import { DailyCountChart } from '../components/analytics/charts' import { Col } from '../components/layout/col' import { Spacer } from '../components/layout/spacer' diff --git a/web/pages/home.tsx b/web/pages/home.tsx index c5b6e804..8e10106f 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -26,7 +26,7 @@ import { fromPropz, usePropz } from '../hooks/use-propz' import { useGetRecentBets, useRecentBets } from '../hooks/use-bets' import { useActiveContracts } from '../hooks/use-contracts' import { useRecentComments } from '../hooks/use-comments' -import { IS_PRIVATE_MANIFOLD } from '../../common/access' +import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants' export const getStaticProps = fromPropz(getStaticPropz) export async function getStaticPropz() { From 20e55f829a8056e525fe48d1d9b2a95c76294b7d Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 20:58:46 -0800 Subject: [PATCH 23/23] Add "dev:dev" alias --- web/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/web/package.json b/web/package.json index 7922f346..61342e4d 100644 --- a/web/package.json +++ b/web/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "concurrently -n NEXT,TS -c magenta,cyan \"next dev -p 3000\" \"yarn ts --watch\"", "devdev": "NEXT_PUBLIC_FIREBASE_ENV=DEV concurrently -n NEXT,TS -c magenta,cyan \"FIREBASE_ENV=DEV next dev -p 3000\" \"FIREBASE_ENV=DEV yarn ts --watch\"", + "dev:dev": "yarn devdev", "dev:the": "NEXT_PUBLIC_FIREBASE_ENV=THEOREMONE concurrently -n NEXT,TS -c magenta,cyan \"FIREBASE_ENV=THEOREMONE next dev -p 3000\" \"FIREBASE_ENV=THEOREMONE yarn ts --watch\"", "ts": "tsc --noEmit --incremental --preserveWatchOutput --pretty", "build": "next build",