diff --git a/packages/stateful/actions/core/chain_governance/GovernanceDeposit/index.tsx b/packages/stateful/actions/core/chain_governance/GovernanceDeposit/index.tsx index 72e343a322..93485c5494 100644 --- a/packages/stateful/actions/core/chain_governance/GovernanceDeposit/index.tsx +++ b/packages/stateful/actions/core/chain_governance/GovernanceDeposit/index.tsx @@ -92,6 +92,7 @@ const InnerComponent: ActionComponent = ( ? govProposalsSelector({ status: ProposalStatus.PROPOSAL_STATUS_DEPOSIT_PERIOD, chainId, + limit: 100, }) : constSelector(undefined) ) diff --git a/packages/stateful/actions/core/chain_governance/GovernanceVote/index.tsx b/packages/stateful/actions/core/chain_governance/GovernanceVote/index.tsx index 9f60ec18da..48c575920d 100644 --- a/packages/stateful/actions/core/chain_governance/GovernanceVote/index.tsx +++ b/packages/stateful/actions/core/chain_governance/GovernanceVote/index.tsx @@ -68,6 +68,7 @@ const Component: ActionComponent = (props) => { ? govProposalsSelector({ status: ProposalStatus.PROPOSAL_STATUS_VOTING_PERIOD, chainId, + limit: 100, }) : constSelector(undefined) ) diff --git a/packages/stateful/actions/core/dao_governance/SetUpApprover/index.tsx b/packages/stateful/actions/core/dao_governance/SetUpApprover/index.tsx index 3d24f25f89..3f79c39271 100644 --- a/packages/stateful/actions/core/dao_governance/SetUpApprover/index.tsx +++ b/packages/stateful/actions/core/dao_governance/SetUpApprover/index.tsx @@ -82,7 +82,7 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg = ( } } - const parsedMsg = decodeJsonFromBase64(info.msg) + const parsedMsg = decodeJsonFromBase64(info.msg, true) if ( !info.label.endsWith(`${DaoProposalSingleAdapterId}_approver`) || !objectMatchesStructure(parsedMsg, { @@ -104,7 +104,8 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg = ( } const parsedPreProposeMsg = decodeJsonFromBase64( - parsedMsg.pre_propose_info.module_may_propose.info.msg + parsedMsg.pre_propose_info.module_may_propose.info.msg, + true ) if ( !objectMatchesStructure(parsedPreProposeMsg, { diff --git a/packages/stateful/actions/core/nfts/TransferNft/index.tsx b/packages/stateful/actions/core/nfts/TransferNft/index.tsx index 70540e57ef..cd2094971d 100644 --- a/packages/stateful/actions/core/nfts/TransferNft/index.tsx +++ b/packages/stateful/actions/core/nfts/TransferNft/index.tsx @@ -157,7 +157,7 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg = ( executeSmartContract: true, smartContractMsg: JSON.stringify( - decodeJsonFromBase64(msg.wasm.execute.msg.send_nft.msg), + decodeJsonFromBase64(msg.wasm.execute.msg.send_nft.msg, true), null, 2 ), diff --git a/packages/stateful/actions/core/smart_contracting/Execute/index.tsx b/packages/stateful/actions/core/smart_contracting/Execute/index.tsx index d08caddbde..38cad7d32a 100644 --- a/packages/stateful/actions/core/smart_contracting/Execute/index.tsx +++ b/packages/stateful/actions/core/smart_contracting/Execute/index.tsx @@ -221,7 +221,7 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg = ( : msg.wasm.execute.contract_addr, message: JSON.stringify( isCw20 - ? decodeJsonFromBase64(msg.wasm.execute.msg.send.msg) + ? decodeJsonFromBase64(msg.wasm.execute.msg.send.msg, true) : msg.wasm.execute.msg, undefined, 2 diff --git a/packages/stateful/actions/core/smart_contracting/Instantiate2/index.tsx b/packages/stateful/actions/core/smart_contracting/Instantiate2/index.tsx index 901515e812..cc1df3dd75 100644 --- a/packages/stateful/actions/core/smart_contracting/Instantiate2/index.tsx +++ b/packages/stateful/actions/core/smart_contracting/Instantiate2/index.tsx @@ -225,7 +225,7 @@ export const makeInstantiate2Action: ActionMaker = ( admin: msg.stargate.value.admin, code_id: Number(msg.stargate.value.codeId), label: msg.stargate.value.label, - msg: decodeJsonFromBase64(toBase64(msg.stargate.value.msg)), + msg: decodeJsonFromBase64(toBase64(msg.stargate.value.msg), true), funds: msg.stargate.value.funds, fix_msg: msg.stargate.value.fixMsg, salt: fromUtf8(msg.stargate.value.salt), diff --git a/packages/stateful/actions/core/treasury/ManageVesting/index.tsx b/packages/stateful/actions/core/treasury/ManageVesting/index.tsx index 82ab1036ca..38310de8d5 100644 --- a/packages/stateful/actions/core/treasury/ManageVesting/index.tsx +++ b/packages/stateful/actions/core/treasury/ManageVesting/index.tsx @@ -874,7 +874,7 @@ export const makeManageVestingAction: ActionMaker = ( }, }) && objectMatchesStructure( - decodeJsonFromBase64(msg.wasm.execute.msg.send.msg), + decodeJsonFromBase64(msg.wasm.execute.msg.send.msg, true), { instantiate_payroll_contract: instantiateStructure, } @@ -934,8 +934,10 @@ export const makeManageVestingAction: ActionMaker = ( // isCw20Begin else { // Extract instantiate message from cw20 send message. - instantiateMsg = decodeJsonFromBase64(msg.wasm.execute.msg.send.msg) - .instantiate_payroll_contract.instantiate_msg as VestingInstantiateMsg + instantiateMsg = decodeJsonFromBase64( + msg.wasm.execute.msg.send.msg, + true + ).instantiate_payroll_contract?.instantiate_msg as VestingInstantiateMsg } } diff --git a/packages/stateful/actions/core/treasury/token_swap/PerformTokenSwap/index.tsx b/packages/stateful/actions/core/treasury/token_swap/PerformTokenSwap/index.tsx index 8bec0993e4..089963de8a 100644 --- a/packages/stateful/actions/core/treasury/token_swap/PerformTokenSwap/index.tsx +++ b/packages/stateful/actions/core/treasury/token_swap/PerformTokenSwap/index.tsx @@ -233,7 +233,8 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg = ( }) && // Use common key to identify CW20s being sent to token swaps from this // DAO DAO action. - CW20_SEND_MSG_KEY in decodeJsonFromBase64(msg.wasm.execute.msg.send.msg) + CW20_SEND_MSG_KEY in + decodeJsonFromBase64(msg.wasm.execute.msg.send.msg, true) ) { return { match: true, diff --git a/packages/stateless/components/dao/create/pages/CreateDaoReview.tsx b/packages/stateless/components/dao/create/pages/CreateDaoReview.tsx index 9ecb15e638..31e26b99db 100644 --- a/packages/stateless/components/dao/create/pages/CreateDaoReview.tsx +++ b/packages/stateless/components/dao/create/pages/CreateDaoReview.tsx @@ -3,7 +3,11 @@ import { useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { CreateDaoContext, DaoInfoCard } from '@dao-dao/types' -import { decodeJsonFromBase64, processError } from '@dao-dao/utils' +import { + decodeJsonFromBase64, + objectMatchesStructure, + processError, +} from '@dao-dao/utils' import { CosmosMessageDisplay } from '../../../CosmosMessageDisplay' import { Checkbox } from '../../../inputs/Checkbox' @@ -47,10 +51,15 @@ export const CreateDaoReview = ({ // Convert encoded pre_propose_info message back to readable JSON. if ( - 'pre_propose_info' in msg && - 'module_may_propose' in msg.pre_propose_info && - 'info' in msg.pre_propose_info.module_may_propose && - 'msg' in msg.pre_propose_info.module_may_propose.info + objectMatchesStructure(msg, { + pre_propose_info: { + module_may_propose: { + info: { + msg: {}, + }, + }, + }, + }) ) { msg.pre_propose_info.module_may_propose.info.msg = decodeJsonFromBase64( diff --git a/packages/utils/messages/cw.ts b/packages/utils/messages/cw.ts index 88a7ba5906..52ad905625 100644 --- a/packages/utils/messages/cw.ts +++ b/packages/utils/messages/cw.ts @@ -99,7 +99,7 @@ export const decodeMessage = (msg: CosmosMsgFor_Empty): Record => { if (msgType && isBinaryType(msgType)) { const base64MsgContainer = (msg.wasm as any)[msgType] if (base64MsgContainer && 'msg' in base64MsgContainer) { - const parsedMsg = decodeJsonFromBase64(base64MsgContainer.msg) + const parsedMsg = decodeJsonFromBase64(base64MsgContainer.msg, true) if (parsedMsg) { return { ...msg, diff --git a/packages/utils/messages/encoding.ts b/packages/utils/messages/encoding.ts index bff9472bf1..b7b2e7645c 100644 --- a/packages/utils/messages/encoding.ts +++ b/packages/utils/messages/encoding.ts @@ -7,13 +7,25 @@ export const encodeJsonToBase64 = (object: any) => toBase64(toUtf8(JSON.stringify(object))) /** - * Decode base64 string into JSON object. + * Decode base64 string into JSON object. If `fallbackToString` is true and + * JSON parse fails, decoded string is returned. */ -export const decodeJsonFromBase64 = (base64String?: string) => { +export const decodeJsonFromBase64 = ( + base64String?: string, + fallbackToString = false +) => { if (base64String) { const jsonMessage = fromUtf8(fromBase64(base64String)) - if (jsonMessage) { - return JSON.parse(jsonMessage) + try { + if (jsonMessage) { + return JSON.parse(jsonMessage) + } + } catch (err) { + if (fallbackToString) { + return jsonMessage + } + + throw err } } }