Skip to content

Commit

Permalink
USE INDEXER (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso authored Jan 8, 2023
1 parent f9ba65e commit 5255d13
Show file tree
Hide file tree
Showing 168 changed files with 4,141 additions and 2,581 deletions.
10 changes: 10 additions & 0 deletions apps/dapp/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ NEXT_PUBLIC_STARGAZE_URL_BASE=https://stargaze.zone
# Wallet profiles
NEXT_PUBLIC_PFPK_API_BASE=https://pfpk.daodao.zone

# Search
NEXT_PUBLIC_SEARCH_HOST=https://search.daodao.zone
NEXT_PUBLIC_SEARCH_API_KEY=613511c001942ea974f72dde06647428d1ae3f42cb13fcf71e88e4317d73f2cf
NEXT_PUBLIC_SEARCH_DAOS_INDEX=daos

# https://nft.storage/docs/#get-an-api-token
NEXT_PUBLIC_NFT_STORAGE_API_KEY=

Expand All @@ -41,3 +46,8 @@ NEXT_PUBLIC_IPFS_GATEWAY_TEMPLATE=https://nftstorage.link/ipfs/PATH

# Comma separated list of action keys to disable.
NEXT_PUBLIC_DISABLED_ACTIONS=

# Discord notifier
NEXT_PUBLIC_DISCORD_NOTIFIER_CLIENT_ID=1060326264801595402
NEXT_PUBLIC_DISCORD_NOTIFIER_REDIRECT_URI=https://testnet.daodao.zone/discord
NEXT_PUBLIC_DISCORD_NOTIFIER_API_BASE=https://discord-notifier.dao-dao.workers.dev
10 changes: 10 additions & 0 deletions apps/dapp/.env.localhost
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ NEXT_PUBLIC_STARGAZE_URL_BASE=https://testnet.publicawesome.dev
# Wallet profiles
NEXT_PUBLIC_PFPK_API_BASE=https://pfpk.daodao.zone

# Search
NEXT_PUBLIC_SEARCH_HOST=https://search.daodao.zone
NEXT_PUBLIC_SEARCH_API_KEY=613511c001942ea974f72dde06647428d1ae3f42cb13fcf71e88e4317d73f2cf
NEXT_PUBLIC_SEARCH_DAOS_INDEX=testnet_daos

# Payroll
NEXT_PUBLIC_RETROACTIVE_COMPENSATION_API_BASE=https://retroactive-compensation-cf-worker.dao-dao.workers.dev

Expand All @@ -36,3 +41,8 @@ NEXT_PUBLIC_IPFS_GATEWAY_TEMPLATE=https://nftstorage.link/ipfs/PATH

# Comma separated list of action keys to disable.
NEXT_PUBLIC_DISABLED_ACTIONS=

# Discord notifications
NEXT_PUBLIC_DISCORD_NOTIFIER_CLIENT_ID=1060326264801595402
NEXT_PUBLIC_DISCORD_NOTIFIER_REDIRECT_URI=http://localhost:3000/discord
NEXT_PUBLIC_DISCORD_NOTIFIER_API_BASE=https://discord-notifier.dao-dao.workers.dev
10 changes: 10 additions & 0 deletions apps/dapp/.env.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ NEXT_PUBLIC_STARGAZE_URL_BASE=https://stargaze.zone
# Wallet profiles
NEXT_PUBLIC_PFPK_API_BASE=https://pfpk.daodao.zone

# Search
NEXT_PUBLIC_SEARCH_HOST=https://search.daodao.zone
NEXT_PUBLIC_SEARCH_API_KEY=613511c001942ea974f72dde06647428d1ae3f42cb13fcf71e88e4317d73f2cf
NEXT_PUBLIC_SEARCH_DAOS_INDEX=daos

# https://nft.storage/docs/#get-an-api-token
NEXT_PUBLIC_NFT_STORAGE_API_KEY=

Expand All @@ -41,3 +46,8 @@ NEXT_PUBLIC_IPFS_GATEWAY_TEMPLATE=https://nftstorage.link/ipfs/PATH

# Comma separated list of action keys to disable.
NEXT_PUBLIC_DISABLED_ACTIONS=

# Discord notifications
NEXT_PUBLIC_DISCORD_NOTIFIER_CLIENT_ID=1060326264801595402
NEXT_PUBLIC_DISCORD_NOTIFIER_REDIRECT_URI=https://daodao.zone/discord
NEXT_PUBLIC_DISCORD_NOTIFIER_API_BASE=https://discord-notifier.dao-dao.workers.dev
2 changes: 2 additions & 0 deletions apps/dapp/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const { i18n } = require('./next-i18next.config')

/** @type {import("next").NextConfig} */
const config = {
// Faster minifier during Next build.
swcMinify: true,
i18n,
/*
The reactStrictMode flag is set to false
Expand Down
2 changes: 1 addition & 1 deletion apps/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"formidable": "^2.0.1",
"interchain-rpc": "^1.5.0",
"lodash.clonedeep": "^4.5.0",
"next": "^12.2.0",
"next": "12.2.6",
"next-intercept-stdout": "^1.0.1",
"next-seo": "^5.4.0",
"nft.storage": "^7.0.0",
Expand Down
27 changes: 21 additions & 6 deletions apps/dapp/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ import { RecoilRoot, useRecoilState, useSetRecoilState } from 'recoil'

import {
activeThemeAtom,
featuredDaoDumpStatesAtom,
mountedInBrowserAtom,
navigatingToHrefAtom,
} from '@dao-dao/state'
import { AppLayout, SubQueryProvider, WalletProvider } from '@dao-dao/stateful'
import { ApolloGqlProvider, AppLayout, WalletProvider } from '@dao-dao/stateful'
import { Theme, ThemeProvider, ToastNotifications } from '@dao-dao/stateless'
import { SITE_IMAGE, SITE_URL } from '@dao-dao/utils'

const InnerApp = ({ Component, pageProps }: AppProps) => {
type DappProps = AppProps<{ featuredDaoDumpStates?: any[] } | {}>

const InnerApp = ({ Component, pageProps }: DappProps) => {
const router = useRouter()

const setMountedInBrowser = useSetRecoilState(mountedInBrowserAtom)
Expand Down Expand Up @@ -65,7 +68,7 @@ const InnerApp = ({ Component, pageProps }: AppProps) => {
themeChangeCount={themeChangeCount}
updateTheme={setTheme}
>
<SubQueryProvider>
<ApolloGqlProvider>
{/* Don't mount wallet or load AppLayout while static page data is still loading. Things look weird and broken, and the wallet connects twice. AppLayout uses wallet hook, which depends on WalletProvider, so use placeholder Layout during fallback. */}
{router.isFallback ? (
<LayoutLoading>
Expand All @@ -82,7 +85,7 @@ const InnerApp = ({ Component, pageProps }: AppProps) => {
)}

<ToastNotifications />
</SubQueryProvider>
</ApolloGqlProvider>
</ThemeProvider>
)
}
Expand All @@ -92,7 +95,7 @@ const LayoutLoading = ({ children }: { children: ReactNode }) => (
<main className="h-full min-h-screen w-full overflow-hidden">{children}</main>
)

