Skip to content

Commit

Permalink
Added Cosmos Hub to governance page.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Dec 14, 2023
1 parent 679ef07 commit 0ec02b3
Show file tree
Hide file tree
Showing 41 changed files with 852 additions and 613 deletions.
34 changes: 18 additions & 16 deletions apps/dapp/pages/gov/[chain]/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@ import {
DaoDappTabbedHome,
GovernanceHome,
useChain,
useConfiguredChainContext,
useDaoInfoContext,
useSupportedChainContext,
} from '@dao-dao/stateless'
import { ChainId, DaoTabId, DaoTabWithComponent } from '@dao-dao/types'
import {
NEUTRON_GOVERNANCE_DAO,
SITE_URL,
getConfiguredChainConfig,
getConfiguredChains,
getGovPath,
getSupportedChainConfig,
getSupportedChains,
} from '@dao-dao/utils'

const InnerGovHome = () => {
const { t } = useTranslation()
const { chainId, config } = useSupportedChainContext()
const {
chainId,
config: { name },
} = useConfiguredChainContext()
const daoInfo = useDaoInfoContext()

const router = useRouter()
Expand All @@ -70,34 +73,34 @@ const InnerGovHome = () => {
// Pre-fetch tabs.
useEffect(() => {
tabs.forEach((tab) => {
router.prefetch(getGovPath(config.name, tab.id))
router.prefetch(getGovPath(name, tab.id))
})
}, [config.name, router, tabs])
}, [name, router, tabs])

const slug = (router.query.slug || []) as string[]
useEffect(() => {
// If no slug, redirect to first tab.
if (slug.length === 0) {
router.push(getGovPath(config.name, firstTabId), undefined, {
router.push(getGovPath(name, firstTabId), undefined, {
shallow: true,
})
}
}, [router, slug.length, firstTabId, config.name])
}, [router, slug.length, firstTabId, name])

