Skip to content

Commit

Permalink
cleaned up headers and improved chain-specific home UX
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Jun 1, 2024
1 parent 9c9bb07 commit a6de2db
Show file tree
Hide file tree
Showing 21 changed files with 469 additions and 238 deletions.
78 changes: 51 additions & 27 deletions apps/dapp/pages/[[...tab]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,80 @@ export default Home

export const getStaticProps: GetStaticProps<StatefulHomeProps> = async ({
locale,
params,
}) => {
// Get chain DAOs.
const chainDaos = [
// Start with Cosmos Hub.
MAINNET ? ChainId.CosmosHubMainnet : ChainId.CosmosHubTestnet,
// Add DAO DAO-supported chains.
...getSupportedChains().flatMap(({ chainId, noGov }) =>
noGov ? [] : chainId
),
// Add some other common chains.
...(MAINNET
? [
'akashnet-2',
'secret-4',
'regen-1',
'injective-1',
'celestia',
'dydx-mainnet-1',
'archway-1',
'coreum-mainnet-1',
]
: []),
].map((chainId) => getDaoInfoForChainId(chainId, []))
const tabPath =
params?.tab && Array.isArray(params?.tab) ? params.tab[0] : undefined

// Get stats and TVL.
// If defined, try to find matching chain. If found, show chain-only page.
const selectedChain = tabPath
? getSupportedChains().find(({ name }) => name === tabPath)
: undefined
const chainId = selectedChain?.chainId

const chainGovDaos = chainId
? selectedChain.noGov
? undefined
: [getDaoInfoForChainId(chainId, [])]
: // Get chain x/gov DAOs if not on a chain-specific home.
[
// Start with Cosmos Hub.
MAINNET ? ChainId.CosmosHubMainnet : ChainId.CosmosHubTestnet,
// Add DAO DAO-supported chains.
...getSupportedChains().flatMap(({ chainId, noGov }) =>
noGov ? [] : chainId
),
// Add some other common chains.
...(MAINNET
? [
'akashnet-2',
'secret-4',
'regen-1',
'injective-1',
'celestia',
'dydx-mainnet-1',
'archway-1',
'coreum-mainnet-1',
]
: []),
].map((chainId) => getDaoInfoForChainId(chainId, []))

// Get all or chain-specific stats and TVL.
const [tvl, stats] = await Promise.all([
querySnapper<number>({
query: 'daodao-all-tvl',
query: chainId ? 'daodao-chain-tvl' : 'daodao-all-tvl',
parameters: chainId ? { chainId } : undefined,
}),
querySnapper<DaoDaoIndexerChainStats>({
query: 'daodao-all-stats',
query: chainId ? 'daodao-chain-stats' : 'daodao-all-stats',
parameters: chainId ? { chainId } : undefined,
}),
])

if (!tvl || !stats) {
processError('Failed to fetch TVL/stats for home page', {
forceCapture: true,
tags: {
chainId,
},
})
throw new Error('Failed to fetch stats.')
}

return {
props: {
...(await serverSideTranslations(locale, ['translation'])),
// Chain-specific home page.
...(chainId && { chainId }),
// All or chain-specific stats.
stats: {
...stats,
chains: getSupportedChains().length,
// If chain is 1, it will not be shown.
chains: chainId ? 1 : getSupportedChains().length,
tvl,
},
chainDaos,
// Chain x/gov DAOs.
...(chainGovDaos && { chainGovDaos }),
},
// Revalidate every hour.
revalidate: 60 * 60,
Expand Down
5 changes: 3 additions & 2 deletions packages/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@
"earlyExecute": "Early execute",
"enable": "Enable",
"execute": "Execute",
"findAnotherChain": "Find another chain",
"findAnotherDao": "Find another DAO",
"findDifferentChain": "Find a different chain",
"follow": "Follow",
"forceExecute": "Force execute",
"forcePublish": "Force publish",
Expand Down Expand Up @@ -1000,7 +1000,7 @@
"errored": "Errored",
"establishedTooltip": "When the DAO was created.",
"estimatedStargazeUsdValueTooltip": "USD value is estimated using price data from Stargaze. This is not fully reflective of realizable spending power due to liquidity limitations.",
"estimatedTreasuryUsdValueTooltip": "The USD value of treasuries is estimated by summing the value of all tokens held in the treasury that are listed on CoinGecko, Osmosis, Stargaze, White Whale, and Astroport. This is not fully reflective of realizable spending power due to liquidity limitations.",
"estimatedTreasuryUsdValueTooltip": "The USD value of DAO treasuries is estimated by summing the value of all tokens held in the treasury that are listed on CoinGecko, Osmosis, Astroport, Stargaze, and White Whale. This is not fully reflective of realizable spending power due to liquidity limitations.",
"estimatedUsdValueTooltip": "USD value is estimated using price data from CoinGecko, Osmosis, White Whale, and Astroport. This is not fully reflective of realizable spending power due to liquidity limitations.",
"executeSmartContractActionDescription": "Execute a message on a smart contract.",
"failing": "Failing",
Expand Down Expand Up @@ -1234,6 +1234,7 @@
"remainingBalanceVesting": "Remaining balance vesting",
"removeCw20FromTreasuryActionDescription": "Stop displaying the DAO's balance of a CW20 token in the treasury view.",
"removeCw721FromTreasuryActionDescription": "Stop displaying the NFTs owned by the DAO from a CW721 NFT collection in the treasury view.",
"required": "Required",
"retroactiveCompensationDescription": "After each contribution cycle, contributors are assigned points based on their contributions. Payment is split based on the points they receive.",
"reviewActionImportData": "Review the following actions to make sure they look right. If they do, click the Import button at the bottom to add them to the proposal.",
"reviewYourProposal": "Review your proposal...",
Expand Down
38 changes: 21 additions & 17 deletions packages/state/recoil/selectors/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { ConfigResponse as CwCoreV1ConfigResponse } from '@dao-dao/types/contracts/CwCore.v1'
import { ConfigResponse as DaoCoreV2ConfigResponse } from '@dao-dao/types/contracts/DaoCore.v2'
import {
CHAIN_SUBDAOS,
DAO_CORE_CONTRACT_NAMES,
INACTIVE_DAO_NAMES,
VETOABLE_DAOS_ITEM_KEY_PREFIX,
Expand All @@ -21,6 +20,7 @@ import {
getDisplayNameForChainId,
getFallbackImage,
getImageUrlForChainId,
getSupportedChainConfig,
isConfiguredChainName,
isFeatureSupportedByVersion,
parseContractVersion,
Expand Down Expand Up @@ -118,28 +118,30 @@ export const daoDropdownInfoSelector: (
coreAddress,
})
)
const subDaos = CHAIN_SUBDAOS[chainId] || []
const subDaos = getSupportedChainConfig(chainId)?.subDaos || []

return {
chainId,
coreAddress,
imageUrl: lazyInfo.info.imageUrl,
name: lazyInfo.info.name,
subDaos: get(
waitForAll(
subDaos.map((subDaoAddress) =>
daoDropdownInfoSelector({
chainId,
coreAddress: subDaoAddress,
parents: [...(parents ?? []), coreAddress],
// Prevents cycles. If one of our children is also our
// ancestor, don't let it load any children, but still load it
// so we can see the cycle exists.
noSubDaos: !!parents?.includes(subDaoAddress),
})
subDaos: subDaos.length
? get(
waitForAll(
subDaos.map((subDaoAddress) =>
daoDropdownInfoSelector({
chainId,
coreAddress: subDaoAddress,
parents: [...(parents ?? []), coreAddress],
// Prevents cycles. If one of our children is also our
// ancestor, don't let it load any children, but still load it
// so we can see the cycle exists.
noSubDaos: !!parents?.includes(subDaoAddress),
})
)
)
)
)
),
: [],
}
}

Expand Down Expand Up @@ -324,7 +326,9 @@ export const daoParentInfoSelector = selectorFamily<
admin: '',
registeredSubDao:
!!childAddress &&
!!CHAIN_SUBDAOS[chainId]?.includes(childAddress),
!!getSupportedChainConfig(chainId)?.subDaos?.includes(
childAddress
),
}
)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/stateful/components/gov/GovSubDaosTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useCachedLoading,
useChain,
} from '@dao-dao/stateless'
import { CHAIN_SUBDAOS } from '@dao-dao/utils'
import { getSupportedChainConfig } from '@dao-dao/utils'

import { GovActionsProvider } from '../../actions'
import { daoInfoSelector } from '../../recoil'
Expand All @@ -19,7 +19,7 @@ export const GovSubDaosTab = () => {

const subDaos = useCachedLoading(
waitForAll(
CHAIN_SUBDAOS[chainId]?.map((coreAddress) =>
getSupportedChainConfig(chainId)?.subDaos?.map((coreAddress) =>
daoInfoSelector({ chainId, coreAddress })
) ?? []
),
Expand Down
Loading

0 comments on commit a6de2db

Please sign in to comment.