Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amam/fix_duration_error #98

Merged
merged 13 commits into from
May 23, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import { PropTypes as MobxPropTypes } from 'mobx-react';
import { connect } from 'Stores/connect';
import { convertDurationLimit } from 'Stores/Modules/Trading/Helpers/duration';
import Duration from './duration.jsx';

class DurationWrapper extends React.Component {
Expand Down Expand Up @@ -43,22 +44,48 @@ class DurationWrapper extends React.Component {
}

componentDidMount() {
const current_unit = this.props.is_advanced_duration ?
this.props.advanced_duration_unit : this.props.simple_duration_unit;
const current_duration = this.props.getDurationFromUnit(this.props.duration_unit);

if (this.props.duration_unit !== current_unit) {
this.props.onChangeUiStore({ name: `${this.props.is_advanced_duration ? 'advanced' : 'simple'}_duration_unit`, value: this.props.duration_unit });
const {
advanced_duration_unit,
advanced_expiry_type,
contract_expiry_type,
duration,
duration_min_max,
duration_unit,
expiry_type,
getDurationFromUnit,
is_advanced_duration,
onChange,
onChangeUiStore,
simple_duration_unit,
} = this.props;

const current_unit = is_advanced_duration ?
advanced_duration_unit : simple_duration_unit;
cakasuma marked this conversation as resolved.
Show resolved Hide resolved
const current_duration = getDurationFromUnit(current_unit);
const max_value = convertDurationLimit(+duration_min_max[contract_expiry_type].max, current_unit);
const min_value = convertDurationLimit(+duration_min_max[contract_expiry_type].min, current_unit);
cakasuma marked this conversation as resolved.
Show resolved Hide resolved

if (duration_unit !== current_unit) {
onChangeUiStore({ name: `${is_advanced_duration ? 'advanced' : 'simple'}_duration_unit`, value: duration_unit });
}

if (this.props.duration !== current_duration) {
this.props.onChangeUiStore({ name: `duration_${current_unit}`, value: this.props.duration });
if (duration !== current_duration) {
onChangeUiStore({ name: `duration_${current_unit}`, value: duration });
}

if (this.props.expiry_type === 'endtime') this.handleEndTime();
if (expiry_type === 'endtime') this.handleEndTime();

if (this.advancedHasWrongExpiry()) {
this.props.onChange({ target: { name: 'expiry_type', value: this.props.advanced_expiry_type } });
onChange({ target: { name: 'expiry_type', value: advanced_expiry_type } });
}

if (current_duration < min_value) {
onChangeUiStore({ name: `duration_${current_unit}`, value: min_value });
onChange({ target: { name: 'duration', value: min_value } });
}
if (current_duration > max_value) {
cakasuma marked this conversation as resolved.
Show resolved Hide resolved
onChangeUiStore({ name: `duration_${current_unit}`, value: max_value });
onChange({ target: { name: 'duration', value: max_value } });
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/javascript/app/Modules/Trading/Containers/purchase.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ const Purchase = ({
validation_errors,
}) => {
const is_high_low = /high_low/.test(contract_type.toLowerCase());
const isLoading = info => {
const has_validation_error = Object.values(validation_errors).some(e => e.length);
return !has_validation_error && !info.has_error && !info.id;
};
const has_validation_error = Object.values(validation_errors).some(e => e.length);

const isLoading = info => !has_validation_error && !info.has_error && !info.id;

const components = [];
Object.keys(trade_types).map((type, index) => {
const info = proposal_info[type] || {};
const is_disabled = !is_purchase_enabled || !is_trade_enabled || !info.id || !is_client_allowed_to_visit;
const is_proposal_error = info.has_error && !info.has_error_details;
const is_proposal_error = has_validation_error || (info.has_error && !info.has_error_details);
cakasuma marked this conversation as resolved.
Show resolved Hide resolved

const purchase_fieldset = (
<PurchaseFieldset
Expand Down