Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use multi-chain address for admin check #535

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/pages/contract/ContractItemActions.tsx
Original file line number Diff line number Diff line change
@@ -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 { 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"

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 (
<ExtraActions>
<ModalButton
Expand Down
10 changes: 7 additions & 3 deletions src/txs/wasm/MigrateContractForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<TxValues>({ mode: "onChange" })
Expand Down
10 changes: 7 additions & 3 deletions src/txs/wasm/UpdateAdminContractForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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<TxValues>({ mode: "onChange" })
Expand Down