const DApp = (props: AppProps) => {
const DApp = (props: DappProps) => {
const { t } = useTranslation()

return (
Expand Down Expand Up @@ -163,7 +166,19 @@ const DApp = (props: AppProps) => {
}}
/>

<RecoilRoot>
<RecoilRoot
initializeState={(snapshot) => {
if (
'featuredDaoDumpStates' in props.pageProps &&
Array.isArray(props.pageProps.featuredDaoDumpStates)
) {
snapshot.set(
featuredDaoDumpStatesAtom,
props.pageProps.featuredDaoDumpStates
)
}
}}
>
<InnerApp {...props} />
</RecoilRoot>
</>
Expand Down
170 changes: 94 additions & 76 deletions apps/dapp/pages/dao/[address]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@
import { useWallet } from '@noahsaso/cosmodal'
import type { GetStaticPaths, NextPage } from 'next'
import { useRouter } from 'next/router'
import React, { useEffect, useMemo } from 'react'
import React, { useEffect, useMemo, useState } from 'react'
import toast from 'react-hot-toast'
import { useTranslation } from 'react-i18next'
import {
constSelector,
useRecoilValue,
useRecoilValueLoadable,
waitForAll,
} from 'recoil'
import { constSelector, useRecoilValueLoadable, waitForAll } from 'recoil'

import { DaoCoreV2Selectors } from '@dao-dao/state'
import {
DaoInfoBar,
DaoPageWrapper,
DaoPageWrapperProps,
DiscordNotifierConfigureModal,
LinkWrapper,
ProposalsTab,
SubDaosTab,
SuspenseLoader,
TreasuryAndNftsTab,
useEncodedDaoProposalSinglePrefill,
useMembership,
usePinnedDaos,
useVotingModule,
useWalletInfo,
} from '@dao-dao/stateful'
import { useCoreActionForKey } from '@dao-dao/stateful/actions'
Expand All @@ -36,10 +32,12 @@ import { makeGetDaoStaticProps } from '@dao-dao/stateful/server'
import { useVotingModuleAdapter } from '@dao-dao/stateful/voting-module-adapter'
import {
DaoHome,
Loader,
ProfileDisconnectedCard,
ProfileMemberCard,
ProfileNotMemberCard,
useAppLayoutContext,
useCachedLoadable,
useDaoInfoContext,
} from '@dao-dao/stateless'
import { CoreActionKey } from '@dao-dao/types'
Expand All @@ -57,18 +55,13 @@ const InnerDaoHome = () => {
const {
components: { MembersTab, ProfileCardMemberInfo },
} = useVotingModuleAdapter()
const { isMember } = useVotingModule(daoInfo.coreAddress, {
fetchMembership: true,
})
const { isMember } = useMembership(daoInfo)

// If no parent, fallback to current address since it's already loaded from
// the above hook. We won't use this value unless there's a parent. It's
// redundant but has no effect.
const { isMember: isMemberOfParent } = useVotingModule(
daoInfo.parentDao?.coreAddress ?? daoInfo.coreAddress,
{
fetchMembership: true,
}
const { isMember: isMemberOfParent } = useMembership(
daoInfo.parentDao ?? daoInfo
)
const parentDaosSubDaosLoadable = useRecoilValueLoadable(
daoInfo.parentDao
Expand Down Expand Up @@ -173,78 +166,103 @@ const InnerDaoHome = () => {
),
[daoInfo.chainId, daoInfo.coreAddress, daoInfo.proposalModules]
)
const proposalModuleDepositInfos = useRecoilValue(
const proposalModuleDepositInfosLoadable = useCachedLoadable(
waitForAll(depositInfoSelectors)
).filter(Boolean) as CheckedDepositInfo[]

const maxProposalModuleDeposit = Math.max(
...proposalModuleDepositInfos.map(({ amount }) => Number(amount)),
0
)

const maxProposalModuleDeposit =
proposalModuleDepositInfosLoadable.state !== 'hasValue'
? 0
: Math.max(
...(
proposalModuleDepositInfosLoadable.contents.filter(
Boolean
) as CheckedDepositInfo[]
).map(({ amount }) => Number(amount)),
0
)

const { isPinned, setPinned, setUnpinned } = usePinnedDaos()
const pinned = isPinned(daoInfo.coreAddress)

// Get payroll tab component, if exists.
const PayrollTab = usePayrollAdapter()?.PayrollTab

const [showConfigureModal, setShowConfigureModal] = useState(false)

return (
<DaoHome
LinkWrapper={LinkWrapper}
SuspenseLoader={SuspenseLoader}
daoInfo={daoInfo}
daoInfoBar={<DaoInfoBar />}
membersTab={MembersTab && <MembersTab />}
onPin={() =>
pinned
? setUnpinned(daoInfo.coreAddress)
: setPinned(daoInfo.coreAddress)
}
payrollTab={PayrollTab && <PayrollTab />}
pinned={pinned}
proposalsTab={<ProposalsTab />}
rightSidebarContent={
connected ? (
isMember ? (
<ProfileMemberCard
daoName={daoInfo.name}
membershipInfo={
<ProfileCardMemberInfo
deposit={
maxProposalModuleDeposit > 0
? maxProposalModuleDeposit.toString()
: undefined
}
/>
}
showUpdateProfileNft={updateProfileNft.toggle}
updateProfileName={updateProfileName}
walletProfile={walletProfile}
/>
<>
<DaoHome
LinkWrapper={LinkWrapper}
SuspenseLoader={SuspenseLoader}
daoInfo={daoInfo}
daoInfoBar={<DaoInfoBar />}
membersTab={MembersTab && <MembersTab />}
onConfigure={() => setShowConfigureModal(true)}
onPin={() =>
pinned
? setUnpinned(daoInfo.coreAddress)
: setPinned(daoInfo.coreAddress)
}
payrollTab={PayrollTab && <PayrollTab />}
pinned={pinned}
proposalsTab={<ProposalsTab />}
rightSidebarContent={
connected ? (
// If membership not yet loaded, show loading skeleton.
isMember === undefined ? (
<ProfileDisconnectedCard className="animate-pulse" />
) : isMember ? (
<ProfileMemberCard
daoName={daoInfo.name}
membershipInfo={
<SuspenseLoader fallback={<Loader size={24} />}>
<ProfileCardMemberInfo
deposit={
maxProposalModuleDeposit > 0
? maxProposalModuleDeposit.toString()
: undefined
}
/>
</SuspenseLoader>
}
showUpdateProfileNft={updateProfileNft.toggle}
updateProfileName={updateProfileName}
walletProfile={walletProfile}
/>
) : (
<ProfileNotMemberCard
daoName={daoInfo.name}
membershipInfo={
<SuspenseLoader fallback={<Loader size={24} />}>
<ProfileCardMemberInfo
deposit={
maxProposalModuleDeposit > 0
? maxProposalModuleDeposit.toString()
: undefined
}
/>
</SuspenseLoader>
}
showUpdateProfileNft={updateProfileNft.toggle}
updateProfileName={updateProfileName}
walletProfile={walletProfile}
/>
)
) : (
<ProfileNotMemberCard
daoName={daoInfo.name}
membershipInfo={
<ProfileCardMemberInfo
deposit={
maxProposalModuleDeposit > 0
? maxProposalModuleDeposit.toString()
: undefined
}
/>
}
showUpdateProfileNft={updateProfileNft.toggle}
updateProfileName={updateProfileName}
walletProfile={walletProfile}
/>
<ProfileDisconnectedCard />
)
) : (
<ProfileDisconnectedCard />
)
}
subDaosTab={<SubDaosTab />}
treasuryAndNftsTab={<TreasuryAndNftsTab />}
/>
}
subDaosTab={<SubDaosTab />}
treasuryAndNftsTab={<TreasuryAndNftsTab />}
/>

<DiscordNotifierConfigureModal
onClose={() => setShowConfigureModal(false)}
open={() => setShowConfigureModal(true)}
visible={showConfigureModal}
/>
</>
)
}

Expand Down
Loading

2 comments on commit 5255d13

@vercel
Copy link

@vercel vercel bot commented on 5255d13 Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 5255d13 Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.