Skip to content

Commit 6021798

Browse files
ci-botAniket-Engg
authored andcommitted
fix dropdown label delay
1 parent 72c84cf commit 6021798

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

apps/remix-ide/src/blockchain/blockchain.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,6 @@ export class Blockchain extends Plugin {
796796

797797
const logTransaction = (txhash, origin) => {
798798
this.detectNetwork((error, network) => {
799-
console.log(`transaction sent: ${txhash}`, network)
800799
if (network && network.id) {
801800
_paq.push(['trackEvent', 'udapp', `sendTransaction-from-${origin}`, `${txhash}-${network.id}`])
802801
} else {

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line no-use-before-define
2-
import React, { useRef, useState } from 'react'
2+
import React, { useRef, useState, useEffect } from 'react'
33
import { FormattedMessage, useIntl } from 'react-intl'
44
import { EnvironmentProps } from '../types'
55
import { Dropdown } from 'react-bootstrap'
@@ -12,6 +12,8 @@ const _paq = (window._paq = window._paq || [])
1212
export function EnvironmentUI(props: EnvironmentProps) {
1313
const vmStateName = useRef('')
1414
const providers = props.providers.providerList
15+
const [isSwitching, setIsSwitching] = useState(false)
16+
const watchdogTimer = useRef<NodeJS.Timeout | null>(null)
1517

1618
const remixVMs = providers.filter(p => p.config.isVM)
1719
const injectedProviders = providers.filter(p => p.config.isInjected)
@@ -23,10 +25,43 @@ export function EnvironmentUI(props: EnvironmentProps) {
2325
const walletConnect = providers.find(p => p.name === 'walletconnect' || p.name === 'walletConnect')
2426
const httpProvider = providers.find(p => p.name === 'basic-http-provider' || p.name === 'web3Provider' || p.name === 'basicHttpProvider')
2527

26-
const handleChangeExEnv = (env: string) => {
27-
const provider = props.providers.providerList.find((exEnv) => exEnv.name === env)
28-
const context = provider.name
29-
props.setExecutionContext({ context })
28+
const stopSwitching = () => {
29+
if (watchdogTimer.current) {
30+
clearTimeout(watchdogTimer.current)
31+
watchdogTimer.current = null
32+
}
33+
setIsSwitching(false)
34+
}
35+
36+
useEffect(() => {
37+
if (isSwitching) {
38+
stopSwitching()
39+
}
40+
}, [props.selectedEnv])
41+
42+
const handleChangeExEnv = async (env: string) => {
43+
if (props.selectedEnv === env || isSwitching) return
44+
45+
setIsSwitching(true)
46+
47+
watchdogTimer.current = setTimeout(() => {
48+
stopSwitching()
49+
}, 10000)
50+
51+
const provider = providers.find((exEnv) => exEnv.name === env)
52+
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+
}
3065
}
3166

3267
const currentProvider = props.providers.providerList.find((exEnv) => exEnv.name === props.selectedEnv)
@@ -165,6 +200,8 @@ export function EnvironmentUI(props: EnvironmentProps) {
165200
<span className="ms-1" style = {{ textTransform: 'none', fontSize: '13px' }}>Reset State</span>
166201
</span>
167202
</CustomTooltip> }
203+
{isSwitching && <i className="fa fa-spinner fa-pulse ms-2" aria-hidden="true"></i>}
204+
168205
</label>
169206
<div className="" data-id={`selected-provider-${currentProvider && currentProvider.name}`}>
170207
<Dropdown

0 commit comments

Comments
 (0)