Skip to content

Commit fbd2729

Browse files
committed
fix: pr comments
1 parent 742527d commit fbd2729

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/components/transactions/Warnings/ChangeNetworkWarning.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type ChangeNetworkWarningProps = AlertProps & {
1515
chainId: ChainId;
1616
event?: TrackEventProps;
1717
askManualSwitch?: boolean;
18-
autoSwitchOnMount?: boolean; // New prop to control auto-switching
18+
autoSwitchOnMount?: boolean;
1919
};
2020

2121
export const ChangeNetworkWarning = ({
@@ -24,33 +24,29 @@ export const ChangeNetworkWarning = ({
2424
event,
2525
funnel,
2626
askManualSwitch = false,
27-
autoSwitchOnMount = true, // Default to true for better UX
27+
autoSwitchOnMount = true,
2828
...rest
2929
}: ChangeNetworkWarningProps) => {
3030
const { switchNetwork, switchNetworkError } = useWeb3Context();
3131
const trackEvent = useRootStore((store) => store.trackEvent);
3232

33-
// State to track auto-switch attempt
3433
const [isAutoSwitching, setIsAutoSwitching] = useState(false);
3534
const [hasAttemptedAutoSwitch, setHasAttemptedAutoSwitch] = useState(false);
3635

37-
// Auto-attempt network switch on mount
3836
useEffect(() => {
39-
if (autoSwitchOnMount && !hasAttemptedAutoSwitch) {
37+
if (autoSwitchOnMount && !hasAttemptedAutoSwitch && !isAutoSwitching) {
4038
setHasAttemptedAutoSwitch(true);
4139
setIsAutoSwitching(true);
4240

43-
// Track the automatic attempt
4441
trackEvent(GENERAL.SWITCH_NETWORK, {
4542
funnel,
4643
...event?.eventParams,
4744
network: networkName,
48-
automatic: true,
4945
});
5046

51-
// Attempt switch and handle completion
5247
switchNetwork(chainId).finally(() => {
5348
setIsAutoSwitching(false);
49+
setHasAttemptedAutoSwitch(true);
5450
});
5551
}
5652
}, [
@@ -69,20 +65,18 @@ export const ChangeNetworkWarning = ({
6965
funnel,
7066
...event?.eventParams,
7167
network: networkName,
72-
manual: true,
68+
manual: false,
7369
});
7470
switchNetwork(chainId);
7571
};
7672
return (
7773
<Warning severity="error" icon={false} {...rest}>
7874
{isAutoSwitching ? (
79-
// Show loading state during auto-switch attempt
8075
<Typography variant="description" sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
8176
<CircularProgress size={16} />
8277
<Trans>Switching to {networkName}...</Trans>
8378
</Typography>
8479
) : switchNetworkError ? (
85-
// Show error message if switch failed
8680
<Typography>
8781
<Trans>
8882
{hasAttemptedAutoSwitch

0 commit comments

Comments
 (0)