From 13c44874914a6c4f5461b8c7154ebd66b46813d2 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 15 Sep 2020 10:25:23 +0100 Subject: [PATCH] Resolved bugs in step manager --- .../lib/button-navigator/button-navigator.tsx | 4 +- .../debugger-ui/src/lib/debugger-ui.tsx | 12 ++++-- .../debugger-ui/src/lib/slider/slider.tsx | 42 +++++-------------- .../src/lib/step-manager/step-manager.tsx | 33 ++++----------- .../src/lib/tx-browser/tx-browser.tsx | 21 +++++----- 5 files changed, 38 insertions(+), 74 deletions(-) diff --git a/libs/remix-ui/debugger-ui/src/lib/button-navigator/button-navigator.tsx b/libs/remix-ui/debugger-ui/src/lib/button-navigator/button-navigator.tsx index b7b09b3b06..b2bfcc9dbb 100644 --- a/libs/remix-ui/debugger-ui/src/lib/button-navigator/button-navigator.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/button-navigator/button-navigator.tsx @@ -44,8 +44,8 @@ export const ButtonNavigation = ({ stepManager, revertedReason, stepState, jumpO jumpPreviousBreakpointDisabled: stepState === 'initial', intoForwardDisabled: stepState === 'end', overForwardDisabled: stepState === 'end', - jumpNextBreakpointDisabled: jumpOutDisabled, - jumpOutDisabled + jumpNextBreakpointDisabled: jumpOutDisabled ? jumpOutDisabled : stepState === 'end', + jumpOutDisabled: jumpOutDisabled ? jumpOutDisabled : true } }) } diff --git a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx index f9541837b5..95cd1c064e 100644 --- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx @@ -27,7 +27,7 @@ export const DebuggerUI = ({ debuggerModule, fetchContractAndCompile, debugHash, to: null }, blockNumber: null, - txNumber: null, + txNumber: '', visibility: { vmDebugger: false, stepManager: false, @@ -74,7 +74,9 @@ export const DebuggerUI = ({ debuggerModule, fetchContractAndCompile, debugHash, debuggerInstance.event.register('debuggerStatus', async (isActive) => { await debuggerModule.call('editor', 'discardHighlight') - setState({ ...state, isActive }) + setState( prevState => { + return { ...prevState, isActive } + }) }) debuggerInstance.event.register('newSourceLocation', async (lineColumnPos, rawLocation) => { @@ -192,7 +194,9 @@ const getTrace = (hash) => { const web3 = await getDebugWeb3() const currentReceipt = await web3.eth.getTransactionReceipt(hash) - setState({ ...state, currentReceipt }) + setState(prevState => { + return { ...prevState, currentReceipt } + }) const debug = new Debugger({ web3, @@ -224,7 +228,7 @@ const deleteHighlights = async () => { return (
- + {/* */}
diff --git a/libs/remix-ui/debugger-ui/src/lib/slider/slider.tsx b/libs/remix-ui/debugger-ui/src/lib/slider/slider.tsx index 3b50143418..8ce1ac31c6 100644 --- a/libs/remix-ui/debugger-ui/src/lib/slider/slider.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/slider/slider.tsx @@ -1,46 +1,26 @@ import React, { useState, useEffect } from 'react' -export const Slider = ({ stepManager, sliderLength, sliderValue }) => { +export const Slider = ({ stepManager, sliderValue }) => { const [state, setState] = useState({ - max: null, - disabled: true, - previousValue: null, - currentValue: null + currentValue: '' }) - useEffect(() => { - setState(prevState => { - return { - ...prevState, - max: sliderLength - 1, - disabled: (sliderLength === 0) - } - }) - - setValue(0) - }, [sliderLength]) - useEffect(() => { setValue(sliderValue) }, [sliderValue]) const setValue = (value) => { - setState({ ...state, currentValue: value }) + if (value === state.currentValue) return + setState(prevState => { + return { ...prevState, currentValue: value } + }) + stepManager && stepManager.jumpTo(value) } const handleChange = (e) => { - console.log('e.target: ', e.target) const value = parseInt(e.target.value) - if (value === state.previousValue) return - setState(prevState => { - return { - ...prevState, - previousValue: value, - currentValue: value - } - }) - stepManager.jumpTo(value) + setValue(value) } return ( @@ -50,10 +30,10 @@ export const Slider = ({ stepManager, sliderLength, sliderValue }) => { className='w-100 my-0' type='range' min={0} - max={state.max} - defaultValue={state.currentValue} + max={stepManager ? stepManager.traceLength - 1 : 0} + value={state.currentValue} onChange={handleChange} - disabled={state.disabled} + disabled={stepManager ? stepManager.traceLength === 0 : true} />
) diff --git a/libs/remix-ui/debugger-ui/src/lib/step-manager/step-manager.tsx b/libs/remix-ui/debugger-ui/src/lib/step-manager/step-manager.tsx index 018c1d57c3..d2b641730e 100644 --- a/libs/remix-ui/debugger-ui/src/lib/step-manager/step-manager.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/step-manager/step-manager.tsx @@ -4,7 +4,6 @@ import ButtonNavigator from '../button-navigator/button-navigator' export const StepManager = ({ stepManager }) => { const [state, setState] = useState({ - sliderLength: null, sliderValue: 0, revertWarning: '', stepState: '', @@ -12,45 +11,27 @@ export const StepManager = ({ stepManager }) => { }) useEffect(() => { - stepManager.event.register('traceLengthChanged', setSliderLength) - stepManager.event.register('revertWarning', setRevertWarning) - stepManager.event.register('stepChanged', updateStep) - }, []) - - const setSliderLength = (length) => { - setState(prevState => { - return { - ...prevState, - sliderLength: length - } - }) - } + stepManager && stepManager.event.register('revertWarning', setRevertWarning) + stepManager && stepManager.event.register('stepChanged', updateStep) + }, [stepManager]) const setRevertWarning = (warning) => { setState(prevState => { - return { - ...prevState, - revertWarning: warning - } + return { ...prevState, revertWarning: warning } }) } const updateStep = (step, stepState, jumpOutDisabled) => { setState(prevState => { - return { - ...prevState, - sliderValue: step, - stepState, - jumpOutDisabled - } + return { ...prevState, sliderValue: step, stepState, jumpOutDisabled } }) } - const { sliderLength, sliderValue, revertWarning, stepState, jumpOutDisabled } = state + const { sliderValue, revertWarning, stepState, jumpOutDisabled } = state return (
- +
) diff --git a/libs/remix-ui/debugger-ui/src/lib/tx-browser/tx-browser.tsx b/libs/remix-ui/debugger-ui/src/lib/tx-browser/tx-browser.tsx index d9a2d3291a..39841b5021 100644 --- a/libs/remix-ui/debugger-ui/src/lib/tx-browser/tx-browser.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/tx-browser/tx-browser.tsx @@ -1,10 +1,9 @@ import React, { useState, useEffect } from 'react' import './tx-browser.css' -export const TxBrowser = ({ requestDebug, unloadRequested, transactionNumber }) => { +export const TxBrowser = ({ requestDebug, unloadRequested, transactionNumber, debugging }) => { const [state, setState] = useState({ - txNumber: undefined, - debugging: false + txNumber: '' }) useEffect(() => { @@ -17,7 +16,7 @@ export const TxBrowser = ({ requestDebug, unloadRequested, transactionNumber }) }, [transactionNumber]) const handleSubmit = () => { - if (state.debugging) { + if (debugging) { unload() } else { requestDebug(undefined, state.txNumber) @@ -44,30 +43,30 @@ export const TxBrowser = ({ requestDebug, unloadRequested, transactionNumber }) } return ( -
+