Skip to content

Commit

Permalink
Fix making SubDAOs on other chains. (#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso authored Nov 1, 2023
1 parent 64f7917 commit bbd4d37
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/stateful/components/dao/CreateDaoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useEffect, useMemo, useState } from 'react'
import { SubmitErrorHandler, SubmitHandler, useForm } from 'react-hook-form'
import toast from 'react-hot-toast'
import { useTranslation } from 'react-i18next'
import { useRecoilState, useRecoilValue } from 'recoil'
import { constSelector, useRecoilState, useRecoilValue } from 'recoil'

import { averageColorSelector, walletChainIdAtom } from '@dao-dao/state/recoil'
import {
Expand Down Expand Up @@ -94,7 +94,11 @@ export interface CreateDaoFormProps {
}

export const CreateDaoForm = (props: CreateDaoFormProps) => {
const chainId = useRecoilValue(walletChainIdAtom)
const chainId = useRecoilValue(
// If parent DAO exists, we're making a SubDAO, so use the parent DAO's
// chain ID.
props.parentDao ? constSelector(props.parentDao.chainId) : walletChainIdAtom
)
const config = getSupportedChainConfig(chainId)
if (!config) {
throw new Error('Unsupported chain.')
Expand Down Expand Up @@ -631,7 +635,7 @@ export const InnerCreateDaoForm = ({
}}
className="mx-auto max-w-4xl"
gradient
rightNode={<ChainSwitcher />}
rightNode={!makingSubDao && <ChainSwitcher />}
/>

{/* No container padding because we want the gradient to expand. Apply px-6 to children instead. */}
Expand Down
12 changes: 10 additions & 2 deletions packages/stateful/components/dao/CreateSubDao.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ import { CreateDaoForm } from './CreateDaoForm'

// Wrap the CreateDaoForm to create a SubDao for the current DAO.
export const CreateSubDao = () => {
const { coreAddress, coreVersion, name, imageUrl, parentDao, admin } =
useDaoInfoContext()
const {
chainId,
coreAddress,
coreVersion,
name,
imageUrl,
parentDao,
admin,
} = useDaoInfoContext()

return (
<CreateDaoForm
parentDao={{
chainId,
coreAddress,
coreVersion,
name,
Expand Down
3 changes: 3 additions & 0 deletions packages/stateful/recoil/selectors/dao/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const daoCardInfoSelector = selectorFamily<

if (coreVersion) {
parentDao = {
chainId,
coreAddress: admin,
coreVersion,
name,
Expand Down Expand Up @@ -183,6 +184,7 @@ export const daoCardInfoSelector = selectorFamily<
false

parentDao = {
chainId,
coreAddress: admin,
coreVersion: adminVersion,
name,
Expand All @@ -203,6 +205,7 @@ export const daoCardInfoSelector = selectorFamily<
// Chain module account.
const chainConfig = getSupportedChainConfig(chainId)
parentDao = chainConfig && {
chainId,
coreAddress: chainConfig.name,
coreVersion: ContractVersion.Gov,
name: getDisplayNameForChainId(chainId),
Expand Down
2 changes: 2 additions & 0 deletions packages/stateful/recoil/selectors/dao/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ export const daoInfoSelector: (param: {
// Chain module account.
const chainConfig = getSupportedChainConfig(chainId)
parentDaoInfo = chainConfig && {
chainId,
coreAddress: chainConfig.name,
coreVersion: ContractVersion.Gov,
name: getDisplayNameForChainId(chainId),
Expand Down Expand Up @@ -331,6 +332,7 @@ export const daoInfoSelector: (param: {
polytoneProxies,
parentDao: parentDaoInfo
? {
chainId: parentDaoInfo.chainId,
coreAddress: parentDaoInfo.coreAddress,
coreVersion: parentDaoInfo.coreVersion,
name: parentDaoInfo.name,
Expand Down
2 changes: 2 additions & 0 deletions packages/stateful/server/makeGetDaoStaticProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ const loadParentDaoInfo = async (
const chainConfig = getSupportedChainConfig(chainId)
return chainConfig
? {
chainId,
coreAddress: chainConfig.name,
coreVersion: ContractVersion.Gov,
name: getDisplayNameForChainId(chainId),
Expand Down Expand Up @@ -512,6 +513,7 @@ const loadParentDaoInfo = async (
])

return {
chainId,
coreAddress: potentialParentAddress,
coreVersion: version,
name: name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const makeFeaturedDao = (): DaoCardInfo => ({
tokenDecimals: 6,

parentDao: {
chainId: CHAIN_ID,
coreAddress: 'parent',
coreVersion: ContractVersion.V2Alpha,
name: 'parent',
Expand Down
4 changes: 3 additions & 1 deletion packages/stateless/components/dao/DaoCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComponentMeta, ComponentStory } from '@storybook/react'

import { CHAIN_ID } from '@dao-dao/storybook'
import { ContractVersion } from '@dao-dao/types'

import { IconButtonLink } from '../icon_buttons'
Expand All @@ -19,7 +20,7 @@ const Template: ComponentStory<typeof DaoCard> = (args) => (
)

export const makeProps = (id = 1): DaoCardProps => ({
chainId: 'uni-6',
chainId: CHAIN_ID,
coreAddress: 'daoCoreAddress',
name: 'Modern DAO',
description:
Expand All @@ -41,6 +42,7 @@ export const makeProps = (id = 1): DaoCardProps => ({
},

parentDao: {
chainId: CHAIN_ID,
coreAddress: 'parentDaoCoreAddress',
coreVersion: ContractVersion.V2Alpha,
name: 'parent',
Expand Down
1 change: 1 addition & 0 deletions packages/types/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type DaoInfo = {
}

export type DaoParentInfo = {
chainId: string
coreAddress: string
coreVersion: ContractVersion
name: string
Expand Down

2 comments on commit bbd4d37

@vercel
Copy link

@vercel vercel bot commented on bbd4d37 Nov 1, 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 bbd4d37 Nov 1, 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.