Skip to content

Commit 337f52f

Browse files
committed
fix: disable start transaction button on autostart
1 parent 88618c8 commit 337f52f

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

packages/thirdweb/src/react/core/hooks/useStepExecutor.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface StepExecutorResult {
6161
currentTxIndex?: number;
6262
progress: number; // 0–100
6363
onrampStatus?: "pending" | "executing" | "completed" | "failed";
64-
isExecuting: boolean;
64+
executionState: "idle" | "executing" | "auto-starting";
6565
error?: ApiError;
6666
start: () => void;
6767
cancel: () => void;
@@ -111,7 +111,9 @@ export function useStepExecutor(
111111
const [currentTxIndex, setCurrentTxIndex] = useState<number | undefined>(
112112
undefined,
113113
);
114-
const [isExecuting, setIsExecuting] = useState(false);
114+
const [executionState, setExecutionState] = useState<
115+
"idle" | "executing" | "auto-starting"
116+
>("idle");
115117
const [error, setError] = useState<ApiError | undefined>(undefined);
116118
const [completedTxs, setCompletedTxs] = useState<Set<number>>(new Set());
117119
const [onrampStatus, setOnrampStatus] = useState<
@@ -348,11 +350,11 @@ export function useStepExecutor(
348350

349351
// Main execution function
350352
const execute = useCallback(async () => {
351-
if (isExecuting) {
353+
if (executionState !== "idle") {
352354
return;
353355
}
354356

355-
setIsExecuting(true);
357+
setExecutionState("executing");
356358
setError(undefined);
357359
const completedStatusResults: CompletedStatusResult[] = [];
358360

@@ -476,11 +478,11 @@ export function useStepExecutor(
476478
);
477479
}
478480
} finally {
479-
setIsExecuting(false);
481+
setExecutionState("idle");
480482
abortControllerRef.current = null;
481483
}
482484
}, [
483-
isExecuting,
485+
executionState,
484486
wallet,
485487
currentTxIndex,
486488
flatTxs,
@@ -494,17 +496,17 @@ export function useStepExecutor(
494496

495497
// Start execution
496498
const start = useCallback(() => {
497-
if (!isExecuting) {
499+
if (executionState === "idle") {
498500
execute();
499501
}
500-
}, [execute, isExecuting]);
502+
}, [execute, executionState]);
501503

502504
// Cancel execution
503505
const cancel = useCallback(() => {
504506
if (abortControllerRef.current) {
505507
abortControllerRef.current.abort();
506508
}
507-
setIsExecuting(false);
509+
setExecutionState("idle");
508510
if (onrampStatus === "executing") {
509511
setOnrampStatus("pending");
510512
}
@@ -523,17 +525,18 @@ export function useStepExecutor(
523525
useEffect(() => {
524526
if (
525527
autoStart &&
526-
!isExecuting &&
528+
executionState === "idle" &&
527529
currentTxIndex === undefined &&
528530
!hasInitialized.current
529531
) {
530532
hasInitialized.current = true;
533+
setExecutionState("auto-starting");
531534
// add a delay to ensure the UI is ready
532535
setTimeout(() => {
533536
start();
534537
}, 500);
535538
}
536-
}, [autoStart, isExecuting, currentTxIndex, start]);
539+
}, [autoStart, executionState, currentTxIndex, start]);
537540

538541
// Cleanup on unmount
539542
useEffect(() => {
@@ -548,7 +551,7 @@ export function useStepExecutor(
548551
currentStep,
549552
currentTxIndex,
550553
progress,
551-
isExecuting,
554+
executionState,
552555
onrampStatus,
553556
error,
554557
start,

packages/thirdweb/src/react/web/ui/Bridge/StepRunner.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function StepRunner({
8282
const {
8383
currentStep,
8484
progress,
85-
isExecuting,
85+
executionState,
8686
onrampStatus,
8787
error,
8888
start,
@@ -123,9 +123,14 @@ export function StepRunner({
123123
);
124124

125125
if (stepIndex < currentStepIndex) return "completed";
126-
if (stepIndex === currentStepIndex && isExecuting) return "executing";
126+
if (stepIndex === currentStepIndex && executionState === "executing")
127+
return "executing";
127128
if (stepIndex === currentStepIndex && error) return "failed";
128-
if (stepIndex === currentStepIndex && !isExecuting && progress === 100)
129+
if (
130+
stepIndex === currentStepIndex &&
131+
executionState === "idle" &&
132+
progress === 100
133+
)
129134
return "completed";
130135

131136
return "pending";
@@ -392,11 +397,12 @@ export function StepRunner({
392397
Retry
393398
</Button>
394399
</Container>
395-
) : !isExecuting && progress === 0 ? (
400+
) : executionState === "idle" && progress === 0 ? (
396401
<Button variant="accent" fullWidth onClick={start}>
397402
Start Transaction
398403
</Button>
399-
) : isExecuting ? (
404+
) : executionState === "executing" ||
405+
executionState === "auto-starting" ? (
400406
<Button variant="secondary" fullWidth onClick={handleCancel}>
401407
Cancel Transaction
402408
</Button>

packages/thirdweb/src/react/web/ui/PayEmbed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export function PayEmbed(props: PayEmbedProps) {
436436
);
437437
}
438438

439-
export function PayEmbed2(props: PayEmbedProps) {
439+
export function LegacyPayEmbed(props: PayEmbedProps) {
440440
const localeQuery = useConnectLocale(props.locale || "en_US");
441441
const [screen, setScreen] = useState<"buy" | "execute-tx">("buy");
442442
const theme = props.theme || "dark";

0 commit comments

Comments
 (0)