From bbd4d37151d9ca1af852ef0dc87d284d420d82eb Mon Sep 17 00:00:00 2001 From: noah Date: Wed, 1 Nov 2023 09:03:58 -0700 Subject: [PATCH] Fix making SubDAOs on other chains. (#1437) --- packages/stateful/components/dao/CreateDaoForm.tsx | 10 +++++++--- packages/stateful/components/dao/CreateSubDao.tsx | 12 ++++++++++-- packages/stateful/recoil/selectors/dao/cards.ts | 3 +++ packages/stateful/recoil/selectors/dao/misc.ts | 2 ++ packages/stateful/server/makeGetDaoStaticProps.ts | 2 ++ .../components/HorizontalScroller.stories.tsx | 1 + .../stateless/components/dao/DaoCard.stories.tsx | 4 +++- packages/types/dao.ts | 1 + 8 files changed, 29 insertions(+), 6 deletions(-) diff --git a/packages/stateful/components/dao/CreateDaoForm.tsx b/packages/stateful/components/dao/CreateDaoForm.tsx index f7a41e6c3..3ee7201b6 100644 --- a/packages/stateful/components/dao/CreateDaoForm.tsx +++ b/packages/stateful/components/dao/CreateDaoForm.tsx @@ -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 { @@ -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.') @@ -631,7 +635,7 @@ export const InnerCreateDaoForm = ({ }} className="mx-auto max-w-4xl" gradient - rightNode={} + rightNode={!makingSubDao && } /> {/* No container padding because we want the gradient to expand. Apply px-6 to children instead. */} diff --git a/packages/stateful/components/dao/CreateSubDao.tsx b/packages/stateful/components/dao/CreateSubDao.tsx index b10191502..deede3108 100644 --- a/packages/stateful/components/dao/CreateSubDao.tsx +++ b/packages/stateful/components/dao/CreateSubDao.tsx @@ -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 ( ({ tokenDecimals: 6, parentDao: { + chainId: CHAIN_ID, coreAddress: 'parent', coreVersion: ContractVersion.V2Alpha, name: 'parent', diff --git a/packages/stateless/components/dao/DaoCard.stories.tsx b/packages/stateless/components/dao/DaoCard.stories.tsx index c885d102a..c5a874426 100644 --- a/packages/stateless/components/dao/DaoCard.stories.tsx +++ b/packages/stateless/components/dao/DaoCard.stories.tsx @@ -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' @@ -19,7 +20,7 @@ const Template: ComponentStory = (args) => ( ) export const makeProps = (id = 1): DaoCardProps => ({ - chainId: 'uni-6', + chainId: CHAIN_ID, coreAddress: 'daoCoreAddress', name: 'Modern DAO', description: @@ -41,6 +42,7 @@ export const makeProps = (id = 1): DaoCardProps => ({ }, parentDao: { + chainId: CHAIN_ID, coreAddress: 'parentDaoCoreAddress', coreVersion: ContractVersion.V2Alpha, name: 'parent', diff --git a/packages/types/dao.ts b/packages/types/dao.ts index 760f5ca64..843114717 100644 --- a/packages/types/dao.ts +++ b/packages/types/dao.ts @@ -52,6 +52,7 @@ export type DaoInfo = { } export type DaoParentInfo = { + chainId: string coreAddress: string coreVersion: ContractVersion name: string