diff --git a/libs/remix-ui/run-tab/src/lib/actions/index.ts b/libs/remix-ui/run-tab/src/lib/actions/index.ts index 9c0b06e36b..ea12ad7efa 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/index.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/index.ts @@ -3,7 +3,7 @@ import React from 'react' import * as ethJSUtil from 'ethereumjs-util' import Web3 from 'web3' import { addressToString, createNonClashingNameAsync, shortenAddress } from '@remix-ui/helper' -import { addNewInstance, addProvider, clearAllInstances, clearRecorderCount, displayNotification, displayPopUp, fetchAccountsListFailed, fetchAccountsListRequest, fetchAccountsListSuccess, fetchContractListSuccess, hidePopUp, removeExistingInstance, removeProvider, setBaseFeePerGas, setConfirmSettings, setCurrentFile, setDecodedResponse, setEnvToasterContent, setExecutionEnvironment, setExternalEndpoint, setGasLimit, setGasPrice, setGasPriceStatus, setLoadType, setMatchPassphrase, setMaxFee, setMaxPriorityFee, setNetworkName, setPassphrase, setPathToScenario, setRecorderCount, setSelectedAccount, setSendUnit, setSendValue, setTxFeeContent, setWeb3Dialog } from './payload' +import { addNewInstance, addProvider, clearAllInstances, clearRecorderCount, displayNotification, displayPopUp, fetchAccountsListFailed, fetchAccountsListRequest, fetchAccountsListSuccess, fetchContractListSuccess, hidePopUp, removeExistingInstance, removeProvider, resetUdapp, setBaseFeePerGas, setConfirmSettings, setCurrentFile, setDecodedResponse, setEnvToasterContent, setExecutionEnvironment, setExternalEndpoint, setGasLimit, setGasPrice, setGasPriceStatus, setLoadType, setMatchPassphrase, setMaxFee, setMaxPriorityFee, setNetworkName, setPassphrase, setPathToScenario, setRecorderCount, setSelectedAccount, setSendUnit, setSendValue, setTxFeeContent, setWeb3Dialog } from './payload' import { RunTab } from '../types/run-tab' import { CompilerAbstract } from '@remix-project/remix-solidity' import * as remixLib from '@remix-project/remix-lib' @@ -23,6 +23,7 @@ let plugin: RunTab, dispatch: React.Dispatch export const initRunTab = (udapp: RunTab) => async (reducerDispatch: React.Dispatch) => { plugin = udapp dispatch = reducerDispatch + resetAndInit() setupEvents() setInterval(() => { fillAccountsList() @@ -30,29 +31,6 @@ export const initRunTab = (udapp: RunTab) => async (reducerDispatch: React.Dispa } const setupEvents = () => { - plugin.blockchain.resetAndInit(plugin.config, { - getAddress: (cb) => { - cb(null, plugin.REACT_API.accounts.selectedAccount) - }, - getValue: (cb) => { - try { - const number = plugin.REACT_API.sendValue - const unit = plugin.REACT_API.sendUnit - - cb(null, Web3.utils.toWei(number, unit)) - } catch (e) { - cb(e) - } - }, - getGasLimit: (cb) => { - try { - cb(null, '0x' + new ethJSUtil.BN(plugin.REACT_API.gasLimit, 10).toString(16)) - } catch (e) { - cb(e.message) - } - } - }) - plugin.blockchain.events.on('newTransaction', (tx, receipt) => { plugin.emit('newTransaction', tx, receipt) }) @@ -103,6 +81,11 @@ const setupEvents = () => { setExecutionContext(env, plugin.REACT_API.web3Dialog()) }) + plugin.on('filePanel', 'setWorkspace', () => { + dispatch(resetUdapp()) + resetAndInit() + }) + plugin.fileManager.events.on('currentFileChanged', (currentFile: string) => { if (/.(.abi)$/.exec(currentFile)) { dispatch(setLoadType('abi')) @@ -718,3 +701,28 @@ export const getFuncABIInputs = (funcABI: FuncABI) => { export const setSendTransactionValue = (value: string) => { dispatch(setSendValue(value)) } + +const resetAndInit = () => { + plugin.blockchain.resetAndInit(plugin.config, { + getAddress: (cb) => { + cb(null, plugin.REACT_API.accounts.selectedAccount) + }, + getValue: (cb) => { + try { + const number = plugin.REACT_API.sendValue + const unit = plugin.REACT_API.sendUnit + + cb(null, Web3.utils.toWei(number, unit)) + } catch (e) { + cb(e) + } + }, + getGasLimit: (cb) => { + try { + cb(null, '0x' + new ethJSUtil.BN(plugin.REACT_API.gasLimit, 10).toString(16)) + } catch (e) { + cb(e.message) + } + } + }) +} 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 bf547cbecf..bf1194c85b 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/payload.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/payload.ts @@ -283,3 +283,9 @@ export const setWeb3Dialog = () => { type: 'SET_WEB3_DIALOG' } } + +export const resetUdapp = () => { + return { + type: 'RESET_STATE' + } +} diff --git a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts index 7ad0b0f500..c932202aa5 100644 --- a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts +++ b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts @@ -656,6 +656,13 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A } } + case 'RESET_STATE': { + return { + ...runTabInitialState, + ipfsChecked: state.ipfsChecked + } + } + default: return state }