From 15e36d821192ebd9256eeeddc6df1915b507b962 Mon Sep 17 00:00:00 2001
From: magiodev <31893902+magiodev@users.noreply.github.com>
Date: Wed, 17 Apr 2024 16:33:55 +0200
Subject: [PATCH 1/3] implement cosmwasm MsgUpdateAdmin msgType
---
.../TxMsgUpdateAdminContractDetails.tsx | 59 ++++++++
.../dataViews/TransactionInfo/index.tsx | 3 +
.../MsgForm/MsgUpdateAdminContractForm.tsx | 128 ++++++++++++++++++
.../forms/CreateTxForm/MsgForm/index.tsx | 3 +
components/forms/CreateTxForm/index.tsx | 3 +
lib/txMsgHelpers.ts | 5 +-
types/txMsg.ts | 3 +
7 files changed, 202 insertions(+), 2 deletions(-)
create mode 100644 components/dataViews/TransactionInfo/TxMsgUpdateAdminContractDetails.tsx
create mode 100644 components/forms/CreateTxForm/MsgForm/MsgUpdateAdminContractForm.tsx
diff --git a/components/dataViews/TransactionInfo/TxMsgUpdateAdminContractDetails.tsx b/components/dataViews/TransactionInfo/TxMsgUpdateAdminContractDetails.tsx
new file mode 100644
index 0000000..04e9e3f
--- /dev/null
+++ b/components/dataViews/TransactionInfo/TxMsgUpdateAdminContractDetails.tsx
@@ -0,0 +1,59 @@
+import { MsgUpdateAdmin } from "cosmjs-types/cosmwasm/wasm/v1/tx";
+import HashView from "../HashView";
+
+interface TxMsgUpdateAdminDetailsProps {
+ readonly msgValue: MsgUpdateAdmin;
+}
+
+const TxMsgUpdateAdminDetails = ({ msgValue }: TxMsgUpdateAdminDetailsProps) => {
+ return (
+ <>
+
+ MsgUpdateAdmin
+
+
+
+
+
+
+
+
+
+ {msgValue.newAdmin.toString()}
+
+
+ >
+ );
+};
+
+export default TxMsgUpdateAdminDetails;
diff --git a/components/dataViews/TransactionInfo/index.tsx b/components/dataViews/TransactionInfo/index.tsx
index e0a959b..c8f6c42 100644
--- a/components/dataViews/TransactionInfo/index.tsx
+++ b/components/dataViews/TransactionInfo/index.tsx
@@ -16,6 +16,7 @@ import TxMsgSendDetails from "./TxMsgSendDetails";
import TxMsgSetWithdrawAddressDetails from "./TxMsgSetWithdrawAddressDetails";
import TxMsgTransferDetails from "./TxMsgTransferDetails";
import TxMsgUndelegateDetails from "./TxMsgUndelegateDetails";
+import TxMsgUpdateAdminContractDetails from "./TxMsgUpdateAdminContractDetails";
const TxMsgDetails = ({ typeUrl, value: msgValue }: EncodeObject) => {
switch (typeUrl) {
@@ -43,6 +44,8 @@ const TxMsgDetails = ({ typeUrl, value: msgValue }: EncodeObject) => {
return ;
case MsgTypeUrls.Migrate:
return ;
+ case MsgTypeUrls.UpdateAdmin:
+ return ;
default:
return null;
}
diff --git a/components/forms/CreateTxForm/MsgForm/MsgUpdateAdminContractForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgUpdateAdminContractForm.tsx
new file mode 100644
index 0000000..3aa6e75
--- /dev/null
+++ b/components/forms/CreateTxForm/MsgForm/MsgUpdateAdminContractForm.tsx
@@ -0,0 +1,128 @@
+import { MsgUpdateAdminEncodeObject } from "@cosmjs/cosmwasm-stargate";
+import { useEffect, useRef, useState } from "react";
+import { MsgGetter } from "..";
+import { useChains } from "../../../../context/ChainsContext";
+import { checkAddress, exampleAddress, trimStringsObj } from "../../../../lib/displayHelpers";
+import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg";
+import Input from "../../../inputs/Input";
+import StackableContainer from "../../../layout/StackableContainer";
+
+interface MsgUpdateAdminContractFormProps {
+ readonly fromAddress: string;
+ readonly setMsgGetter: (msgGetter: MsgGetter) => void;
+ readonly deleteMsg: () => void;
+}
+
+const MsgUpdateAdminContractForm = ({
+ fromAddress,
+ setMsgGetter,
+ deleteMsg,
+ }: MsgUpdateAdminContractFormProps) => {
+ const { chain } = useChains();
+
+ const [contractAddress, setContractAddress] = useState("");
+ const [newAdmin, setNewAdmin] = useState("");
+
+ const [contractAddressError, setContractAddressError] = useState("");
+ const [codeIdError, setNewAdminError] = useState("");
+
+ const trimmedInputs = trimStringsObj({ contractAddress, newAdmin });
+
+ useEffect(() => {
+ // eslint-disable-next-line no-shadow
+ const { contractAddress, newAdmin } = trimmedInputs;
+
+ const isMsgValid = (): boolean => {
+ setContractAddressError("");
+ setNewAdminError("");
+
+ const addressErrorMsg = checkAddress(contractAddress, chain.addressPrefix);
+ if (addressErrorMsg) {
+ setContractAddressError(`Invalid address for network ${chain.chainId}: ${addressErrorMsg}`);
+ return false;
+ }
+
+ const newAdminErrorMsg = checkAddress(newAdmin, chain.addressPrefix);
+ if (newAdminErrorMsg) {
+ setNewAdminError("New admin should be a valid bech32 address.");
+ return false;
+ }
+
+ return true;
+ };
+
+ const msgValue = MsgCodecs[MsgTypeUrls.UpdateAdmin].fromPartial({
+ sender: fromAddress,
+ contract: contractAddress,
+ newAdmin: newAdmin,
+ });
+
+ const msg: MsgUpdateAdminEncodeObject = { typeUrl: MsgTypeUrls.UpdateAdmin, value: msgValue };
+
+ setMsgGetter({ isMsgValid, msg });
+ }, [chain.addressPrefix, chain.chainId, fromAddress, setMsgGetter, trimmedInputs]);
+
+ return (
+
+
+ MsgUpdateAdminContract
+
+ {
+ setContractAddress(target.value);
+ setContractAddressError("");
+ }}
+ error={contractAddressError}
+ placeholder={`E.g. ${exampleAddress(0, chain.addressPrefix)}`}
+ />
+
+
+ {
+ setNewAdmin(target.value);
+ setNewAdminError("");
+ }}
+ error={codeIdError}
+ />
+
+
+
+ );
+};
+
+export default MsgUpdateAdminContractForm;
diff --git a/components/forms/CreateTxForm/MsgForm/index.tsx b/components/forms/CreateTxForm/MsgForm/index.tsx
index 21f048f..13718b5 100644
--- a/components/forms/CreateTxForm/MsgForm/index.tsx
+++ b/components/forms/CreateTxForm/MsgForm/index.tsx
@@ -12,6 +12,7 @@ import MsgSendForm from "./MsgSendForm";
import MsgSetWithdrawAddressForm from "./MsgSetWithdrawAddressForm";
import MsgTransferForm from "./MsgTransferForm";
import MsgUndelegateForm from "./MsgUndelegateForm";
+import MsgUpdateAdminContractForm from "@/components/forms/CreateTxForm/MsgForm/MsgUpdateAdminContractForm";
interface MsgFormProps {
readonly msgType: MsgTypeUrl;
@@ -46,6 +47,8 @@ const MsgForm = ({ msgType, senderAddress, ...restProps }: MsgFormProps) => {
return ;
case MsgTypeUrls.Migrate:
return ;
+ case MsgTypeUrls.UpdateAdmin:
+ return ;
default:
return null;
}
diff --git a/components/forms/CreateTxForm/index.tsx b/components/forms/CreateTxForm/index.tsx
index f5aca87..c575686 100644
--- a/components/forms/CreateTxForm/index.tsx
+++ b/components/forms/CreateTxForm/index.tsx
@@ -254,6 +254,9 @@ const CreateTxForm = ({ router, senderAddress, accountOnChain }: CreateTxFormPro
+
+
diff --git a/lib/txMsgHelpers.ts b/lib/txMsgHelpers.ts
index 5f365b3..e4022e6 100644
--- a/lib/txMsgHelpers.ts
+++ b/lib/txMsgHelpers.ts
@@ -30,6 +30,8 @@ const gasOfMsg = (msgType: MsgTypeUrl): number => {
return 150_000;
case MsgTypeUrls.Migrate:
return 150_000;
+ case MsgTypeUrls.UpdateAdmin:
+ return 150_000;
default:
throw new Error("Unknown msg type");
}
@@ -37,8 +39,7 @@ const gasOfMsg = (msgType: MsgTypeUrl): number => {
export const gasOfTx = (msgTypes: readonly MsgTypeUrl[]): number => {
const txFlatGas = 100_000;
- const totalTxGas = msgTypes.reduce((acc, msgType) => acc + gasOfMsg(msgType), txFlatGas);
- return totalTxGas;
+ return msgTypes.reduce((acc, msgType) => acc + gasOfMsg(msgType), txFlatGas);
};
export const isKnownMsgTypeUrl = (typeUrl: string): typeUrl is MsgTypeUrl =>
diff --git a/types/txMsg.ts b/types/txMsg.ts
index 6a1ccb2..129d3ab 100644
--- a/types/txMsg.ts
+++ b/types/txMsg.ts
@@ -14,6 +14,7 @@ import {
MsgInstantiateContract,
MsgInstantiateContract2,
MsgMigrateContract,
+ MsgUpdateAdmin
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
@@ -30,6 +31,7 @@ export const MsgTypeUrls = {
Instantiate: "/cosmwasm.wasm.v1.MsgInstantiateContract",
Instantiate2: "/cosmwasm.wasm.v1.MsgInstantiateContract2",
Migrate: "/cosmwasm.wasm.v1.MsgMigrateContract",
+ UpdateAdmin: "/cosmwasm.wasm.v1.MsgUpdateAdmin",
} as const;
export type MsgTypeUrl = (typeof MsgTypeUrls)[keyof typeof MsgTypeUrls];
@@ -47,4 +49,5 @@ export const MsgCodecs = {
[MsgTypeUrls.Instantiate]: MsgInstantiateContract,
[MsgTypeUrls.Instantiate2]: MsgInstantiateContract2,
[MsgTypeUrls.Migrate]: MsgMigrateContract,
+ [MsgTypeUrls.UpdateAdmin]: MsgUpdateAdmin,
};
From b5a3148c6bd8684dd72a44cf99ecc6a378e179e1 Mon Sep 17 00:00:00 2001
From: magiodev <31893902+magiodev@users.noreply.github.com>
Date: Thu, 18 Apr 2024 10:13:01 +0200
Subject: [PATCH 2/3] renaming components consistently as protobuf definition
---
...ContractDetails.tsx => TxMsgUpdateAdminDetails.tsx} | 0
components/dataViews/TransactionInfo/index.tsx | 4 ++--
...ateAdminContractForm.tsx => MsgUpdateAdminForm.tsx} | 10 +++++-----
components/forms/CreateTxForm/MsgForm/index.tsx | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)
rename components/dataViews/TransactionInfo/{TxMsgUpdateAdminContractDetails.tsx => TxMsgUpdateAdminDetails.tsx} (100%)
rename components/forms/CreateTxForm/MsgForm/{MsgUpdateAdminContractForm.tsx => MsgUpdateAdminForm.tsx} (94%)
diff --git a/components/dataViews/TransactionInfo/TxMsgUpdateAdminContractDetails.tsx b/components/dataViews/TransactionInfo/TxMsgUpdateAdminDetails.tsx
similarity index 100%
rename from components/dataViews/TransactionInfo/TxMsgUpdateAdminContractDetails.tsx
rename to components/dataViews/TransactionInfo/TxMsgUpdateAdminDetails.tsx
diff --git a/components/dataViews/TransactionInfo/index.tsx b/components/dataViews/TransactionInfo/index.tsx
index c8f6c42..d0737fa 100644
--- a/components/dataViews/TransactionInfo/index.tsx
+++ b/components/dataViews/TransactionInfo/index.tsx
@@ -16,7 +16,7 @@ import TxMsgSendDetails from "./TxMsgSendDetails";
import TxMsgSetWithdrawAddressDetails from "./TxMsgSetWithdrawAddressDetails";
import TxMsgTransferDetails from "./TxMsgTransferDetails";
import TxMsgUndelegateDetails from "./TxMsgUndelegateDetails";
-import TxMsgUpdateAdminContractDetails from "./TxMsgUpdateAdminContractDetails";
+import TxMsgUpdateAdminDetails from "./TxMsgUpdateAdminDetails";
const TxMsgDetails = ({ typeUrl, value: msgValue }: EncodeObject) => {
switch (typeUrl) {
@@ -45,7 +45,7 @@ const TxMsgDetails = ({ typeUrl, value: msgValue }: EncodeObject) => {
case MsgTypeUrls.Migrate:
return ;
case MsgTypeUrls.UpdateAdmin:
- return ;
+ return ;
default:
return null;
}
diff --git a/components/forms/CreateTxForm/MsgForm/MsgUpdateAdminContractForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgUpdateAdminForm.tsx
similarity index 94%
rename from components/forms/CreateTxForm/MsgForm/MsgUpdateAdminContractForm.tsx
rename to components/forms/CreateTxForm/MsgForm/MsgUpdateAdminForm.tsx
index 3aa6e75..066044b 100644
--- a/components/forms/CreateTxForm/MsgForm/MsgUpdateAdminContractForm.tsx
+++ b/components/forms/CreateTxForm/MsgForm/MsgUpdateAdminForm.tsx
@@ -7,17 +7,17 @@ import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg";
import Input from "../../../inputs/Input";
import StackableContainer from "../../../layout/StackableContainer";
-interface MsgUpdateAdminContractFormProps {
+interface MsgUpdateAdminFormProps {
readonly fromAddress: string;
readonly setMsgGetter: (msgGetter: MsgGetter) => void;
readonly deleteMsg: () => void;
}
-const MsgUpdateAdminContractForm = ({
+const MsgUpdateAdminForm = ({
fromAddress,
setMsgGetter,
deleteMsg,
- }: MsgUpdateAdminContractFormProps) => {
+ }: MsgUpdateAdminFormProps) => {
const { chain } = useChains();
const [contractAddress, setContractAddress] = useState("");
@@ -67,7 +67,7 @@ const MsgUpdateAdminContractForm = ({
- MsgUpdateAdminContract
+ MsgUpdateAdmin
{
case MsgTypeUrls.Migrate:
return
;
case MsgTypeUrls.UpdateAdmin:
- return
;
+ return
;
default:
return null;
}
From 77ea4aac6c70592ba62dc1d327774227acf739df Mon Sep 17 00:00:00 2001
From: abefernan <44572727+abefernan@users.noreply.github.com>
Date: Tue, 11 Jun 2024 07:43:41 +0200
Subject: [PATCH 3/3] Add tweaks
---
.../TxMsgUpdateAdminDetails.tsx | 4 +-
.../MsgForm/MsgUpdateAdminForm.tsx | 91 ++++++++++---------
.../forms/CreateTxForm/MsgForm/index.tsx | 2 +-
components/forms/CreateTxForm/index.tsx | 5 +-
lib/txMsgHelpers.ts | 3 +-
types/txMsg.ts | 2 +-
6 files changed, 57 insertions(+), 50 deletions(-)
diff --git a/components/dataViews/TransactionInfo/TxMsgUpdateAdminDetails.tsx b/components/dataViews/TransactionInfo/TxMsgUpdateAdminDetails.tsx
index 04e9e3f..9a7c1d8 100644
--- a/components/dataViews/TransactionInfo/TxMsgUpdateAdminDetails.tsx
+++ b/components/dataViews/TransactionInfo/TxMsgUpdateAdminDetails.tsx
@@ -19,7 +19,9 @@ const TxMsgUpdateAdminDetails = ({ msgValue }: TxMsgUpdateAdminDetailsProps) =>
- {msgValue.newAdmin.toString()}
+
+
+
);
diff --git a/components/forms/CreateTxForm/MsgForm/index.tsx b/components/forms/CreateTxForm/MsgForm/index.tsx
index 11da8d3..82c840a 100644
--- a/components/forms/CreateTxForm/MsgForm/index.tsx
+++ b/components/forms/CreateTxForm/MsgForm/index.tsx
@@ -12,7 +12,7 @@ import MsgSendForm from "./MsgSendForm";
import MsgSetWithdrawAddressForm from "./MsgSetWithdrawAddressForm";
import MsgTransferForm from "./MsgTransferForm";
import MsgUndelegateForm from "./MsgUndelegateForm";
-import MsgUpdateAdminForm from "@/components/forms/CreateTxForm/MsgForm/MsgUpdateAdminForm";
+import MsgUpdateAdminForm from "./MsgUpdateAdminForm";
interface MsgFormProps {
readonly msgType: MsgTypeUrl;
diff --git a/components/forms/CreateTxForm/index.tsx b/components/forms/CreateTxForm/index.tsx
index c575686..10e50a4 100644
--- a/components/forms/CreateTxForm/index.tsx
+++ b/components/forms/CreateTxForm/index.tsx
@@ -255,7 +255,10 @@ const CreateTxForm = ({ router, senderAddress, accountOnChain }: CreateTxFormPro
diff --git a/lib/txMsgHelpers.ts b/lib/txMsgHelpers.ts
index e4022e6..3fa8f2c 100644
--- a/lib/txMsgHelpers.ts
+++ b/lib/txMsgHelpers.ts
@@ -39,7 +39,8 @@ const gasOfMsg = (msgType: MsgTypeUrl): number => {
export const gasOfTx = (msgTypes: readonly MsgTypeUrl[]): number => {
const txFlatGas = 100_000;
- return msgTypes.reduce((acc, msgType) => acc + gasOfMsg(msgType), txFlatGas);
+ const totalTxGas = msgTypes.reduce((acc, msgType) => acc + gasOfMsg(msgType), txFlatGas);
+ return totalTxGas;
};
export const isKnownMsgTypeUrl = (typeUrl: string): typeUrl is MsgTypeUrl =>
diff --git a/types/txMsg.ts b/types/txMsg.ts
index 129d3ab..00a4f0c 100644
--- a/types/txMsg.ts
+++ b/types/txMsg.ts
@@ -14,7 +14,7 @@ import {
MsgInstantiateContract,
MsgInstantiateContract2,
MsgMigrateContract,
- MsgUpdateAdmin
+ MsgUpdateAdmin,
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";