From d7950ec6bb1fb7665661e8da887941f30a48f27b Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Thu, 14 Nov 2024 11:04:28 -0500 Subject: [PATCH] fixed attempting to unset non-existent banner --- .../actions/core/actions/UpdateInfo/index.tsx | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/stateful/actions/core/actions/UpdateInfo/index.tsx b/packages/stateful/actions/core/actions/UpdateInfo/index.tsx index e434752a9..1990f186b 100644 --- a/packages/stateful/actions/core/actions/UpdateInfo/index.tsx +++ b/packages/stateful/actions/core/actions/UpdateInfo/index.tsx @@ -52,12 +52,29 @@ export class UpdateInfoAction extends ActionBase { } } - encode({ banner, ...data }: UpdateInfoData): UnifiedCosmosMsg[] { + async encode({ + banner, + ...data + }: UpdateInfoData): Promise { // 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, @@ -82,11 +99,16 @@ export class UpdateInfoAction extends ActionBase { }, }, }), - 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 || '', + }), + ] + : []), ] }