From 5b769581040a05301566b68593eb01b99af74a54 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Thu, 26 Nov 2020 17:31:07 +0100 Subject: [PATCH] at address is disabled when no contract compiled --- .../src/tests/signingMessage.test.ts | 2 +- .../src/app/tabs/runTab/contractDropdown.js | 83 +++++++++++++++---- 2 files changed, 68 insertions(+), 17 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/signingMessage.test.ts b/apps/remix-ide-e2e/src/tests/signingMessage.test.ts index 28a88d3d22..e10760a35e 100644 --- a/apps/remix-ide-e2e/src/tests/signingMessage.test.ts +++ b/apps/remix-ide-e2e/src/tests/signingMessage.test.ts @@ -27,7 +27,7 @@ module.exports = { }) .addFile('signMassage.sol', sources[0]['browser/signMassage.sol']) .openFile('browser/signMassage.sol') - .pause(5000) + .pause(10000) .selectContract('ECVerify') .createContract('') .clickInstance(0) diff --git a/apps/remix-ide/src/app/tabs/runTab/contractDropdown.js b/apps/remix-ide/src/app/tabs/runTab/contractDropdown.js index 849128d5da..6afa3aa8b6 100644 --- a/apps/remix-ide/src/app/tabs/runTab/contractDropdown.js +++ b/apps/remix-ide/src/app/tabs/runTab/contractDropdown.js @@ -21,6 +21,7 @@ class ContractDropdownUI { this.ipfsCheckedState = false this.exEnvironment = blockchain.getProvider() this.listenToContextChange() + this.loadType = 'other' } listenToEvents () { @@ -29,13 +30,14 @@ class ContractDropdownUI { var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`) contractNames.innerHTML = '' if (success) { - this.selectContractNames.removeAttribute('disabled') + this.enableContractNames(true) this.dropdownLogic.getCompiledContracts(compiler, compilerFullName).forEach((contract) => { contractNames.appendChild(yo``) }) } else { - this.selectContractNames.setAttribute('disabled', true) + this.enableContractNames(false, 'sol') } + this.enableAtAddress(success) this.setInputParamsPlaceHolder() if (success) { @@ -80,14 +82,42 @@ class ContractDropdownUI { window.localStorage.setItem(`ipfs/${this.exEnvironment}/${this.networkName}`, this.ipfsCheckedState) } + enableContractNames (enable) { + if (enable) { + this.selectContractNames.removeAttribute('disabled') + this.selectContractNames.setAttribute('title', 'Select contract for Deploy or At Address.') + } else { + this.selectContractNames.setAttribute('disabled', true) + if (this.loadType === 'sol') { + this.selectContractNames.setAttribute('title', '⚠ Select and compile *.sol file to deploy or access a contract.') + } else { + this.selectContractNames.setAttribute('title', '⚠ Selected *.abi file allows accessing contracts, select and compile *.sol file to deploy and access one.') + } + } + } + + enableAtAddress (enable) { + if (enable) { + if (this.atAddressButtonInput.value === '') return + this.atAddress.removeAttribute('disabled') + this.atAddress.setAttribute('title', 'Interact with the given contract.') + } else { + this.atAddress.setAttribute('disabled', true) + if (this.atAddressButtonInput.value === '') { + this.atAddress.setAttribute('title', '⚠ Compile *.sol file or select *.abi file & then enter the address of deployed contract.') + } else { + this.atAddress.setAttribute('title', '⚠ Compile *.sol file or select *.abi file.') + } + } + } + render () { this.compFails = yo`` - var info = yo`` - this.atAddress = yo`` + this.atAddress = yo`` this.atAddressButtonInput = yo`` - this.selectContractNames = yo`` - + this.selectContractNames = yo`` if (this.exEnvironment === 'vm') this.networkName = 'VM' + this.enableAtAddress(false) const savedConfig = window.localStorage.getItem(`ipfs/${this.exEnvironment}/${this.networkName}`) this.ipfsCheckedState = savedConfig === 'true' ? true : false // eslint-disable-line @@ -119,11 +149,11 @@ class ContractDropdownUI { this.createPanel = yo`
` this.orLabel = yo`
or
` - const el = yo` + const contractNamesContainer = yo`
- ${this.selectContractNames} ${this.compFails} ${info} + ${this.selectContractNames} ${this.compFails}
${this.createPanel} @@ -137,32 +167,53 @@ class ContractDropdownUI { ` this.selectContractNames.addEventListener('change', this.setInputParamsPlaceHolder.bind(this)) this.setInputParamsPlaceHolder() - if (!this.el) { - this.el = el + if (!this.contractNamesContainer) { + this.contractNamesContainer = contractNamesContainer } - return el + return contractNamesContainer } atAddressChanged (event) { if (!this.atAddressButtonInput.value) { - this.atAddress.setAttribute('disabled', 'true') + this.enableAtAddress(false) } else { - this.atAddress.removeAttribute('disabled') + if ((this.selectContractNames && !this.selectContractNames.getAttribute('disabled') && this.loadType === 'sol') || + this.loadType === 'abi') { + this.enableAtAddress(true) + } else { + this.enableAtAddress(false) + } } } changeCurrentFile (currentFile) { if (!document.querySelector(`.${css.contractNames}`)) return - var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`) if (/.(.abi)$/.exec(currentFile)) { this.createPanel.style.display = 'none' this.orLabel.style.display = 'none' this.compFails.style.display = 'none' - contractNames.appendChild(yo``) - this.selectContractNames.setAttribute('disabled', true) + this.loadType = 'abi' + this.contractNamesContainer.style.display = 'block' + while (this.selectContractNames.options.length > 0) this.selectContractNames.remove(0) + this.selectContractNames.appendChild(yo``) + this.enableContractNames(true) + this.enableAtAddress(true) } else if (/.(.sol)$/.exec(currentFile)) { this.createPanel.style.display = 'block' this.orLabel.style.display = 'block' + this.contractNamesContainer.style.display = 'block' + this.loadType = 'sol' + while (this.selectContractNames.options.length > 0) this.selectContractNames.remove(0) + this.enableContractNames(false) + this.enableAtAddress(false) + } else { + this.loadType = 'other' + this.createPanel.style.display = 'none' + this.orLabel.style.display = 'none' + this.compFails.style.display = 'none' + this.contractNamesContainer.style.display = 'none' + this.enableContractNames(false) + this.enableAtAddress(false) } }