diff --git a/apps/remix-ide/src/app/udapp/run-tab.js b/apps/remix-ide/src/app/udapp/run-tab.js index d3fb7851ac..7fbdb599b4 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.js +++ b/apps/remix-ide/src/app/udapp/run-tab.js @@ -126,7 +126,7 @@ export class RunTab extends ViewPlugin { Currently you have no contract instances to interact with. ` - this.event.register('clearInstance', () => { + this.event.register('clearInstance', () => { // setFinalContext calls this this.instanceContainer.innerHTML = '' // clear the instances list this.instanceContainer.appendChild(instanceContainerTitle) this.instanceContainer.appendChild(this.noInstancesText) diff --git a/libs/remix-ui/run-tab/src/lib/actions/custom.ts b/libs/remix-ui/run-tab/src/lib/actions/custom.ts index 1100411043..09c0892360 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/custom.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/custom.ts @@ -10,6 +10,29 @@ export function useRunTabPlugin (plugin) { const [runTab, dispatch] = React.useReducer(runTabReducer, runTabInitialState) const setupEvents = () => { + plugin.blockchain.resetAndInit(plugin.config, { + getAddress: (cb) => { + cb(null, runTab.accounts.selectedAccount) + }, + getValue: (cb) => { + try { + const number = runTab.sendValue + const unit = runTab.sendUnit + + cb(null, Web3.utils.toWei(number, unit)) + } catch (e) { + cb(e) + } + }, + getGasLimit: (cb) => { + try { + cb(null, '0x' + new ethJSUtil.BN(runTab.gasLimit, 10).toString(16)) + } catch (e) { + cb(e.message) + } + } + }) + plugin.blockchain.events.on('newTransaction', (tx, receipt) => { plugin.emit('newTransaction', tx, receipt) }) @@ -39,29 +62,16 @@ export function useRunTabPlugin (plugin) { plugin.blockchain.event.register('addProvider', provider => addExternalProvider(provider)) plugin.blockchain.event.register('removeProvider', name => removeExternalProvider(name)) - - plugin.blockchain.resetAndInit(plugin.config, { - getAddress: (cb) => { - cb(null, runTab.accounts.selectedAccount) - }, - getValue: (cb) => { - try { - const number = runTab.sendValue - const unit = runTab.sendUnit - - cb(null, Web3.utils.toWei(number, unit)) - } catch (e) { - cb(e) - } - }, - getGasLimit: (cb) => { - try { - cb(null, '0x' + new ethJSUtil.BN(runTab.gasLimit, 10).toString(16)) - } catch (e) { - cb(e.message) - } - } - }) + plugin.on('manager', 'pluginActivated', addPluginProvider.bind(plugin)) + plugin.on('manager', 'pluginDeactivated', removePluginProvider.bind(plugin)) + + // setInterval(() => { + // fillAccountsList() + // }, 1000) + // fillAccountsList() + setTimeout(() => { + fillAccountsList() + }, 0) } const updateAccountBalances = () => { @@ -183,5 +193,5 @@ export function useRunTabPlugin (plugin) { }, setFinalContext()) } - return { runTab, setupEvents, fillAccountsList, setAccount, setUnit, setGasFee, addPluginProvider, removePluginProvider, setExecEnv, setFinalContext, setExecutionContext } + return { runTab, setupEvents, fillAccountsList, setAccount, setUnit, setGasFee, setExecEnv, setFinalContext, setExecutionContext } } diff --git a/libs/remix-ui/run-tab/src/lib/actions/payload.ts b/libs/remix-ui/run-tab/src/lib/actions/payload.ts index 5387638cc0..8886135b26 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/payload.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/payload.ts @@ -81,3 +81,16 @@ export const removeProvider = (provider: string) => { payload: provider } } + +export const displayNotification = (title: string, message: string, labelOk: string, labelCancel: string, actionOk?: (...args) => void, actionCancel?: (...args) => void) => { + return { + type: 'DISPLAY_NOTIFICATION', + payload: { title, message, labelOk, labelCancel, actionOk, actionCancel } + } +} + +export const hideNotification = () => { + return { + type: 'HIDE_NOTIFICATION' + } +} diff --git a/libs/remix-ui/run-tab/src/lib/components/environment.tsx b/libs/remix-ui/run-tab/src/lib/components/environment.tsx index e9ba916433..473fba234c 100644 --- a/libs/remix-ui/run-tab/src/lib/components/environment.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/environment.tsx @@ -3,47 +3,14 @@ import React from 'react' import { EnvironmentProps } from '../types' export function EnvironmentUI (props: EnvironmentProps) { - // setDropdown (selectExEnv) { - // this.selectExEnv = selectExEnv - - // const addProvider = (network) => { - // selectExEnv.appendChild(yo``) - // addTooltip(yo`${network.name} provider added`) - // } - - // const removeProvider = (name) => { - // var env = selectExEnv.querySelector(`option[value="${name}"]`) - // if (env) { - // selectExEnv.removeChild(env) - // addTooltip(yo`${name} provider removed`) - // } - // } - // this.blockchain.event.register('addProvider', provider => addProvider(provider)) - // this.blockchain.event.register('removeProvider', name => removeProvider(name)) - - // selectExEnv.addEventListener('change', (event) => { - // const provider = selectExEnv.options[selectExEnv.selectedIndex] - // const fork = provider.getAttribute('fork') // can be undefined if connected to an external source (web3 provider / injected) - // let context = provider.value - // context = context.startsWith('vm') ? 'vm' : context // context has to be 'vm', 'web3' or 'injected' - // this.setExecutionContext({ context, fork }) - // }) - - // selectExEnv.value = this._getProviderDropdownValue() - // } - const handleChangeExEnv = (env: string) => { - props.setExecEnv(env) - const fork = provider.getAttribute('fork') // can be undefined if connected to an external source (web3 provider / injected) + const provider = props.providers.providerList.find(exEnv => exEnv.value === env) + const fork = provider.fork // can be undefined if connected to an external source (web3 provider / injected) let context = provider.value + context = context.startsWith('vm') ? 'vm' : context // context has to be 'vm', 'web3' or 'injected' - this.setExecutionContext({ context, fork }) + props.setExecutionContext({ context, fork }) + props.setExecEnv(env) } return ( @@ -54,10 +21,10 @@ export function EnvironmentUI (props: EnvironmentProps) {