From d212c056785ea1ccd189bf3242c33e5153b45191 Mon Sep 17 00:00:00 2001 From: Michael Merz Date: Sun, 15 Oct 2023 23:13:21 -0400 Subject: [PATCH 1/3] feat: use multi-chain address for admin check --- src/pages/contract/ContractItemActions.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pages/contract/ContractItemActions.tsx b/src/pages/contract/ContractItemActions.tsx index 0c2f1cb58..76dc6c587 100644 --- a/src/pages/contract/ContractItemActions.tsx +++ b/src/pages/contract/ContractItemActions.tsx @@ -1,16 +1,24 @@ import { useTranslation } from "react-i18next" -import { useAddress } from "data/wallet" +import { useAddress, useNetwork } from "data/wallet" +import { useInterchainAddresses } from "auth/hooks/useAddress" import { Button, LinkButton } from "components/general" import { ModalButton } from "components/feedback" import { ExtraActions } from "components/layout" import ContractQuery from "./ContractQuery" import { useContract } from "./Contract" +import { getChainIDFromAddress } from "utils/bech32" const ContractItemActions = () => { const { t } = useTranslation() - const connectedAddress = useAddress() + const networks = useNetwork() + const terraAddress = useAddress() + const addresses = useInterchainAddresses() const { address, admin } = useContract() + const chainID = getChainIDFromAddress(address, networks) + const connectedAddress = + chainID && addresses?.[chainID] ? addresses[chainID] : terraAddress + return ( Date: Sun, 15 Oct 2023 23:35:40 -0400 Subject: [PATCH 2/3] bump: import sort to bump --- src/pages/contract/ContractItemActions.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/contract/ContractItemActions.tsx b/src/pages/contract/ContractItemActions.tsx index 76dc6c587..f6ab589df 100644 --- a/src/pages/contract/ContractItemActions.tsx +++ b/src/pages/contract/ContractItemActions.tsx @@ -1,12 +1,12 @@ import { useTranslation } from "react-i18next" import { useAddress, useNetwork } from "data/wallet" import { useInterchainAddresses } from "auth/hooks/useAddress" +import { getChainIDFromAddress } from "utils/bech32" +import { useContract } from "./Contract" +import ContractQuery from "./ContractQuery" import { Button, LinkButton } from "components/general" import { ModalButton } from "components/feedback" import { ExtraActions } from "components/layout" -import ContractQuery from "./ContractQuery" -import { useContract } from "./Contract" -import { getChainIDFromAddress } from "utils/bech32" const ContractItemActions = () => { const { t } = useTranslation() From 078c1c198df72002a80dd853cce14178929fcfaa Mon Sep 17 00:00:00 2001 From: Michael Merz Date: Mon, 16 Oct 2023 00:01:35 -0400 Subject: [PATCH 3/3] feat: make migrate and update use interchain --- src/txs/wasm/MigrateContractForm.tsx | 10 +++++++--- src/txs/wasm/UpdateAdminContractForm.tsx | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/txs/wasm/MigrateContractForm.tsx b/src/txs/wasm/MigrateContractForm.tsx index 79f1c93b2..f7f8019a5 100644 --- a/src/txs/wasm/MigrateContractForm.tsx +++ b/src/txs/wasm/MigrateContractForm.tsx @@ -3,7 +3,9 @@ import { useTranslation } from "react-i18next" import { useForm } from "react-hook-form" import { AccAddress, MsgMigrateContract } from "@terra-money/feather.js" import { parseJSON, validateMsg } from "utils/data" -import { useAddress, useChainID } from "data/wallet" +import { useNetwork } from "data/wallet" +import { useInterchainAddresses } from "auth/hooks/useAddress" +import { getChainIDFromAddress } from "utils/bech32" import { Form, FormItem } from "components/form" import { Input, EditorInput } from "components/form" import validate from "../validate" @@ -18,8 +20,10 @@ interface TxValues { const MigrateContractForm = ({ contract }: { contract: AccAddress }) => { const { t } = useTranslation() - const address = useAddress() - const chainID = useChainID() + const networks = useNetwork() + const addresses = useInterchainAddresses() + const chainID = getChainIDFromAddress(contract, networks) ?? "" + const address = addresses?.[chainID ?? ""] /* form */ const form = useForm({ mode: "onChange" }) diff --git a/src/txs/wasm/UpdateAdminContractForm.tsx b/src/txs/wasm/UpdateAdminContractForm.tsx index 17965ebb3..3c37e33e6 100644 --- a/src/txs/wasm/UpdateAdminContractForm.tsx +++ b/src/txs/wasm/UpdateAdminContractForm.tsx @@ -2,9 +2,11 @@ import { useCallback, useMemo } from "react" import { useTranslation } from "react-i18next" import { useForm } from "react-hook-form" import { AccAddress, MsgUpdateContractAdmin } from "@terra-money/feather.js" -import { useAddress, useChainID } from "data/wallet" +import { useNetwork } from "data/wallet" +import { useInterchainAddresses } from "auth/hooks/useAddress" import { Form, FormItem } from "components/form" import { Input } from "components/form" +import { getChainIDFromAddress } from "utils/bech32" import validate from "../validate" import Tx from "../Tx" @@ -16,8 +18,10 @@ interface TxValues { const UpdateAdminContractForm = ({ contract }: { contract: AccAddress }) => { const { t } = useTranslation() - const address = useAddress() - const chainID = useChainID() + const networks = useNetwork() + const addresses = useInterchainAddresses() + const chainID = getChainIDFromAddress(contract, networks) ?? "" + const address = addresses?.[chainID ?? ""] /* form */ const form = useForm({ mode: "onChange" })