Skip to content

Commit

Permalink
Allow usage of different permissions in custom_json ops
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed May 26, 2019
1 parent e100d38 commit 457fbec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
10 changes: 8 additions & 2 deletions app/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,17 @@ export function cancelWithdrawVesting(wif, params) {

export function customJson(wif, params) {
return (dispatch: () => void) => {
const { account, id, json } = params
const { account, id, json, permission } = params
let auths = []
let postingAuths = [account]
if (permission === 'active') {
auths = [account]
postingAuths = []
}
dispatch({
type: ACCOUNT_CUSTOM_JSON_STARTED
})
steem.broadcast.customJson(wif, [], [account], id, json, function(err, result) {
steem.broadcast.customJson(wif, auths, postingAuths, id, json, function(err, result) {
if(result) {
dispatch({
type: ACCOUNT_CUSTOM_JSON_RESOLVED
Expand Down
28 changes: 25 additions & 3 deletions app/components/Accounts/CustomJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default class AccountsCustomJSON extends Component {
account: props.keys.names[0],
id: '',
json: '',
message: false
message: false,
permission: 'posting',
}
}

Expand Down Expand Up @@ -43,12 +44,18 @@ export default class AccountsCustomJSON extends Component {
})
}

handlePermissionChange = (e: SyntheticEvent, { value }: { value: any }) => {
this.setState({
permission: value
})
}

onValidSubmit = (
e: SyntheticEvent
) => {
const { account, id, json } = this.state
const { account, id, json, permission } = this.state
this.setState({message: false})
this.props.actions.useKey('customJson', { account, id, json }, this.props.keys.permissions[account]);
this.props.actions.useKey('customJson', { account, id, json, permission }, this.props.keys.permissions[account]);
}

componentWillReceiveProps = (nextProps) => {
Expand Down Expand Up @@ -79,6 +86,11 @@ export default class AccountsCustomJSON extends Component {
text: name + ' (unavailable - active/owner key not loaded)'
};
});
const availablePermissions = ['active', 'posting'].map((permission) => ({
key: permission,
text: permission,
value: permission
}))
let message = false
if(this.state.message) {
message = (
Expand All @@ -89,6 +101,7 @@ export default class AccountsCustomJSON extends Component {
/>
)
}
console.log(this.state)
return (
<Segment basic padded>
<Header>
Expand All @@ -111,6 +124,15 @@ export default class AccountsCustomJSON extends Component {
placeholder="Sending Account..."
onChange={this.handleAccountChange}
/>
<Form.Field
control={Select}
value={this.state.permission}
name="permission"
label="Select a permission to use"
options={availablePermissions}
placeholder="Permission"
onChange={this.handlePermissionChange}
/>
<Form.Input
label="ID"
name="id"
Expand Down

0 comments on commit 457fbec

Please sign in to comment.