Skip to content

Commit

Permalink
fixed attempting to unset non-existent banner
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Nov 14, 2024
1 parent 5eb44a6 commit d7950ec
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions packages/stateful/actions/core/actions/UpdateInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,29 @@ export class UpdateInfoAction extends ActionBase<UpdateInfoData> {
}
}

encode({ banner, ...data }: UpdateInfoData): UnifiedCosmosMsg[] {
async encode({
banner,
...data
}: UpdateInfoData): Promise<UnifiedCosmosMsg[]> {
// Type-check. Should be validated in the constructor.
if (this.options.context.type !== ActionContextType.Dao) {
throw new Error('Only DAOs can update info.')
}

const isSettingBanner = !!banner

const hasBanner = !!(
await this.options.queryClient.fetchQuery(
daoDaoCoreQueries.getItem(this.options.queryClient, {
chainId: this.options.chain.chainId,
contractAddress: this.options.address,
args: {
key: 'banner',
},
})
)
).item

return [
makeExecuteSmartContractMessage({
chainId: this.options.chain.chainId,
Expand All @@ -82,11 +99,16 @@ export class UpdateInfoAction extends ActionBase<UpdateInfoData> {
},
},
}),
this.manageStorageItemsAction.encode({
setting: !!banner,
key: 'banner',
value: banner || '',
}),
// Only unset banner if it is currently set.
...(isSettingBanner || hasBanner
? [
this.manageStorageItemsAction.encode({
setting: isSettingBanner,
key: 'banner',
value: banner || '',
}),
]
: []),
]
}

Expand Down

0 comments on commit d7950ec

Please sign in to comment.