diff --git a/apps/remix-ide-e2e/src/commands/validateValueInput.ts b/apps/remix-ide-e2e/src/commands/validateValueInput.ts index 61e90a80dc..9740c71e8a 100644 --- a/apps/remix-ide-e2e/src/commands/validateValueInput.ts +++ b/apps/remix-ide-e2e/src/commands/validateValueInput.ts @@ -5,9 +5,12 @@ class ValidateValueInput extends EventEmitter { command (this: NightwatchBrowser, selector: string, valueTosSet: string, expectedValue: string) { const browser = this.api browser.perform((done) => { - browser.clearValue(selector) - .pause(2000) - .setValue(selector, valueTosSet).pause(2000) + browser + .clearValue(selector) + .execute((selector) => { + (document.querySelector(selector) as any).focus() + }, [selector], () => { }) + .setValue(selector, valueTosSet) .execute(function (selector) { const elem = document.querySelector(selector) as HTMLInputElement return elem.value diff --git a/apps/remix-ide-e2e/src/helpers/init.ts b/apps/remix-ide-e2e/src/helpers/init.ts index cf56435aae..ac327e1fa1 100644 --- a/apps/remix-ide-e2e/src/helpers/init.ts +++ b/apps/remix-ide-e2e/src/helpers/init.ts @@ -40,12 +40,16 @@ export default function (browser: NightwatchBrowser, callback: VoidFunction, url }}) .perform(() => { browser.execute(function () { - (window as any).logs = [] + (window as any).logs = []; + (console as any).browserLog = console.log; + (console as any).browserError = console.error console.log = function () { - (window as any).logs.push(JSON.stringify(arguments)) + (window as any).logs.push(JSON.stringify(arguments)); + (console as any).browserLog(...arguments) } console.error = function () { - (window as any).logs.push(JSON.stringify(arguments)) + (window as any).logs.push(JSON.stringify(arguments)); + (console as any).browserError(...arguments) } }) }) diff --git a/apps/remix-ide-e2e/src/tests/runAndDeploy.test.ts b/apps/remix-ide-e2e/src/tests/runAndDeploy.test.ts index 0dda6bad28..33036dd789 100644 --- a/apps/remix-ide-e2e/src/tests/runAndDeploy.test.ts +++ b/apps/remix-ide-e2e/src/tests/runAndDeploy.test.ts @@ -25,9 +25,10 @@ module.exports = { 'Should load run and deploy tab and check value validation #group1': function (browser: NightwatchBrowser) { browser.waitForElementPresent('*[data-id="remixIdeSidePanel"]') .assert.containsText('*[data-id="sidePanelSwapitTitle"]', 'DEPLOY & RUN TRANSACTIONS') - .validateValueInput('#value', '0000', '0') - .validateValueInput('#value', '', '0') - .validateValueInput('#value', 'dragon', '0') + .validateValueInput('*[data-id="dandrValue"]', '999', '999') + .validateValueInput('*[data-id="dandrValue"]', '0000', '0') + .validateValueInput('*[data-id="dandrValue"]', '1.3', '0') // no decimal + // .validateValueInput('*[data-id="dandrValue"]', 'dragon', '0') // only numbers }, 'Should sign message using account key #group2': function (browser: NightwatchBrowser) { diff --git a/libs/remix-ui/run-tab/src/lib/components/value.tsx b/libs/remix-ui/run-tab/src/lib/components/value.tsx index 96837e7af2..1dc2080eee 100644 --- a/libs/remix-ui/run-tab/src/lib/components/value.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/value.tsx @@ -6,49 +6,43 @@ import {CustomTooltip, isNumeric} from '@remix-ui/helper' import {ValueProps} from '../types' export function ValueUI(props: ValueProps) { - const [sendValue, setSendValue] = useState(props.sendValue) - const inputValue = useRef({} as HTMLInputElement) + const inputValue = useRef({} as HTMLInputElement) useEffect(() => { - sendValue !== props.sendValue && props.setSendValue(sendValue) - }, [sendValue]) - - useEffect(() => { - if(props.sendValue !== sendValue) { - setSendValue(props.sendValue) + if (props.sendValue !== inputValue.current.value) { + inputValue.current.value = props.sendValue } },[props.sendValue]) - const validateInputKey = (e) => { - // preventing not numeric keys - // preventing 000 case - if (!isNumeric(e.key) || (e.key === '0' && !parseInt(inputValue.current.value) && inputValue.current.value.length > 0)) { - e.preventDefault() - } - } - const validateValue = (e) => { + console.log('validateValue', e.target.value) const value = e.target.value if (!value) { // assign 0 if given value is // - empty - return setSendValue('0') + inputValue.current.value = '0' + props.setSendValue('0') + return } let v try { v = new BN(value, 10) - setSendValue(v.toString(10)) + props.setSendValue(v.toString(10)) } catch (e) { // assign 0 if given value is // - not valid (for ex 4345-54) // - contains only '0's (for ex 0000) copy past or edit - setSendValue('0') + inputValue.current.value = '0' + props.setSendValue('0') } // if giveen value is negative(possible with copy-pasting) set to 0 - if (v.lt(0)) setSendValue('0') + if (v.lt(0)) { + inputValue.current.value = '0' + props.setSendValue('0') + } } return ( @@ -67,9 +61,8 @@ export function ValueUI(props: ValueProps) { className="form-control udapp_gasNval udapp_col2" id="value" data-id="dandrValue" - onKeyPress={validateInputKey} onChange={validateValue} - value={sendValue} + value={props.sendValue} />