Skip to content

Commit ee7ba24

Browse files
ci-botAniket-Engg
authored andcommitted
update spinner logic
1 parent 6021798 commit ee7ba24

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

libs/remix-ui/run-tab/src/lib/components/environment.tsx

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,23 @@ export function EnvironmentUI(props: EnvironmentProps) {
1313
const vmStateName = useRef('')
1414
const providers = props.providers.providerList
1515
const [isSwitching, setIsSwitching] = useState(false)
16-
const watchdogTimer = useRef<NodeJS.Timeout | null>(null)
16+
17+
const switchTimeoutRef = useRef<NodeJS.Timeout | null>(null)
18+
19+
useEffect(() => {
20+
if (switchTimeoutRef.current) {
21+
clearTimeout(switchTimeoutRef.current)
22+
}
23+
setIsSwitching(false)
24+
}, [props.selectedEnv])
25+
26+
useEffect(() => {
27+
return () => {
28+
if (switchTimeoutRef.current) {
29+
clearTimeout(switchTimeoutRef.current)
30+
}
31+
}
32+
}, [])
1733

1834
const remixVMs = providers.filter(p => p.config.isVM)
1935
const injectedProviders = providers.filter(p => p.config.isInjected)
@@ -25,43 +41,22 @@ export function EnvironmentUI(props: EnvironmentProps) {
2541
const walletConnect = providers.find(p => p.name === 'walletconnect' || p.name === 'walletConnect')
2642
const httpProvider = providers.find(p => p.name === 'basic-http-provider' || p.name === 'web3Provider' || p.name === 'basicHttpProvider')
2743

28-
const stopSwitching = () => {
29-
if (watchdogTimer.current) {
30-
clearTimeout(watchdogTimer.current)
31-
watchdogTimer.current = null
32-
}
33-
setIsSwitching(false)
34-
}
44+
const handleChangeExEnv = (env: string) => {
45+
if (props.selectedEnv === env || isSwitching) return
3546

36-
useEffect(() => {
37-
if (isSwitching) {
38-
stopSwitching()
47+
if (switchTimeoutRef.current) {
48+
clearTimeout(switchTimeoutRef.current)
3949
}
40-
}, [props.selectedEnv])
41-
42-
const handleChangeExEnv = async (env: string) => {
43-
if (props.selectedEnv === env || isSwitching) return
4450

4551
setIsSwitching(true)
4652

47-
watchdogTimer.current = setTimeout(() => {
48-
stopSwitching()
49-
}, 10000)
50-
51-
const provider = providers.find((exEnv) => exEnv.name === env)
53+
switchTimeoutRef.current = setTimeout(() => {
54+
setIsSwitching(false)
55+
}, 8000)
5256

53-
if (provider && typeof provider.init === 'function') {
54-
try {
55-
await provider.init()
56-
props.setExecutionContext({ context: env })
57-
} catch (e) {
58-
stopSwitching()
59-
}
60-
} else {
61-
setTimeout(() => {
62-
props.setExecutionContext({ context: env })
63-
}, 0)
64-
}
57+
const provider = props.providers.providerList.find((exEnv) => exEnv.name === env)
58+
const context = provider.name
59+
props.setExecutionContext({ context })
6560
}
6661

6762
const currentProvider = props.providers.providerList.find((exEnv) => exEnv.name === props.selectedEnv)

0 commit comments

Comments
 (0)