super(props)
this.submitWithErrors = this.submitWithErrors.bind(this)
+ this.state = {
+ checked: false,
+ key: null
+ }
}
submitWithErrors(data) {
return new Promise((resolve, reject) => {
- this.props.submitForm(data)
- .catch((err) => reject({_error: err}))
+ this.props.submitForm(Object.assign({}, data, {
+ xprv: this.state.key,
+ index: 5000
+ })).catch((err) => reject({_error: err}))
})
}
+ handleCheckedChange(e) {
+ this.setState({
+ checked: e.target.checked
+ })
+ }
+
+ handleFileChange(event) {
+ const files = event.target.files
+ if (files.length <= 0) {
+ this.setState({key: null})
+ return
+ }
+
+ const fileReader = new FileReader()
+ fileReader.onload = fileLoadedEvent => {
+ this.setState({
+ key: fileLoadedEvent.target.result
+ })
+ }
+ fileReader.readAsText(files[0], 'UTF-8')
+ }
+
render() {
const {
- fields: { alias, password },
+ fields: { alias, password, accountAlias },
error,
handleSubmit,
submitting
<FormSection title='Key Information'>
<TextField title='Alias' placeholder='Alias' fieldProps={alias} autoFocus={true} />
{/*<TextField title='Password' placeholder='Password' fieldProps={password} autoFocus={false} type={'password'} />*/}
+ <div>
+ <input type='checkbox' id='private_key_file_input'
+ checked={this.state.import}
+ onChange={this.handleCheckedChange.bind(this)}/>
+ <label htmlFor='private_key_file_input'
+ style={{'marginLeft': '5px', 'userSelect': 'none'}}>
+ import from file
+ </label>
+ </div>
+ {
+ this.state.checked &&
+ <TextField title='Account alias' placeholder='Account alias' fieldProps={accountAlias}></TextField>
+ }
+ {
+ this.state.checked &&
+ <input type='file' style={{'display': 'flex', 'alignItems': 'center', 'fontSize': '12px'}}
+ onChange={this.handleFileChange.bind(this)}/>
+ }
</FormSection>
</FormContainer>
)
}
}
-const fields = [ 'alias', 'password' ]
+const fields = [ 'alias', 'password', 'accountAlias' ]
export default BaseNew.connect(
BaseNew.mapStateToProps('key'),
BaseNew.mapDispatchToProps('key'),
if (!values.alias) {
errors.alias = 'Key alias is required'
}
+ if (!values.accountAlias) {
+ errors.accountAlias = 'Account alias is required'
+ }
return errors
}
return {
create: (params, cb) => {
let body = Object.assign({ clientToken: uuid.v4() }, params, {password: '123456'})
+ const uri = body.xprv ? '/import-private-key' : '/create-key'
+
+ debugger
return shared.tryCallback(
- client.request('/create-key', body).then(data => data),
+ client.request(uri, body).then(data => data),
cb
)
},