const tabId =
slug.length > 0 && tabs.some(({ id }) => id === slug[0])
? slug[0]
: // If tab is invalid, default to first tab.
firstTabId
const onSelectTabId = (tabId: string) =>
router.push(getGovPath(config.name, tabId), undefined, {
router.push(getGovPath(name, tabId), undefined, {
shallow: true,
})

const [goingToChainId, setGoingToChainId] = useState<string>()
// Pre-fetch other chains.
useEffect(() => {
getSupportedChains().forEach(({ name }) => {
getConfiguredChains().forEach(({ name }) => {
router.prefetch(getGovPath(name))
tabs.map((tab) => router.prefetch(getGovPath(name, tab.id)))
})
Expand All @@ -113,13 +116,11 @@ const InnerGovHome = () => {
loading={!!goingToChainId && goingToChainId !== chainId}
onSelect={(chainId) => {
router.push(
getGovPath(
getSupportedChainConfig(chainId)?.name || config.name,
tabId
)
getGovPath(getConfiguredChainConfig(chainId)?.name || name, tabId)
)
setGoingToChainId(chainId)
}}
type="configured"
/>
}
daoInfo={daoInfo}
Expand Down Expand Up @@ -163,7 +164,7 @@ const NeutronGovHome: NextPage = () => {
const [goingToChainId, setGoingToChainId] = useState<string>()
// Pre-fetch other chains.
useEffect(() => {
getSupportedChains().forEach(({ name }) => {
getConfiguredChains().forEach(({ name }) => {
router.prefetch('/' + name)
})
}, [router])
Expand All @@ -175,12 +176,13 @@ const NeutronGovHome: NextPage = () => {
<ChainSwitcher
loading={!!goingToChainId && goingToChainId !== chainId}
onSelect={(chainId) => {
const chainConfig = getSupportedChainConfig(chainId)
const chainConfig = getConfiguredChainConfig(chainId)
if (chainConfig) {
router.push(getGovPath(chainConfig.name))
setGoingToChainId(chainId)
}
}}
type="configured"
/>
}
daos={daosLoading}
Expand Down
12 changes: 10 additions & 2 deletions apps/dapp/pages/gov/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ import { useRecoilValue } from 'recoil'

import { walletChainIdAtom } from '@dao-dao/state'
import { PageLoader } from '@dao-dao/stateless'
import { getGovPath, getSupportedChainConfig } from '@dao-dao/utils'
import {
getConfiguredChainConfig,
getConfiguredChains,
getGovPath,
} from '@dao-dao/utils'

const GovRedirectPage: NextPage = () => {
const chainId = useRecoilValue(walletChainIdAtom)

const router = useRouter()
useEffect(() => {
router.push(getGovPath(getSupportedChainConfig(chainId)!.name))
router.push(
getGovPath(
getConfiguredChainConfig(chainId)?.name || getConfiguredChains()[0].name
)
)
}, [chainId, router])

return <PageLoader />
Expand Down
4 changes: 2 additions & 2 deletions packages/state/recoil/atoms/chain.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { atom, atomFamily } from 'recoil'

import { DEFAULT_CHAIN_ID, getSupportedChains } from '@dao-dao/utils'
import { DEFAULT_CHAIN_ID, getConfiguredChains } from '@dao-dao/utils'

import { localStorageEffect } from '../effects'

Expand All @@ -20,7 +20,7 @@ export const walletChainIdAtom = atom<string>({
localStorageEffect(JSON.stringify, (jsonValue: string) => {
const value = JSON.parse(jsonValue)
// If no supported chain matches, set to default.
return getSupportedChains().some(({ chain }) => chain.chain_id === value)
return getConfiguredChains().some(({ chain }) => chain.chain_id === value)
? value
: DEFAULT_CHAIN_ID
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
TextAreaInput,
TextInput,
TokenInput,
useSupportedChainContext,
useConfiguredChainContext,
} from '@dao-dao/stateless'
import {
AddressInputProps,
Expand Down Expand Up @@ -91,9 +91,11 @@ export const GovernanceProposalComponent: ActionComponent<
const {
chainId,
chain: { bech32_prefix: bech32Prefix },
config: { supportsV1GovProposals },
config: {
gov: { supportsV1GovProposals },
},
nativeToken,
} = useSupportedChainContext()
} = useConfiguredChainContext()

const selectedMinDepositToken = minDeposits.loading
? undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ export const makeGovernanceProposalAction: ActionMaker<
context,
chain: { chain_id: currentChainId },
chainContext: {
config: { supportsV1GovProposals },
config: {
gov: { supportsV1GovProposals },
},
},
}) => {
const useDefaults: UseDefaults<GovernanceProposalActionData> = () => {
Expand Down
23 changes: 16 additions & 7 deletions packages/stateful/actions/core/dao_appearance/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { ActionCategoryKey, ActionCategoryMaker } from '@dao-dao/types'
import {
ActionCategoryKey,
ActionCategoryMaker,
ActionContextType,
} from '@dao-dao/types'

import { makeManageWidgetsAction } from './ManageWidgets'
import { makeUpdateInfoAction } from './UpdateInfo'

export const makeDaoAppearanceActionCategory: ActionCategoryMaker = ({
t,
}) => ({
key: ActionCategoryKey.DaoAppearance,
label: t('actionCategory.daoAppearanceLabel'),
description: t('actionCategory.daoAppearanceDescription'),
actionMakers: [makeUpdateInfoAction, makeManageWidgetsAction],
})
context,
}) =>
// Only DAOs.
context.type === ActionContextType.Dao
? {
key: ActionCategoryKey.DaoAppearance,
label: t('actionCategory.daoAppearanceLabel'),
description: t('actionCategory.daoAppearanceDescription'),
actionMakers: [makeUpdateInfoAction, makeManageWidgetsAction],
}
: null
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { useFormContext } from 'react-hook-form'
import { useTranslation } from 'react-i18next'

import { CopyToClipboard, RadioInput } from '@dao-dao/stateless'
import { ActionComponent, ActionContextType } from '@dao-dao/types/actions'
import {
ActionChainContextType,
ActionComponent,
ActionContextType,
} from '@dao-dao/types/actions'
import { getDisplayNameForChainId, getImageUrlForChainId } from '@dao-dao/utils'

import { useActionOptions } from '../../../react'
Expand All @@ -26,6 +30,7 @@ export const CreateCrossChainAccountComponent: ActionComponent = ({
if (
context.type !== ActionContextType.Dao ||
// Type check.
chainContext.type !== ActionChainContextType.Supported ||
!chainContext.config.polytone
) {
throw new Error('Invalid context for this action.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback } from 'react'

import { ChainEmoji } from '@dao-dao/stateless'
import {
ActionChainContextType,
ActionContextType,
ActionKey,
ActionMaker,
Expand All @@ -21,22 +22,18 @@ import {

export const makeCreateCrossChainAccountAction: ActionMaker<
CreateCrossChainAccountData
> = ({
t,
context,
chain,
chainContext: {
config: { polytone },
},
}) => {
> = ({ t, context, chain, chainContext }) => {
// Only allow using this action in DAOs.
if (context.type !== ActionContextType.Dao) {
if (
context.type !== ActionContextType.Dao ||
chainContext.type !== ActionChainContextType.Supported
) {
return null
}

const missingChainIds = Object.keys(polytone || {}).filter(
(chainId) => !(chainId in context.info.polytoneProxies)
)
const missingChainIds = Object.keys(
chainContext.config.polytone || {}
).filter((chainId) => !(chainId in context.info.polytoneProxies))

const useDefaults: UseDefaults<CreateCrossChainAccountData> = () => ({
chainId: missingChainIds[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,13 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg<DaoAdminExecData> = (
export const makeDaoAdminExecAction: ActionMaker<DaoAdminExecData> = ({
t,
context,
chainContext: {
config: { noCosmWasm },
},
}) =>
// Only allow using this action in DAOs or gov props.
// Only allow using this action in DAOs or gov props on chains with CW.
context.type === ActionContextType.Dao ||
context.type === ActionContextType.Gov
(context.type === ActionContextType.Gov && !noCosmWasm)
? {
key: ActionKey.DaoAdminExec,
Icon: JoystickEmoji,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TokenType,
} from '@dao-dao/types'
import {
ActionChainContextType,
ActionContextType,
ActionKey,
ActionMaker,
Expand Down Expand Up @@ -81,16 +82,15 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg<EnableMultipleChoiceData> = (

export const makeEnableMultipleChoiceAction: ActionMaker<
EnableMultipleChoiceData
> = ({
t,
address,
context,
chain: { chain_id: chainId },
chainContext: { config: chainConfig },
}) => {
> = ({ t, address, context, chain: { chain_id: chainId }, chainContext }) => {
// Disallows creation if multiple choice proposal module already exists, down
// at the bottom of this function, instead of returning null here. This
// ensures this action can be rendered correctly in past proposals after
// multiple choice is enabled.
if (
context.type !== ActionContextType.Dao ||
!context.info.supportedFeatures[Feature.MultipleChoiceProposals]
!context.info.supportedFeatures[Feature.MultipleChoiceProposals] ||
chainContext.type !== ActionChainContextType.Supported
) {
return null
}
Expand Down Expand Up @@ -152,7 +152,7 @@ export const makeEnableMultipleChoiceAction: ActionMaker<
}

const info = DaoProposalMultipleAdapter.daoCreation.getInstantiateInfo(
chainConfig,
chainContext.config,
{
...makeDefaultNewDao(chainId),
// Only the name is used in this function to pick the contract label.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useCachedLoading,
} from '@dao-dao/stateless'
import {
ActionChainContextType,
ActionComponent,
ActionContextType,
ActionKey,
Expand Down Expand Up @@ -139,18 +140,19 @@ export const makeUpgradeV1ToV2Action: ActionMaker<UpgradeV1ToV2Data> = ({
t,
address,
chain,
chainContext: {
config: { codeIds },
},
chainContext,
}) => {
if (
context.type !== ActionContextType.Dao ||
// If no DAO migrator, don't show upgrade action.
codeIds.DaoMigrator <= 0
chainContext.type !== ActionChainContextType.Supported ||
chainContext.config.codeIds.DaoMigrator <= 0
) {
return null
}

const { codeIds } = chainContext.config

const useDefaults: UseDefaults<UpgradeV1ToV2Data> = () => {
// Load sub DAOs for registering as the current DAO upgrades to v2. If this
// DAO is not on v1, there are no SubDAOs to load.
Expand Down
Loading

0 comments on commit 0ec02b3

Please sign in to comment.