Skip to content

Commit

Permalink
fixed authz exec broken when wallet using it for a DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Nov 28, 2024
1 parent 898f16f commit 6e0b850
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
9 changes: 2 additions & 7 deletions packages/stateful/actions/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion packages/stateful/actions/core/actions/Spend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,9 @@ export class SpendAction extends ActionBase<SpendData> {
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
? {
Expand Down
7 changes: 6 additions & 1 deletion packages/types/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e0b850

Please sign in to comment.