diff --git a/src/components/VerifyContract.vue b/src/components/VerifyContract.vue index e5c41418..215ec586 100644 --- a/src/components/VerifyContract.vue +++ b/src/components/VerifyContract.vue @@ -34,7 +34,7 @@ form-row(v-bind='formFields.ABI_ENCODED_ARGUMENTS') ctrl-radio-grp.frow(name='encoded' @change='(value)=>abiEncodedArgs=value' :selected='abiEncodedArgs') form-row - button.brand.big(name="submit") + button.brand.big(name="submit" :disabled="errors.length > 0") span Verify form.flex(v-if='method === verifyMethods.SOLIDITY_SOURCE_FILE' @submit.prevent='submit') @@ -94,7 +94,7 @@ form-row(v-bind='formFields.LIB_ADDRESS') input(type='text' v-model='lib.address' v-bind='formFields.LIB_ADDRESS.input' ) form-row - button.brand.big(name="submit") + button.brand.big(name="submit" :disabled="errors.length > 0") span Verify //-button.btn.big(name="submit" @click.passive='resetForm') span Reset @@ -198,7 +198,8 @@ export default { errors: [], timer: undefined, method: VERIFY_METHODS.SOLIDITY_SOURCE_FILE, - sources: undefined + sources: undefined, + json: undefined } }, created () { @@ -383,18 +384,22 @@ export default { this.clearErrors() this.sources = undefined this.method = method + this.files = [] }, handleStandardJsonInput (json) { this.errors.pop() + this.json = json if (json[0]) { try { const { sources, settings } = JSON.parse(json[0].contents) - if (!sources) this.addError('Invalid JSON, missing sources') if (!settings) this.addError('Invalid JSON, missing settings') - this.settings = settings this.sources = sources + const fileName = json[0].name.replace('.json', '') + if (this.name && fileName !== this.name) { + this.addError(messages.JSON_INPUT_INVALID(this.name)) + } } catch (error) { this.addError(error) } @@ -478,8 +483,36 @@ export default { changeName (name) { this.name = name.trim() this.inputErrors.delete('name') + this.clearErrors() + if (this.files.length > 0) { + const hasMatchingFile = this.files.some(file => file.name.replace('.sol', '') === this.name) + if (!hasMatchingFile) { + this.errors.push(messages.CONTRACT_NAME_INVALID(this.name)) + } else { + this.clearErrors() + } + } + if (this.json && this.json[0]) { + const fileName = this.json[0].name.replace('.json', '') + if (fileName !== this.name) { + this.addError(messages.JSON_INPUT_INVALID(this.name)) + } + } + }, + verifyContractName () { + if (this.name && this.files.length > 0) { + const hasMatchingFile = this.files.some(file => file.name.replace('.sol', '') === this.name) + if (!hasMatchingFile) { + this.errors.push(messages.CONTRACT_NAME_INVALID(this.name)) + } + } + if (this.name && this.json && this.json[0]) { + const fileName = this.json[0].name.replace('.json', '') + if (fileName !== this.name) { + this.addError(messages.JSON_INPUT_INVALID(this.name)) + } + } }, - changeAddress (address) { this.address = address.trim() this.reset() @@ -489,12 +522,14 @@ export default { } }, changeVersion (version) { + console.log('version in change is', version) this.version = version this.inputErrors.delete('version') this.errors.pop() if (!this.isSupportedSolidityVersion()) { this.errors.push(messages.NOT_SUPPORTED_SOLIDITY_VERSION_ERROR(version)) } + this.verifyContractName() }, changeAllVersions (version) { this.showAllVersions = version @@ -520,6 +555,15 @@ export default { updateFiles (files) { this.files = files this.inputErrors.delete('file') + this.clearErrors() + if (this.name && files.length > 0) { + const hasMatchingFile = files.some(file => file.name.replace('.sol', '') === this.name) + if (!hasMatchingFile) { + this.errors.push(messages.CONTRACT_NAME_INVALID(this.name)) + } else { + this.clearErrors() + } + } }, buildsList (builds) { return builds.concat().reverse().reduce((v, a, i) => { diff --git a/src/config/texts/verifyContract.js b/src/config/texts/verifyContract.js index 0163aa6a..8d5e736a 100644 --- a/src/config/texts/verifyContract.js +++ b/src/config/texts/verifyContract.js @@ -16,7 +16,9 @@ export const messages = { REQUEST_VERIFICATION: 'Requesting verification', SHOW_RESULT: 'Go to contract page', VERIFIER_DATA_ERROR: 'Missing contract verifier data', - NOT_SUPPORTED_SOLIDITY_VERSION_ERROR: (value) => `You have selected version ${value} which is not supported. Please, try another one.` + NOT_SUPPORTED_SOLIDITY_VERSION_ERROR: (value) => `You have selected version ${value} which is not supported. Please, try another one.`, + CONTRACT_NAME_INVALID: (contractName) => `No file matches the Contract Name (${contractName}). Please ensure one of the uploaded files has the correct name.`, + JSON_INPUT_INVALID: (contractName) => `The JSON input does not match the contract name (${contractName}). Please ensure the JSON input is correct.` } export const formFields = { diff --git a/src/styles/_page.scss b/src/styles/_page.scss index 3fe196f9..d0839502 100644 --- a/src/styles/_page.scss +++ b/src/styles/_page.scss @@ -390,6 +390,10 @@ padding: 12px 30px; color: $white_100; border-radius: 8px; + &:disabled { + opacity: 0.5; + cursor: not-allowed; + } } } }