Skip to content

Commit

Permalink
fix: reset register remote tokens mutations and tx state on confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
alanrsoares committed Jan 16, 2024
1 parent 66a292d commit 5743dbf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ export const RegisterRemoteTokens: FC<RegisterRemoteTokensProps> = (props) => {
const { address: deployerAddress } = useAccount();
const [txState, setTxState] = useTransactionState();

useEffect(
() => {
props.onTxStateChange?.(txState);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[txState.status]
);

const { mutateAsync: recordRemoteTokenDeployment } =
trpc.interchainToken.recordRemoteTokensDeployment.useMutation();

Expand Down Expand Up @@ -72,21 +64,36 @@ export const RegisterRemoteTokens: FC<RegisterRemoteTokensProps> = (props) => {
},
});

const { writeAsync: registerCanonicalTokensAsync } =
const { writeAsync: registerCanonicalTokensAsync, reset: resetCanonical } =
useRegisterRemoteCanonicalTokens({
chainIds: props.chainIds,
deployerAddress: deployerAddress as `0x${string}`,
tokenAddress: props.tokenAddress,
originChainId: props.originChainId ?? -1,
});

const { writeAsync: registerInterchainTokensAsync } =
const { writeAsync: registerInterchainTokensAsync, reset: resetInterchain } =
useRegisterRemoteInterchainTokens({
chainIds: props.chainIds,
tokenAddress: props.tokenAddress,
originChainId: props.originChainId ?? -1,
});

useEffect(
() => {
props.onTxStateChange?.(txState);

if (txState.status === "confirmed") {
// reset muations & tx state
resetCanonical();
resetInterchain();
setTxState({ status: "idle" });
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[txState.status]
);

const registerTokensAsync = useMemo(() => {
switch (props.deploymentKind) {
case "canonical":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,7 @@ const ConnectedInterchainTokensPage: FC<ConnectedInterchainTokensPageProps> = (
break;
case "confirmed":
setSessionState((draft) => {
draft.selectedChainIds = without(
[txState.chainId],
draft.selectedChainIds
) as number[];
draft.selectedChainIds = [];
});
break;
default:
Expand Down

0 comments on commit 5743dbf

Please sign in to comment.