diff --git a/packages/stateful/actions/context.ts b/packages/stateful/actions/context.ts index 1fecf1d4c..9eb15110a 100644 --- a/packages/stateful/actions/context.ts +++ b/packages/stateful/actions/context.ts @@ -6,24 +6,19 @@ import { ActionContextType, ActionEncodeContext } from '@dao-dao/types' import { useProposalModuleAdapterCommonContextIfAvailable } from '../proposal-module-adapter/react/context' /** - * Get encode context. If in a DAO, must be used inside a proposal module common - * context. + * Get encode context. */ export const useActionEncodeContext = (): ActionEncodeContext => { const { context } = useActionOptions() - const proposalModule = useProposalModuleAdapterCommonContextIfAvailable()?.options.proposalModule - if (context.type === ActionContextType.Dao && !proposalModule) { - throw new Error('Proposal module not available in DAO context.') - } return useMemo( (): ActionEncodeContext => context.type === ActionContextType.Dao ? { ...context, - proposalModule: proposalModule!, + proposalModule, } : context, [context, proposalModule] diff --git a/packages/stateful/actions/core/actions/Spend/index.tsx b/packages/stateful/actions/core/actions/Spend/index.tsx index 9f8c4354f..26de6d949 100644 --- a/packages/stateful/actions/core/actions/Spend/index.tsx +++ b/packages/stateful/actions/core/actions/Spend/index.tsx @@ -617,8 +617,9 @@ export class SpendAction extends ActionBase { if (!cw20 && toChainId !== fromChainId) { // Load voting period so we can add the IBC timeout to it. const maxVotingPeriod: Duration = - // If in a DAO, load voting period from proposal module. + // If in a DAO proposal, load voting period from proposal module. (encodeContext.type === ActionContextType.Dao && + encodeContext.proposalModule && (await encodeContext.proposalModule.getMaxVotingPeriod())) || (encodeContext.type === ActionContextType.Gov ? { diff --git a/packages/types/actions.ts b/packages/types/actions.ts index 177755213..8ff49371d 100644 --- a/packages/types/actions.ts +++ b/packages/types/actions.ts @@ -387,7 +387,12 @@ export type ActionEncodeContext = | { type: ActionContextType.Dao dao: IDaoBase - proposalModule: IProposalModuleBase + /** + * Proposal module if being used in a DAO proposal. This is undefined, for + * example, when a wallet uses AuthzExec to execute something on behalf of + * a DAO. + */ + proposalModule?: IProposalModuleBase } | { type: ActionContextType.Wallet