Skip to content

Commit

Permalink
Moved proposal and voting module adapters into common package.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Oct 22, 2022
1 parent e0473d1 commit 5ca82d4
Show file tree
Hide file tree
Showing 198 changed files with 256 additions and 417 deletions.
2 changes: 1 addition & 1 deletion apps/dapp/components/TokenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useRouter } from 'next/router'
import { useCallback, useEffect } from 'react'
import { useSetRecoilState } from 'recoil'

import { useActionForKey } from '@dao-dao/common/actions'
import { useEncodedCwdProposalSinglePrefill } from '@dao-dao/common'
import { useActionForKey } from '@dao-dao/common/actions'
import {
refreshNativeTokenStakingInfoAtom,
tokenCardLazyStakingInfoSelector,
Expand Down
8 changes: 4 additions & 4 deletions apps/dapp/components/dao/tabs/TreasuryAndNftsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
useEncodedCwdProposalSinglePrefill,
} from '@dao-dao/common'
import { useActionForKey } from '@dao-dao/common/actions'
import {
useCw20GovernanceTokenInfoResponseIfExists,
useNativeGovernanceTokenInfoResponseIfExists,
} from '@dao-dao/common/voting-module-adapter'
import {
nftCardInfosSelector,
treasuryTokenCardInfosSelector,
Expand All @@ -20,10 +24,6 @@ import {
} from '@dao-dao/stateless'
import { ActionKey } from '@dao-dao/types'
import { loadableToLoadingData } from '@dao-dao/utils'
import {
useCw20GovernanceTokenInfoResponseIfExists,
useNativeGovernanceTokenInfoResponseIfExists,
} from '@dao-dao/voting-module-adapter'

import { TokenCard } from '@/components'

Expand Down
4 changes: 2 additions & 2 deletions apps/dapp/components/profile/ProfileNewProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import { useTranslation } from 'react-i18next'

import { SuspenseLoader } from '@dao-dao/common'
import { matchAndLoadCommon } from '@dao-dao/proposal-module-adapter'
import { matchAndLoadCommon } from '@dao-dao/common/proposal-module-adapter'
import { useVotingModuleAdapter } from '@dao-dao/common/voting-module-adapter'
import { useWalletProfile } from '@dao-dao/state'
import {
ProfileNewProposalCard as StatelessProfileNewProposalCard,
useAppLayoutContext,
useDaoInfoContext,
} from '@dao-dao/stateless'
import { useVotingModuleAdapter } from '@dao-dao/voting-module-adapter'

export interface ProfileNewProposalCardProps {
proposalModuleAdapterCommon: ReturnType<typeof matchAndLoadCommon>
Expand Down
4 changes: 2 additions & 2 deletions apps/dapp/components/profile/ProfileProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { useRecoilValue, waitForAll } from 'recoil'
import {
matchAndLoadCommon,
useProposalModuleAdapter,
} from '@dao-dao/proposal-module-adapter'
} from '@dao-dao/common/proposal-module-adapter'
import { useVotingModuleAdapter } from '@dao-dao/common/voting-module-adapter'
import { useVotingModule, useWalletProfile } from '@dao-dao/state'
import {
Loader,
Expand All @@ -20,7 +21,6 @@ import {
useDaoInfoContext,
} from '@dao-dao/stateless'
import { CheckedDepositInfo } from '@dao-dao/types/contracts/common'
import { useVotingModuleAdapter } from '@dao-dao/voting-module-adapter'

export interface ProfileProposalCardProps {
onVoteSuccess: () => void | Promise<void>
Expand Down
2 changes: 0 additions & 2 deletions apps/dapp/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const withTM = require('next-transpile-modules')([
'@dao-dao/state',
'@dao-dao/common',
'@dao-dao/i18n',
'@dao-dao/voting-module-adapter',
'@dao-dao/proposal-module-adapter',
'@dao-dao/types',
])

Expand Down
2 changes: 0 additions & 2 deletions apps/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
"@cosmjs/stargate": "0.28.10",
"@dao-dao/common": "2.0.1",
"@dao-dao/i18n": "2.0.1",
"@dao-dao/proposal-module-adapter": "2.0.1",
"@dao-dao/types": "2.0.1",
"@dao-dao/stateless": "2.0.1",
"@dao-dao/utils": "2.0.1",
"@dao-dao/voting-module-adapter": "2.0.1",
"@fontsource/inter": "^4.5.7",
"@fontsource/jetbrains-mono": "^4.5.5",
"@mui/icons-material": "^5.10.3",
Expand Down
6 changes: 3 additions & 3 deletions apps/dapp/pages/dao/[address]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ import {
waitForAll,
} from 'recoil'

import { useActionForKey } from '@dao-dao/common/actions'
import {
DaoInfoBar,
DaoPageWrapper,
DaoPageWrapperProps,
useEncodedCwdProposalSinglePrefill,
} from '@dao-dao/common'
import { useActionForKey } from '@dao-dao/common/actions'
import { matchAndLoadCommon } from '@dao-dao/common/proposal-module-adapter'
import { makeGetDaoStaticProps } from '@dao-dao/common/server'
import { matchAndLoadCommon } from '@dao-dao/proposal-module-adapter'
import { useVotingModuleAdapter } from '@dao-dao/common/voting-module-adapter'
import {
CwdCoreV2Selectors,
usePinnedDaos,
Expand All @@ -42,7 +43,6 @@ import {
import { ActionKey } from '@dao-dao/types'
import { CheckedDepositInfo } from '@dao-dao/types/contracts/common'
import { SITE_URL } from '@dao-dao/utils'
import { useVotingModuleAdapter } from '@dao-dao/voting-module-adapter'

import { ProposalsTab, SubDaosTab, TreasuryAndNftsTab } from '@/components'

Expand Down
8 changes: 4 additions & 4 deletions apps/dapp/pages/dao/[address]/proposals/[proposalId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import { useCallback, useMemo } from 'react'
import toast from 'react-hot-toast'
import { useTranslation } from 'react-i18next'

import { useActions } from '@dao-dao/common/actions'
import {
DaoPageWrapper,
DaoProposalPageWrapperProps,
Trans,
} from '@dao-dao/common'
import { makeGetDaoProposalStaticProps } from '@dao-dao/common/server'
import { useActions } from '@dao-dao/common/actions'
import {
CommonProposalInfo,
ProposalModuleAdapterProvider,
useProposalModuleAdapterContext,
} from '@dao-dao/proposal-module-adapter'
} from '@dao-dao/common/proposal-module-adapter'
import { makeGetDaoProposalStaticProps } from '@dao-dao/common/server'
import { useVotingModuleAdapter } from '@dao-dao/common/voting-module-adapter'
import { useProfile } from '@dao-dao/state'
import {
Loader,
Expand All @@ -31,7 +32,6 @@ import {
} from '@dao-dao/stateless'
import { ActionKey } from '@dao-dao/types'
import { SITE_URL } from '@dao-dao/utils'
import { useVotingModuleAdapter } from '@dao-dao/voting-module-adapter'

import { ProfileProposalCard } from '@/components'

Expand Down
4 changes: 2 additions & 2 deletions apps/dapp/pages/dao/[address]/proposals/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {
DaoPageWrapperProps,
SuspenseLoader,
} from '@dao-dao/common'
import { makeGetDaoStaticProps } from '@dao-dao/common/server'
import {
BaseNewProposalProps,
CwdProposalSingleAdapter,
matchAndLoadCommon,
matchAdapter as matchProposalModuleAdapter,
} from '@dao-dao/proposal-module-adapter'
} from '@dao-dao/common/proposal-module-adapter'
import { makeGetDaoStaticProps } from '@dao-dao/common/server'
import {
proposalCreatedCardPropsAtom,
proposalDraftsAtom,
Expand Down
2 changes: 1 addition & 1 deletion apps/dapp/pages/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { useRecoilState } from 'recoil'

import { ActionsProvider, useActions } from '@dao-dao/common/actions'
import { SuspenseLoader } from '@dao-dao/common'
import { ActionsProvider, useActions } from '@dao-dao/common/actions'
import { serverSideTranslations } from '@dao-dao/i18n/serverSideTranslations'
import { walletTransactionAtom } from '@dao-dao/state'
import {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
"common": "yarn workspace @dao-dao/common",
"i18n": "yarn workspace @dao-dao/i18n",
"storybook": "yarn workspace @dao-dao/storybook",
"proposal-module-adapter": "yarn workspace @dao-dao/proposal-module-adapter",
"voting-module-adapter": "yarn workspace @dao-dao/voting-module-adapter",
"types": "yarn workspace @dao-dao/types"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/actions/actions/Instantiate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useCallback, useMemo } from 'react'
import { useFormContext } from 'react-hook-form'
import { constSelector, useRecoilValue } from 'recoil'

import { useProposalModuleAdapterIfAvailable } from '@dao-dao/proposal-module-adapter/react/context'
import {
nativeBalancesSelector,
transactionEventsSelector,
Expand All @@ -25,6 +24,7 @@ import {
makeWasmMessage,
} from '@dao-dao/utils'

import { useProposalModuleAdapterIfAvailable } from '../../proposal-module-adapter/react/context'
import { InstantiateComponent as StatelessInstantiateComponent } from '../components/Instantiate'

interface InstantiateData {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/actions/actions/Spend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
makeWasmMessage,
nativeTokenDecimals,
} from '@dao-dao/utils'
import { useCw20GovernanceTokenInfoResponseIfExists } from '@dao-dao/voting-module-adapter'

import { useCw20GovernanceTokenInfoResponseIfExists } from '../../voting-module-adapter'
import { SpendComponent as StatelessSpendComponent } from '../components/Spend'

interface SpendData {
Expand Down
5 changes: 3 additions & 2 deletions packages/common/atoms/newDao.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { atom, atomFamily } from 'recoil'

import { CwdProposalSingleAdapter } from '@dao-dao/proposal-module-adapter/adapters/CwdProposalSingle'
import { localStorageEffectJSON } from '@dao-dao/state/recoil/effects'
import { DaoCreatedCardProps, NewDao } from '@dao-dao/types'
import { CwdVotingCw4Adapter } from '@dao-dao/voting-module-adapter'

import { CwdProposalSingleAdapter } from '../proposal-module-adapter/adapters/CwdProposalSingle'
import { CwdVotingCw4Adapter } from '../voting-module-adapter'

export const DefaultNewDao: NewDao = {
name: '',
Expand Down
22 changes: 10 additions & 12 deletions packages/common/components/CreateDaoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import toast from 'react-hot-toast'
import { useTranslation } from 'react-i18next'
import { useRecoilState } from 'recoil'

import {
ProposalModuleAdapter,
getAdapterById as getProposalModuleAdapterById,
} from '@dao-dao/proposal-module-adapter'
import {
CwAdminFactoryHooks,
useAwaitNextBlock,
Expand All @@ -33,6 +29,7 @@ import {
CreateDaoCustomValidator,
DaoParentInfo,
NewDao,
ProposalModuleAdapter,
} from '@dao-dao/types'
import { InstantiateMsg as CwdCoreV2InstantiateMsg } from '@dao-dao/types/contracts/CwdCore.v2'
import instantiateSchema from '@dao-dao/types/contracts/CwdCore.v2.instantiate_schema.json'
Expand All @@ -51,21 +48,22 @@ import {
processError,
validateUrl,
} from '@dao-dao/utils'

import {
DefaultNewDao,
daoCreatedCardPropsAtom,
newDaoAtom,
} from '../atoms/newDao'
import { getAdapterById as getProposalModuleAdapterById } from '../proposal-module-adapter'
import {
CwdVotingCw20StakedAdapter,
getAdapterById as getVotingModuleAdapterById,
getAdapters as getVotingModuleAdapters,
} from '@dao-dao/voting-module-adapter'
} from '../voting-module-adapter'
import {
DaoCreationConfig as CwdVotingCw20StakedCreationConfig,
GovernanceTokenType,
} from '@dao-dao/voting-module-adapter/adapters/CwdVotingCw20Staked/types'

import {
DefaultNewDao,
daoCreatedCardPropsAtom,
newDaoAtom,
} from '../atoms/newDao'
} from '../voting-module-adapter/adapters/CwdVotingCw20Staked/types'
import { SuspenseLoader } from './SuspenseLoader'

// i18n keys
Expand Down
6 changes: 3 additions & 3 deletions packages/common/components/DaoInfoBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
useDaoInfoContext,
} from '@dao-dao/stateless'
import { loadableToLoadingData } from '@dao-dao/utils'

import {
useCw20GovernanceTokenInfoResponseIfExists,
useVotingModuleAdapter,
} from '@dao-dao/voting-module-adapter'
import { useVotingModuleAdapterOptions } from '@dao-dao/voting-module-adapter/react/context'

} from '../voting-module-adapter'
import { useVotingModuleAdapterOptions } from '../voting-module-adapter/react/context'
import { SuspenseLoader } from './SuspenseLoader'

export const DaoInfoBar = (props: InnerDaoInfoBarProps) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/components/DaoPageWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
DaoInfo,
DaoInfoSerializable,
} from '@dao-dao/types'
import { VotingModuleAdapterProvider } from '@dao-dao/voting-module-adapter'

import { ActionsProvider } from '../actions'
import { VotingModuleAdapterProvider } from '../voting-module-adapter'
import { SuspenseLoader } from './SuspenseLoader'
import { Trans } from './Trans'

Expand Down
11 changes: 6 additions & 5 deletions packages/common/components/ProposalLine.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { ComponentType } from 'react'

import { SuspenseLoader } from '@dao-dao/common'
import {
ProposalModuleAdapterProvider,
useProposalModuleAdapter,
} from '@dao-dao/proposal-module-adapter'
import {
Loader as DefaultLoader,
Logo as DefaultLogo,
Expand All @@ -14,6 +9,12 @@ import {
} from '@dao-dao/stateless'
import { ProposalModule } from '@dao-dao/types'

import {
ProposalModuleAdapterProvider,
useProposalModuleAdapter,
} from '../proposal-module-adapter'
import { SuspenseLoader } from './SuspenseLoader'

export interface ProposalLineProps {
chainId: string
coreAddress: string
Expand Down
5 changes: 3 additions & 2 deletions packages/common/components/ProposalList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import { useEffect, useMemo, useState } from 'react'
import { useRecoilCallback } from 'recoil'

import { ProposalLine, ProposalLineProps } from '@dao-dao/common'
import { matchAndLoadCommon } from '@dao-dao/proposal-module-adapter'
import { useVotingModule } from '@dao-dao/state'
import {
Loader,
Expand All @@ -14,6 +12,9 @@ import {
useDaoInfoContext,
} from '@dao-dao/stateless'

import { matchAndLoadCommon } from '../proposal-module-adapter'
import { ProposalLine, ProposalLineProps } from './ProposalLine'

// Contracts enforce a max of 30, though this is on the edge for DAOs with
// proposals that have a large size.
const PROP_LOAD_LIMIT = 20
Expand Down
9 changes: 5 additions & 4 deletions packages/common/hooks/useEncodedCwdProposalSinglePrefill.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useDaoInfoContext } from '@dao-dao/stateless'
import { Action, ProposalPrefill } from '@dao-dao/types'

import {
CwdProposalSingleAdapter,
matchAdapter as matchProposalModuleAdapter,
} from '@dao-dao/proposal-module-adapter'
import { NewProposalForm } from '@dao-dao/proposal-module-adapter/adapters/CwdProposalSingle/types'
import { useDaoInfoContext } from '@dao-dao/stateless'
import { Action, ProposalPrefill } from '@dao-dao/types'
} from '../proposal-module-adapter'
import { NewProposalForm } from '../proposal-module-adapter/adapters/CwdProposalSingle/types'

interface ActionAndData<Data extends {} = any> {
action: Action<Data, any>
Expand Down
5 changes: 3 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
"dependencies": {
"@cosmjs/encoding": "0.28.10",
"@cosmjs/stargate": "0.28.10",
"@dao-dao/proposal-module-adapter": "2.0.1",
"@dao-dao/state": "2.0.1",
"@dao-dao/stateless": "2.0.1",
"@dao-dao/utils": "2.0.1",
"@dao-dao/voting-module-adapter": "2.0.1",
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@mui/icons-material": "^5.10.3",
"@mui/material": "^5.10.3",
"@walletconnect/browser-utils": "^1.8.0",
"axios": "^0.26.1",
"a11y-react-emoji": "^1.2.0",
"buffer": "^6.0.3",
"clsx": "^1.1.1",
"fuse.js": "^6.6.2",
"i18next": "^21.8.10",
Expand All @@ -28,6 +28,7 @@
"react-hook-form": "7.20.4",
"react-hot-toast": "^2.1.1",
"react-i18next": "^11.0.0",
"react-timeago": "^7.1.0",
"recoil": "^0.7.2",
"remove-markdown": "^0.5.0"
},
Expand Down
Loading

0 comments on commit 5ca82d4

Please sign in to comment.