Skip to content

Commit

Permalink
If interacting with the Insights blockchain, only allow specific amou…
Browse files Browse the repository at this point in the history
…nts for tokens staked for network and CPU bandwidth and RAM purchased.
  • Loading branch information
Darwin Lo authored and aaroncox committed Jan 24, 2019
1 parent 2e26bcd commit a34aef9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
12 changes: 10 additions & 2 deletions app/shared/components/Global/Form/Field/Ram.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import debounce from 'lodash/debounce';
export default class GlobalFormFieldRam extends Component<Props> {
constructor(props) {
super(props);

const {
readOnly
} = props;

this.state = {
value: props.defaultValue
value: props.defaultValue,
readOnly
};
}
onChange = debounce((e, { name, value }) => {
Expand All @@ -25,7 +31,8 @@ export default class GlobalFormFieldRam extends Component<Props> {
icon,
label,
loading,
name
name,
readOnly
} = this.props;
const {
value
Expand All @@ -42,6 +49,7 @@ export default class GlobalFormFieldRam extends Component<Props> {
name={name}
onChange={this.onChange}
placeholder="0"
readOnly={readOnly}
/>
);
}
Expand Down
12 changes: 10 additions & 2 deletions app/shared/components/Global/Form/Field/Token.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ import debounce from 'lodash/debounce';
export default class GlobalFormFieldToken extends Component<Props> {
constructor(props) {
super(props);

const {
readOnly
} = props;

this.state = {
value: props.defaultValue
value: props.defaultValue,
readOnly
};
}
onChange = debounce((e, { name, value }) => {
Expand All @@ -34,7 +40,8 @@ export default class GlobalFormFieldToken extends Component<Props> {
placeholder
} = this.props;
const {
value
value,
readOnly
} = this.state;
return (
<Form.Field
Expand All @@ -47,6 +54,7 @@ export default class GlobalFormFieldToken extends Component<Props> {
name={name}
onChange={this.onChange}
placeholder={placeholder || '0.0000'}
readOnly={readOnly}
/>
);
}
Expand Down
27 changes: 24 additions & 3 deletions app/shared/components/Tools/Form/CreateAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,26 @@ class ToolsFormCreateAccount extends Component<Props> {
activeKeyValue,
balance,
connection,
ownerKeyValue
} = props;

let {
delegatedBw,
delegatedCpu,
ownerKeyValue,
ramAmount
} = props;

let disableStakingFields = false;
let disableRamField = false;

if (connection.chainId === 'b042025541e25a472bffde2d62edd457b7e70cee943412b1ea0f044f88591664') {
delegatedBw = '0.0001';
delegatedCpu = '0.0001';
ramAmount = 8192;
disableStakingFields = true;
disableRamField = true;
}

this.state = {
accountName,
activeKeyValue,
Expand All @@ -40,7 +54,9 @@ class ToolsFormCreateAccount extends Component<Props> {
formErrors: {},
ownerKeyValue,
ramAmount,
submitDisabled: true
submitDisabled: true,
disableStakingFields,
disableRamField
};
}

Expand Down Expand Up @@ -278,7 +294,9 @@ class ToolsFormCreateAccount extends Component<Props> {
ownerKeyValue,
ramAmount,
ramPrice,
transferTokens
transferTokens,
disableStakingFields,
disableRamField
} = this.state;

let {
Expand Down Expand Up @@ -368,20 +386,23 @@ class ToolsFormCreateAccount extends Component<Props> {
label={t('tools_form_create_account_ram_amount')}
name="ramAmount"
onChange={this.onChange}
readOnly={disableRamField}
/>
<GlobalFormFieldToken
connection={connection}
defaultValue={delegatedBw && delegatedBw.split(' ')[0]}
label={t('tools_form_create_account_delegated_bw_label', { chainSymbol: connection.chainSymbol })}
name="delegatedBw"
onChange={this.onChange}
readOnly={disableStakingFields}
/>
<GlobalFormFieldToken
connection={connection}
defaultValue={delegatedCpu && delegatedCpu.split(' ')[0]}
label={t('tools_form_create_account_delegated_cpu_label', { chainSymbol: connection.chainSymbol })}
name="delegatedCpu"
onChange={this.onChange}
readOnly={disableStakingFields}
/>
<Form.Checkbox
checked={transferTokens}
Expand Down

0 comments on commit a34aef9

Please sign in to comment.