disabling of import

This commit is contained in:
Victor Baranov 2018-12-07 11:35:25 +03:00
parent a9d19b4044
commit 848e4c81ee
1 changed files with 18 additions and 0 deletions

View File

@ -14,6 +14,7 @@ class ContractImportView extends Component {
contractAddr: '', contractAddr: '',
abi: '', abi: '',
abiInputDisabled: false, abiInputDisabled: false,
importDisabled: true,
web3, web3,
} }
} }
@ -43,9 +44,11 @@ class ContractImportView extends Component {
this.setState({ this.setState({
abi, abi,
abiInputDisabled: true, abiInputDisabled: true,
importDisabled: false,
}) })
} }
} catch (e) { } catch (e) {
this.clearAbi()
log.debug('ABI can not be parsed') log.debug('ABI can not be parsed')
} }
} }
@ -85,6 +88,7 @@ class ContractImportView extends Component {
onKeyPress={(e) => this.createKeyringOnEnter(e)} onKeyPress={(e) => this.createKeyringOnEnter(e)}
/> />
<button <button
disabled={this.state.importDisabled}
onClick={(e) => this.createNewKeychain(e)} onClick={(e) => this.createNewKeychain(e)}
style={{ margin: '20px' }} style={{ margin: '20px' }}
>Import</button> >Import</button>
@ -96,6 +100,7 @@ class ContractImportView extends Component {
autodetectContractAbi = () => { autodetectContractAbi = () => {
const { contractAddr, web3 } = this.state const { contractAddr, web3 } = this.state
if (!contractAddr || !web3.isAddress(contractAddr)) { if (!contractAddr || !web3.isAddress(contractAddr)) {
this.clearAbi()
return return
} }
@ -112,6 +117,7 @@ class ContractImportView extends Component {
this.abiOnChange(responseJson && responseJson.result) this.abiOnChange(responseJson && responseJson.result)
}) })
.catch((e) => { .catch((e) => {
this.clearAbi()
log.debug(e) log.debug(e)
}) })
} }
@ -142,11 +148,13 @@ class ContractImportView extends Component {
const { contractAddr, web3 } = this.state const { contractAddr, web3 } = this.state
if (!contractAddr || !web3.isAddress(contractAddr)) { if (!contractAddr || !web3.isAddress(contractAddr)) {
this.clearAbi()
return this.props.displayWarning('Invalid contract address') return this.props.displayWarning('Invalid contract address')
} }
const contractAddrCode = await this.getContractCode() const contractAddrCode = await this.getContractCode()
if (contractAddrCode === '0x') { if (contractAddrCode === '0x') {
this.clearAbi()
return this.props.displayWarning('This is not a contract address') return this.props.displayWarning('This is not a contract address')
} }
@ -154,10 +162,12 @@ class ContractImportView extends Component {
try { try {
abi = JSON.parse(this.state.abi) abi = JSON.parse(this.state.abi)
} catch (e) { } catch (e) {
this.clearAbi()
this.props.displayWarning('Invalid ABI') this.props.displayWarning('Invalid ABI')
} }
if (!abi) { if (!abi) {
this.clearAbi()
return this.props.displayWarning('Invalid contract ABI') return this.props.displayWarning('Invalid contract ABI')
} }
@ -188,6 +198,14 @@ class ContractImportView extends Component {
} }
} }
clearAbi () {
this.setState({
abi: '',
abiInputDisabled: false,
importDisabled: true
})
}
} }
function mapStateToProps (state) { function mapStateToProps (state) {