Skip to content

Commit 3a289e8

Browse files
committed
Dashboard: Fix token not added to UB on launch success (#7931)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on improving the handling of the `contractAddress` state in the `LaunchTokenStatus` component by using a `ref` to avoid stale closures and ensure the latest address is used during execution. ### Detailed summary - Added `useCallback` and `useRef` imports. - Replaced the state setter for `contractAddress` with a callback to update a `ref`. - Updated the condition to check `contractAddressRef.current` instead of `contractAddress` when launching. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - Bug Fixes - Improved reliability of the token launch flow so the final confirmation consistently uses the latest deployed contract address. - Prevents rare cases where an outdated address could be shown or used after deployment, reducing intermittent post-launch errors. - Fix applies to ERC20 and Drop ERC20 deployments; no visible UI changes, just more consistent launches and confirmations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e9efeba commit 3a289e8

File tree

1 file changed

+13
-4
lines changed
  • apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/tokens/create/token/launch

1 file changed

+13
-4
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/tokens/create/token/launch/launch-token.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ImageOffIcon,
66
} from "lucide-react";
77
import Link from "next/link";
8-
import { useState } from "react";
8+
import { useCallback, useRef, useState } from "react";
99
import type { ThirdwebClient } from "thirdweb";
1010
import { useActiveWallet } from "thirdweb/react";
1111
import {
@@ -68,7 +68,16 @@ export function LaunchTokenStatus(props: {
6868
const { createTokenFunctions } = props;
6969
const [steps, setSteps] = useState<MultiStepState<StepId>[]>([]);
7070
const [isModalOpen, setIsModalOpen] = useState(false);
71-
const [contractAddress, setContractAddress] = useState<string | null>(null);
71+
const [contractAddress, _setContractAddress] = useState<string | null>(null);
72+
73+
// needed to add a ref to avoid `executeSteps` using the stale value of state `contractAddress` because of closure
74+
const contractAddressRef = useRef<string | null>(null);
75+
76+
const setContractAddress = useCallback((address: string) => {
77+
_setContractAddress(address);
78+
contractAddressRef.current = address;
79+
}, []);
80+
7281
const activeWallet = useActiveWallet();
7382
const walletRequiresApproval = activeWallet?.id !== "inApp";
7483

@@ -241,10 +250,10 @@ export function LaunchTokenStatus(props: {
241250
: "ERC20Asset",
242251
});
243252

244-
if (contractAddress) {
253+
if (contractAddressRef.current) {
245254
props.onLaunchSuccess({
246255
chainId: Number(formValues.chain),
247-
contractAddress,
256+
contractAddress: contractAddressRef.current,
248257
});
249258
}
250259
}

0 commit comments

Comments
 (0)