Skip to content

Commit

Permalink
Merge pull request #140 from axelarnetwork/bugfix/fix-token-mintershi…
Browse files Browse the repository at this point in the history
…p-operatorship-transfer

fix: transfer token mintership/operatorship transfer
  • Loading branch information
canhtrinh authored Jan 18, 2024
2 parents c10add0 + 456cbf3 commit 40ed265
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const ManageInterchainToken: FC<Props> = (props) => {
label: "Transfer Mintership",
value: "transferMintership",
icon: <GiftIcon className="h-7 w-7 md:h-8 md:w-8" />,
isVisible: () => false,
isVisible: (props) => props.isTokenMinter,
},
{
label: "Ownnership Pending Approval",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useCallback, useMemo, type FC } from "react";
import { useForm, type SubmitHandler } from "react-hook-form";

import { isAddress, TransactionExecutionError } from "viem";
import { useChainId, useWaitForTransaction } from "wagmi";
import { useAccount, useChainId, useWaitForTransaction } from "wagmi";

import { useInterchainTokenTransferMintership } from "~/lib/contracts/InterchainToken.hooks";
import { useTransactionState } from "~/lib/hooks/useTransactionState";
Expand All @@ -27,8 +27,9 @@ export const TransferInterchainTokenMintership: FC = () => {
const [txState, setTxState] = useTransactionState();
const [state] = useManageInterchainTokenContainer();
const chainId = useChainId();
const account = useAccount();

const { register, handleSubmit, formState, getValues } = useForm<FormState>({
const { register, handleSubmit, formState } = useForm<FormState>({
defaultValues: {
recipientAddress: undefined,
},
Expand All @@ -42,7 +43,7 @@ export const TransferInterchainTokenMintership: FC = () => {
data: transferResult,
} = useInterchainTokenTransferMintership({
address: state.tokenAddress,
account: getValues("recipientAddress"),
account: account.address,
});

const trpcContext = trpc.useUtils();
Expand Down Expand Up @@ -139,8 +140,7 @@ export const TransferInterchainTokenMintership: FC = () => {
</Dialog.Title>
{txState.status === "confirmed" ? (
<Alert status="success">
Token mintership has been successfully transferred. The recipient now
must accept the mintership transfer.
Token mintership has been successfully transferred.
</Alert>
) : (
<form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useCallback, useMemo, type FC } from "react";
import { useForm, type SubmitHandler } from "react-hook-form";

import { isAddress, TransactionExecutionError } from "viem";
import { useChainId, useWaitForTransaction } from "wagmi";
import { useAccount, useChainId, useWaitForTransaction } from "wagmi";

import { useInterchainTokenServiceTransferOperatorship } from "~/lib/contracts/InterchainTokenService.hooks";
import { useTransactionState } from "~/lib/hooks/useTransactionState";
Expand All @@ -27,8 +27,9 @@ export const TransferInterchainTokenOperatorship: FC = () => {
const [txState, setTxState] = useTransactionState();
const [state] = useManageInterchainTokenContainer();
const chainId = useChainId();
const account = useAccount();

const { register, handleSubmit, formState, getValues } = useForm<FormState>({
const { register, handleSubmit, formState } = useForm<FormState>({
defaultValues: {
recipientAddress: undefined,
},
Expand All @@ -37,12 +38,12 @@ export const TransferInterchainTokenOperatorship: FC = () => {
});

const {
writeAsync: transferOwnershipAsync,
writeAsync: transferOperatorshipAsync,
isLoading: isTransfering,
data: transferResult,
} = useInterchainTokenServiceTransferOperatorship({
address: state.tokenAddress,
account: getValues("recipientAddress"),
account: account.address,
});

const trpcContext = trpc.useUtils();
Expand Down Expand Up @@ -70,7 +71,7 @@ export const TransferInterchainTokenOperatorship: FC = () => {
receipt,
});

toast.success("Successfully transferred token ownership");
toast.success("Successfully transferred token operatorship");
},
});

Expand All @@ -83,7 +84,7 @@ export const TransferInterchainTokenOperatorship: FC = () => {
});

try {
const txResult = await transferOwnershipAsync({
const txResult = await transferOperatorshipAsync({
args: [data.recipientAddress],
});

Expand All @@ -97,10 +98,10 @@ export const TransferInterchainTokenOperatorship: FC = () => {
} catch (error) {
if (error instanceof TransactionExecutionError) {
toast.error(
`Failed to transfer token ownership: ${error.cause.shortMessage}`
`Failed to transfer token operatorship: ${error.cause.shortMessage}`
);
logger.error(
`Failed to transfer token ownership: ${error.cause.message}`
`Failed to transfer token operatorship: ${error.cause.message}`
);

setTxState({
Expand All @@ -115,32 +116,31 @@ export const TransferInterchainTokenOperatorship: FC = () => {
});
}
},
[chainId, setTxState, transferOwnershipAsync]
[chainId, setTxState, transferOperatorshipAsync]
);

const buttonChildren = useMemo(() => {
switch (txState.status) {
case "idle":
case "confirmed":
return "Transfer token ownership";
return "Transfer token operatorship";
case "awaiting_approval":
return "Confirm on wallet";
case "submitted":
return "Transfering token ownership";
return "Transfering token operatorship";
case "reverted":
return "Failed to transfer ownership";
return "Failed to transfer operatorship";
}
}, [txState]);

return (
<>
<Dialog.Title className="flex">
<span>Transfer token ownership</span>
<span>Transfer rate-limit manager</span>
</Dialog.Title>
{txState.status === "confirmed" ? (
<Alert status="success">
Token ownership has been successfully transferred. The recipient now
must accept the ownership transfer.
Token operatorship has been successfully transferred.
</Alert>
) : (
<form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export const getERC20TokenBalanceForOwner = publicProcedure
chainConfig,
input.tokenAddress
);
const isTokenMinter = await itClient.reads
.isMinter({
addr: input.owner,
})
.catch(always(false));
const [isTokenMinter] = await Promise.all([
itClient.reads
.isMinter({
addr: input.owner,
})
.catch(always(false)),
]);

return {
isTokenMinter,
Expand Down

1 comment on commit 40ed265

@vercel
Copy link

@vercel vercel bot commented on 40ed265 Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

axelar-ui – ./packages/ui

axelar-ui.vercel.app
axelar-ui-axelar-network.vercel.app
axelar-ui-git-main-axelar-network.vercel.app
ui.axelar.dev

Please sign in to comment.