From e880aaeb04db58b369ab000404ceeda5bb29a51a Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:04:53 +0100 Subject: [PATCH] Use empty array for amount 0. Add check to execute --- .../MsgForm/MsgCreateVestingAccountForm.tsx | 4 ++-- .../MsgForm/MsgExecuteContractForm.tsx | 21 ++++++++++--------- .../MsgForm/MsgInstantiateContract2Form.tsx | 4 ++-- .../MsgForm/MsgInstantiateContractForm.tsx | 4 ++-- .../CreateTxForm/MsgForm/MsgSendForm.tsx | 4 ++-- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx index 687035c..93d5525 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx @@ -78,14 +78,14 @@ const MsgCreateVestingAccountForm = ({ try { return macroCoinToMicroCoin({ denom: chain.displayDenom, amount }, chain.assets); } catch { - return { denom: chain.displayDenom, amount: "0" }; + return null; } })(); const msgValue = MsgCodecs[MsgTypeUrls.CreateVestingAccount].fromPartial({ fromAddress, toAddress, - amount: [microCoin], + amount: microCoin ? [microCoin] : [], endTime: timestampFromDatetimeLocal(endTime, "s"), delayed, }); diff --git a/components/forms/CreateTxForm/MsgForm/MsgExecuteContractForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgExecuteContractForm.tsx index df552bd..6437a59 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgExecuteContractForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgExecuteContractForm.tsx @@ -55,6 +55,8 @@ const MsgExecuteContractForm = ({ useEffect(() => { // eslint-disable-next-line no-shadow const { contractAddress, customDenom, amount } = trimmedInputs; + const denom = + selectedDenom.value === customDenomOption.value ? customDenom : selectedDenom.value.symbol; const isMsgValid = (): boolean => { setContractAddressError(""); @@ -86,24 +88,23 @@ const MsgExecuteContractForm = ({ return false; } - try { - macroCoinToMicroCoin({ denom, amount }, chain.assets); - } catch (e: unknown) { - setAmountError(e instanceof Error ? e.message : "Could not set decimals"); - return false; + if (denom && amount) { + try { + macroCoinToMicroCoin({ denom, amount }, chain.assets); + } catch (e: unknown) { + setAmountError(e instanceof Error ? e.message : "Could not set decimals"); + return false; + } } return true; }; - const denom = - selectedDenom.value === customDenomOption.value ? customDenom : selectedDenom.value.symbol; - const microCoin = (() => { try { return macroCoinToMicroCoin({ denom, amount }, chain.assets); } catch { - return { denom, amount: "0" }; + return null; } })(); @@ -120,7 +121,7 @@ const MsgExecuteContractForm = ({ sender: fromAddress, contract: contractAddress, msg: msgContentUtf8Array, - funds: [microCoin], + funds: microCoin ? [microCoin] : [], }); const msg: MsgExecuteContractEncodeObject = { typeUrl: MsgTypeUrls.Execute, value: msgValue }; diff --git a/components/forms/CreateTxForm/MsgForm/MsgInstantiateContract2Form.tsx b/components/forms/CreateTxForm/MsgForm/MsgInstantiateContract2Form.tsx index 8b4d1a3..ff8edf8 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgInstantiateContract2Form.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgInstantiateContract2Form.tsx @@ -133,7 +133,7 @@ const MsgInstantiateContract2Form = ({ try { return macroCoinToMicroCoin({ denom, amount }, chain.assets); } catch { - return { denom, amount: "0" }; + return null; } })(); @@ -162,7 +162,7 @@ const MsgInstantiateContract2Form = ({ fixMsg: false, salt: hexSalt, msg: msgContentUtf8Array, - funds: [microCoin], + funds: microCoin ? [microCoin] : [], }); const msg: MsgInstantiateContract2EncodeObject = { diff --git a/components/forms/CreateTxForm/MsgForm/MsgInstantiateContractForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgInstantiateContractForm.tsx index 1f39410..0b478ee 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgInstantiateContractForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgInstantiateContractForm.tsx @@ -119,7 +119,7 @@ const MsgInstantiateContractForm = ({ try { return macroCoinToMicroCoin({ denom, amount }, chain.assets); } catch { - return { denom, amount: "0" }; + return null; } })(); @@ -138,7 +138,7 @@ const MsgInstantiateContractForm = ({ label, admin: adminAddress, msg: msgContentUtf8Array, - funds: [microCoin], + funds: microCoin ? [microCoin] : [], }); const msg: MsgInstantiateContractEncodeObject = { diff --git a/components/forms/CreateTxForm/MsgForm/MsgSendForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgSendForm.tsx index 4e738db..b17d746 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgSendForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgSendForm.tsx @@ -89,14 +89,14 @@ const MsgSendForm = ({ fromAddress, setMsgGetter, deleteMsg }: MsgSendFormProps) try { return macroCoinToMicroCoin({ denom, amount }, chain.assets); } catch { - return { denom, amount: "0" }; + return null; } })(); const msgValue = MsgCodecs[MsgTypeUrls.Send].fromPartial({ fromAddress, toAddress, - amount: [microCoin], + amount: microCoin ? [microCoin] : [], }); const msg: MsgSendEncodeObject = { typeUrl: MsgTypeUrls.Send, value: msgValue };