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

fix: transfer token mintership/operatorship transfer #140

Merged
merged 1 commit into from
Jan 18, 2024
Merged
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
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