-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented manual broadcasting of custom json operations
- Loading branch information
Showing
7 changed files
with
292 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// @flow | ||
import React, { Component } from 'react'; | ||
import { Grid, Header, Message, Segment, Select, Table } from 'semantic-ui-react'; | ||
|
||
import { Form, Input } from 'formsy-semantic-ui-react'; | ||
|
||
import AccountName from '../global/AccountName'; | ||
|
||
export default class AccountsCustomJSON extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
account: props.keys.names[0], | ||
id: '', | ||
json: '', | ||
message: false | ||
} | ||
} | ||
|
||
resetState(extraState) { | ||
this.setState(Object.assign({}, { | ||
id: '', | ||
json: '' | ||
}, extraState)) | ||
} | ||
|
||
|
||
handleIdChange = (e: SyntheticEvent, { value }: { value: any }) => { | ||
this.setState({ | ||
id: value | ||
}) | ||
} | ||
|
||
handleJsonChange = (e: SyntheticEvent, { value }: { value: any }) => { | ||
this.setState({ | ||
json: value.trim() | ||
}) | ||
} | ||
|
||
handleAccountChange = (e: SyntheticEvent, { value }: { value: any }) => { | ||
this.setState({ | ||
account: value | ||
}) | ||
} | ||
|
||
onValidSubmit = ( | ||
e: SyntheticEvent | ||
) => { | ||
const { account, id, json } = this.state | ||
this.setState({message: false}) | ||
this.props.actions.useKey('customJson', { account, id, json }, this.props.keys.permissions[account]); | ||
} | ||
|
||
componentWillReceiveProps = (nextProps) => { | ||
if (nextProps.processing.account_custom_json_resolved) { | ||
nextProps.actions.customJsonCompleted(); | ||
this.resetState({ | ||
'message': 'Your transaction was successfully broadcast.' | ||
}); | ||
} | ||
} | ||
|
||
render() { | ||
const { | ||
account_custom_json_error, | ||
account_custom_json_pending, | ||
account_custom_json_resolved | ||
} = this.props.processing; | ||
const keys = this.props.keys; | ||
const availableFrom = keys.names.map((name) => { | ||
const hasPermission = (keys.permissions[name].type === 'active' || keys.permissions[name].type === 'owner'); | ||
return hasPermission ? { | ||
key: name, | ||
text: name, | ||
value: name | ||
} : { | ||
key: name, | ||
disabled: true, | ||
text: name + ' (unavailable - active/owner key not loaded)' | ||
}; | ||
}); | ||
let message = false | ||
if(this.state.message) { | ||
message = ( | ||
<Message | ||
success | ||
header="Operation Complete" | ||
content={this.state.message} | ||
/> | ||
) | ||
} | ||
return ( | ||
<Segment basic padded> | ||
<Header> | ||
<Header.Subheader> | ||
Broadcast a Custom JSON operation to the Steem blockchain. | ||
</Header.Subheader> | ||
</Header> | ||
{message} | ||
<Form | ||
onValidSubmit={this.onValidSubmit} | ||
error={account_custom_json_error} | ||
loading={account_custom_json_pending} | ||
> | ||
<Form.Field | ||
control={Select} | ||
value={this.state.account} | ||
name="from" | ||
label="Select an account to broadcast with" | ||
options={availableFrom} | ||
placeholder="Sending Account..." | ||
onChange={this.handleAccountChange} | ||
/> | ||
<Form.Input | ||
label="ID" | ||
name="id" | ||
value={this.state.id} | ||
onChange={this.handleIdChange} | ||
placeholder="" | ||
/> | ||
<Form.TextArea | ||
label="JSON" | ||
name="json" | ||
value={this.state.json} | ||
onChange={this.handleJsonChange} | ||
placeholder="" | ||
/> | ||
<Message | ||
error | ||
header="Operation Error" | ||
content={account_custom_json_error} | ||
/> | ||
<Form.Button | ||
color='blue' | ||
content='Broadcast' | ||
disabled={account_custom_json_pending} | ||
/> | ||
</Form> | ||
</Segment> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// @flow | ||
import React, { Component } from 'react'; | ||
import { bindActionCreators } from 'redux'; | ||
import { Redirect } from 'react-router'; | ||
import { connect } from 'react-redux'; | ||
import { Button, Header, Icon, Menu, Modal, Segment, Table } from 'semantic-ui-react'; | ||
|
||
import AccountsCustomJson from '../components/Accounts/CustomJSON.js'; | ||
import * as AccountActions from '../actions/account'; | ||
import * as KeyActions from '../actions/keys'; | ||
import * as ProcessingActions from '../actions/processing'; | ||
import MenuBar from './MenuBar'; | ||
import ContentBar from '../components/ContentBar'; | ||
|
||
class AccountsPage extends Component { | ||
|
||
state = { | ||
activeItem: 'custom_json' | ||
}; | ||
|
||
handleItemClick = (e, { name }) => this.setState({ activeItem: name }) | ||
|
||
render() { | ||
if (!this.props.keys.isUser) { | ||
return <Redirect to="/" />; | ||
} | ||
const { activeItem } = this.state; | ||
let activeTab = <AccountsCustomJson {...this.props} />; | ||
switch (activeItem) { | ||
default: { | ||
activeTab = <AccountsCustomJson {...this.props} />; | ||
break; | ||
} | ||
} | ||
return ( | ||
<ContentBar> | ||
<Segment basic padded attached secondary> | ||
<Header> | ||
<Icon name="lab" /> | ||
<Header.Content> | ||
Advanced Operations | ||
<Header.Subheader> | ||
This section can be used to perform more advanced operations using the loaded accounts. | ||
</Header.Subheader> | ||
</Header.Content> | ||
</Header> | ||
</Segment> | ||
<Menu tabular attached> | ||
<Menu.Item | ||
name="custom_json" | ||
icon="lock" | ||
content="Custom JSON" | ||
active={activeItem === 'custom_json'} | ||
onClick={this.handleItemClick} | ||
/> | ||
</Menu> | ||
{activeTab} | ||
<MenuBar /> | ||
</ContentBar> | ||
); | ||
} | ||
} | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
account: state.account, | ||
keys: state.keys, | ||
processing: state.processing, | ||
steem: state.steem | ||
}; | ||
} | ||
|
||
function mapDispatchToProps(dispatch) { | ||
return { | ||
actions: bindActionCreators({ | ||
...AccountActions, | ||
...KeyActions, | ||
...ProcessingActions, | ||
}, dispatch) | ||
}; | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(AccountsPage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters