Skip to content

Commit

Permalink
Better support for permission placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Apr 9, 2020
1 parent 0cb3c6c commit a1843fa
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 47 deletions.
51 changes: 39 additions & 12 deletions src/components/form/authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ import ReactJson from 'react-json-view';
import { find } from 'lodash';

class FormAuthorization extends Component {
getInput = (field, idx, canMatchSigner = true) => {
getInput = (field, idx, canMatchSignerAccount = true, canMatchSignerPermission = true) => {
const {
aliases,
authorization,
fieldsMatchSigner,
fieldsMatchSignerAccount,
fieldsMatchSignerPermission,
onChange,
onChangeAuthorizationMatchSigner,
onChangeAuthorizationMatchSignerAccount,
onChangeAuthorizationMatchSignerPermission,
values,
} = this.props;
const name = field;
const isMatchingSigner = !!(fieldsMatchSigner[`authorization-${name}`]);
const isTemplated = (isMatchingSigner);
const isMatchingSignerAccount = !!(fieldsMatchSignerAccount[`authorization-${name}`]);
const isMatchingSignerPermission = !!(fieldsMatchSignerPermission[`authorization-${name}`]);
let value = authorization[field];
let defaultInput = (
<Form.Input
Expand All @@ -35,13 +37,25 @@ class FormAuthorization extends Component {
defaultValue={(value instanceof Object) ? JSON.stringify(value) : value}
/>
);
if (isTemplated) {
console.log(isMatchingSignerAccount, isMatchingSignerPermission, name)
if (isMatchingSignerAccount && name === 'actor') {
defaultInput = (
<Form.Field>
<label>{name}</label>
<Form.Input
disabled
value="Matching Transaction Signer Account Name"
/>
</Form.Field>
)
}
if (isMatchingSignerPermission && name === 'permission') {
defaultInput = (
<Form.Field>
<label>{name}</label>
<Form.Input
disabled
value={(isMatchingSigner) ? 'Matching Transaction Signer' : 'Prompting Transaction Signer'}
value="Matching Transaction Signer Permission"
/>
</Form.Field>
)
Expand All @@ -50,14 +64,27 @@ class FormAuthorization extends Component {
<Segment attached key={name} secondary={!!(idx % 2)}>
<Form.Field key={name}>
{defaultInput}
{(canMatchSigner)
{(canMatchSignerAccount && name === 'actor')
? (
<React.Fragment>
<Form.Checkbox
checked={fieldsMatchSignerAccount[`authorization-${name}`]}
label="Match to Signer Account Name"
name={name}
onChange={onChangeAuthorizationMatchSignerAccount}
/>
</React.Fragment>
)
: false
}
{(canMatchSignerPermission && name === 'permission')
? (
<React.Fragment>
<Form.Checkbox
checked={fieldsMatchSigner[`authorization-${name}`]}
label="Match to Signer"
checked={fieldsMatchSignerPermission[`authorization-${name}`]}
label="Match to Signer Permission"
name={name}
onChange={onChangeAuthorizationMatchSigner}
onChange={onChangeAuthorizationMatchSignerPermission}
/>
</React.Fragment>
)
Expand All @@ -72,7 +99,7 @@ class FormAuthorization extends Component {
authorization,
billFirstAuthorizer,
fields,
fieldsMatchSigner,
fieldsMatchSignerAccount,
greymassnoop,
onChange,
onChangeAuthorizationMatchSigner,
Expand Down
28 changes: 21 additions & 7 deletions src/components/form/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ class FormFields extends Component {
getInput = (field, idx) => {
const {
aliases,
fieldsMatchSigner,
fieldsMatchSignerAccount,
fieldsMatchSignerPermission,
onChange,
onChangeMatchSigner,
values,
} = this.props;
const { name } = field;
let { type } = field;
const alias = find(aliases, { new_type_name: type });
const isMatchingSigner = !!(fieldsMatchSigner[name]);
const isTemplated = (isMatchingSigner);
const isMatchingSignerAccount = !!(fieldsMatchSignerAccount[name]);
const isMatchingSignerPermission = !!(fieldsMatchSignerPermission[name]);
const isTemplated = (isMatchingSignerAccount );
const label = `${name} [${type}]${(alias) ? `, extending [${alias.type}]` : ''}`;
let fieldType = 'string';
let value = this.formatValue(type, values[name]);
Expand Down Expand Up @@ -72,17 +74,29 @@ class FormFields extends Component {
/>
);
}
if (isTemplated) {
if (isMatchingSignerAccount) {
defaultInput = (
<Form.Field>
<label>{label}</label>
<Form.Input
disabled
value={(isMatchingSigner) ? 'Matching Transaction Signer' : 'Prompting Transaction Signer'}
value='Matching Transaction Signer Account Name'
/>
</Form.Field>
)
}
if (isMatchingSignerPermission) {
defaultInput = (
<Form.Field>
<label>{label}</label>
<Form.Input
disabled
value='Matching Transaction Signer Permission'
/>
</Form.Field>
)
}
console.log(type, alias)
return (
<Segment attached key={name} secondary={!!(idx % 2)}>
<Form.Field key={name}>
Expand All @@ -91,8 +105,8 @@ class FormFields extends Component {
? (
<React.Fragment>
<Form.Checkbox
checked={fieldsMatchSigner[name]}
label="Match to Signer"
checked={fieldsMatchSignerAccount[name]}
label="Match to Signer Account Name"
name={name}
onChange={onChangeMatchSigner}
/>
Expand Down
82 changes: 54 additions & 28 deletions src/containers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const initialState = {
action: '',
authorization: {
actor: "............1",
permission: "............1",
permission: "............2",
},
billFirstAuthorizer: false,
blockchain: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
Expand All @@ -49,8 +49,10 @@ const initialState = {
contract: '',
decoded: {},
fields: {},
fieldsMatchSigner: {
fieldsMatchSignerAccount: {
'authorization-actor': true,
},
fieldsMatchSignerPermission: {
'authorization-permission': true,
},
fieldsPromptSigner: {},
Expand All @@ -76,7 +78,7 @@ const chainAliases = [
['MEETONE','cfe6486a83bad4962f232d48003b1824ab5665c36778141034d75e57b956e422'], // 0x07
['INSIGHTS','b042025541e25a472bffde2d62edd457b7e70cee943412b1ea0f044f88591664'], // 0x08
['BEOS','b912d19a6abd2b1b05611ae5be473355d64d95aeff0c09bedc8c166cd6468fe4'], // 0x09
['WAX', '1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4'],
['WAX', '1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4'], // 0x10
['WAXTESTNET', 'f16b1833c747c43682f4386fca9cbb327929334a762755ebec17f6f23c9b8a12'],
['FIO', '21dcae42c0182200e93f954a074011f9048a7624c6fe81d3c9541a614a88bd1c'],
['FIOTESTNET', 'b20901380af44ef59c5918439a1f9a41d83669020319a80574b804a5f95cbd7e'],
Expand Down Expand Up @@ -215,17 +217,17 @@ class IndexContainer extends Component {
onChangeMatchSigner = (e, { name }) => {
const {
fields,
fieldsMatchSigner,
fieldsMatchSignerAccount,
fieldsPromptSigner
} = this.state;
const newValue = !(fieldsMatchSigner[name] || false)
const newValue = !(fieldsMatchSignerAccount[name] || false)
const newState = {
// Set the field to the placeholder value
fields: Object.assign({}, fields, {
[name]: (newValue) ? '............1' : ''
}),
// Set the boolean value
fieldsMatchSigner: Object.assign({}, fieldsMatchSigner, {
fieldsMatchSignerAccount: Object.assign({}, fieldsMatchSignerAccount, {
[name]: newValue
})
}
Expand All @@ -242,7 +244,7 @@ class IndexContainer extends Component {
onChangePromptSigner = (e, { name, checked }) => {
const {
fields,
fieldsMatchSigner,
fieldsMatchSignerAccount,
fieldsPromptSigner
} = this.state;
const newValue = !(fieldsPromptSigner[name] || false)
Expand All @@ -254,8 +256,8 @@ class IndexContainer extends Component {
[name]: newValue
})
}
if (fieldsMatchSigner[name]) {
newState['fieldsMatchSigner'] = Object.assign({}, fieldsMatchSigner, {
if (fieldsMatchSignerAccount[name]) {
newState['fieldsMatchSignerAccount'] = Object.assign({}, fieldsMatchSignerAccount, {
[name]: false
});
}
Expand All @@ -272,27 +274,45 @@ class IndexContainer extends Component {
});
}

onChangeAuthorizationMatchSigner = (e, { name }) => {
onChangeAuthorizationMatchSignerAccount = (e, { name }) => {
const {
authorization,
fieldsMatchSigner,
fieldsMatchSignerAccount,
fieldsPromptSigner
} = this.state;
const newValue = !(fieldsMatchSigner[`authorization-${name}`] || false)
const placeholder = (name === 'permission') ? '............2' : '............1';
const newValue = !(fieldsMatchSignerAccount[`authorization-${name}`] || false)
const placeholder = '............1';
const newState = {
// Set the field to the placeholder value
authorization: Object.assign({}, authorization, {
[name]: (newValue) ? placeholder : ''
}),
// Set the boolean value
fieldsMatchSigner: Object.assign({}, fieldsMatchSigner, {
fieldsMatchSignerAccount: Object.assign({}, fieldsMatchSignerAccount, {
[`authorization-${name}`]: newValue
})
}
if (fieldsPromptSigner[name]) {
newState['fieldsPromptSigner'] = Object.assign({}, fieldsPromptSigner, {
[`authorization-${name}`]: false
this.setState(newState);
e.preventDefault();
return false;
}

onChangeAuthorizationMatchSignerPermission = (e, { name }) => {
const {
authorization,
fieldsMatchSignerPermission,
fieldsPromptSigner
} = this.state;
const newValue = !(fieldsMatchSignerPermission[`authorization-${name}`] || false)
const placeholder = '............2';
const newState = {
// Set the field to the placeholder value
authorization: Object.assign({}, authorization, {
[name]: (newValue) ? placeholder : ''
}),
// Set the boolean value
fieldsMatchSignerPermission: Object.assign({}, fieldsMatchSignerPermission, {
[`authorization-${name}`]: newValue
})
}
this.setState(newState);
Expand Down Expand Up @@ -370,23 +390,24 @@ class IndexContainer extends Component {
greymassnoop = true
noop = actions[0]
}
const fieldsMatchSigner = {};
const fieldsMatchSignerAccount = {};
const fieldsMatchSignerPermission = {};
const fieldsPromptSigner = {};
action.authorization.forEach((auth, idx) => {
if (auth.actor === '............1') {
fieldsMatchSigner[`authorization-actor`] = true;
fieldsMatchSignerAccount[`authorization-actor`] = true;
}
if (auth.permission === '............1') {
fieldsMatchSigner[`authorization-permission`] = true;
if (auth.permission === '............2') {
fieldsMatchSignerPermission[`authorization-permission`] = true;
}
});
Object.keys(action.data).forEach((field) => {
const data = action.data[field];
if (data === '............2') {
fieldsPromptSigner[field] = true;
fieldsMatchSignerPermission[field] = true;
}
if (data === '............1') {
fieldsMatchSigner[field] = true;
fieldsMatchSignerAccount[field] = true;
}
});
const combinedAuthorization = (billFirstAuthorizer) ? {
Expand All @@ -411,7 +432,8 @@ class IndexContainer extends Component {
callback,
},
fields: Object.assign({}, action.data),
fieldsMatchSigner,
fieldsMatchSignerAccount,
fieldsMatchSignerPermission,
fieldsPromptSigner,
greymassnoop,
loading: false,
Expand Down Expand Up @@ -529,7 +551,8 @@ class IndexContainer extends Component {
blockchain,
contract,
decoded,
fieldsMatchSigner,
fieldsMatchSignerAccount,
fieldsMatchSignerPermission,
fieldsPromptSigner,
greymassnoop,
loading,
Expand Down Expand Up @@ -560,7 +583,8 @@ class IndexContainer extends Component {
<FormFields
aliases={abi.types}
fields={fields}
fieldsMatchSigner={fieldsMatchSigner}
fieldsMatchSignerAccount={fieldsMatchSignerAccount}
fieldsMatchSignerPermission={fieldsMatchSignerPermission}
fieldsPromptSigner={fieldsPromptSigner}
onChange={this.onChangeField}
onChangeMatchSigner={this.onChangeMatchSigner}
Expand All @@ -572,10 +596,12 @@ class IndexContainer extends Component {
<FormAuthorization
authorization={authorization}
billFirstAuthorizer={billFirstAuthorizer}
fieldsMatchSigner={fieldsMatchSigner}
fieldsMatchSignerAccount={fieldsMatchSignerAccount}
fieldsMatchSignerPermission={fieldsMatchSignerPermission}
greymassnoop={greymassnoop}
onChange={this.onChangeAuthorization}
onChangeAuthorizationMatchSigner={this.onChangeAuthorizationMatchSigner}
onChangeAuthorizationMatchSignerAccount={this.onChangeAuthorizationMatchSignerAccount}
onChangeAuthorizationMatchSignerPermission={this.onChangeAuthorizationMatchSignerPermission}
onChangeBillFirst={this.onChangeBillFirst}
onChangeNoop={this.onChangeNoop}
values={this.state.callback}
Expand Down

0 comments on commit a1843fa

Please sign in to comment.