Skip to content

Commit

Permalink
Merge pull request #4 from reza-fs/mt-dashboard
Browse files Browse the repository at this point in the history
Mt dashboard
  • Loading branch information
msamprz committed Sep 25, 2019
2 parents 76200de + 6d4bc0e commit 0e0ee4c
Show file tree
Hide file tree
Showing 22 changed files with 828 additions and 65 deletions.
10 changes: 0 additions & 10 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,6 @@ export default class ClientStore extends BaseStore {

}

@computed
get default_currency() {
if (Object.keys(this.currencies_list).length > 0) {
const keys = Object.keys(this.currencies_list);
// Fix for edge case when logging out from crypto accounts causes Fiat list to be empty
if (this.currencies_list.Fiat.length < 1) return 'USD';
return Object.values(this.currencies_list[`${keys[0]}`])[0].text;
} return 'USD';
}

@computed
get is_fully_authenticated() {
if (!this.account_status.status) return false;
Expand Down
2 changes: 2 additions & 0 deletions packages/trader/src/App/Containers/Layout/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from 'App/Components/Layout/Header';
import header_links from 'App/Constants/header-links';
import Lazy from 'App/Containers/Lazy';
import Password from 'App/Containers/Mt5';
import RealAccountSignup from 'App/Containers/RealAccountSignup';
import { connect } from 'Stores/connect';

Expand Down Expand Up @@ -73,6 +74,7 @@ const Header = ({
</div>
</div>
<RealAccountSignup />
<Password />
</header>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Button } from 'deriv-components';
import React from 'react';
import Localize from 'App/Components/Elements/localize.jsx';
import Icon from 'Assets/icon.jsx';

const SuccessCurrencyDialog = ({
current,
const SuccessDialog = ({
icon,
message,
onCancel,
onSubmit,
success_message,
icon_size,
text_submit,
}) => {
const IconNextCurrency = () => <Icon
icon='IconAccountsCurrency'
type={current.toLowerCase()}
/>;
const MainIcon = () => icon || null;

const IconWon = ({ className }) => <Icon
const Checkmark = ({ className }) => <Icon
className={className}
icon='IconWon'
/>;

return (
<div className='success-change'>
<div className={
classNames('success-change__icon-area', 'success-change__icon-area--big')
classNames('success-change__icon-area', {
'success-change__icon-area--large' : icon_size === 'large',
'success-change__icon-area--xlarge': icon_size === 'xlarge',
})
}
>
<IconNextCurrency />
<IconWon className='bottom-right-overlay' />
<MainIcon />
<Checkmark className='bottom-right-overlay' />
</div>
<div className='success-change__body-area'>
<h2>
<Localize
i18n_default_text='Success!'
/>
</h2>
<p>{success_message}</p>
<p>{message}</p>
</div>
<div className='success-change__btn-area'>
<Button
Expand All @@ -46,16 +49,24 @@ const SuccessCurrencyDialog = ({
i18n_default_text='Maybe later'
/>
</Button>
<Button
onClick={onSubmit}
>
<Localize
i18n_default_text='Deposit now'
/>
</Button>
<Button onClick={onSubmit}>{text_submit}</Button>
</div>
</div>
);
};

export default SuccessCurrencyDialog;
SuccessDialog.defaultProps = {
icon_size: 'large',
};

SuccessDialog.propTypes = {
icon : PropTypes.object,
icon_size : PropTypes.string,
icon_type : PropTypes.string,
message : PropTypes.string,
onCancel : PropTypes.func,
onSubmit : PropTypes.func,
text_submit: PropTypes.string,
};

export default SuccessDialog;
1 change: 1 addition & 0 deletions packages/trader/src/App/Containers/Mt5/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default from './password';
14 changes: 14 additions & 0 deletions packages/trader/src/App/Containers/Mt5/mt5-signup.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { Component } from 'react';
import Password from './password.jsx';

class Mt5Signup extends Component {
render() {
return (
<React.Fragment>
<Password />
</React.Fragment>
);
}
}

export default Mt5Signup;
204 changes: 204 additions & 0 deletions packages/trader/src/App/Containers/Mt5/password.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import {
Input,
Modal,
PasswordMeter,
} from 'deriv-components';
import { Formik } from 'formik';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import SuccessDialog from 'App/Containers/Modals/success-dialog.jsx';
import { connect } from 'Stores/connect';
import Localize from 'App/Components/Elements/localize.jsx';
import FormSubmitButton from 'App/Containers/RealAccountSignup/form-submit-button.jsx';
import { localize } from 'App/i18n';
import IconMT5Synthetic from 'Assets/Mt5/icon-mt5-synthetic.jsx';
import IconMT5Advanced from 'Assets/Mt5/icon-mt5-advanced.jsx';
import IconMT5Standard from 'Assets/Mt5/icon-mt5-standard.jsx';
import {
validPassword,
validLength,
} from 'Utils/Validator/declarative-validation-rules';
import 'Sass/mt5.scss';

const getSubmitText = (account_title) => localize(`You have created a ${account_title}. To start trading, transfer funds from your Deriv account into this account.`);

const getIconFromType = (type) => {
switch (type) {
case 'synthetic_indices':
return IconMT5Synthetic;
case 'standard':
return IconMT5Standard;
default:
return IconMT5Advanced;
}
};

class Password extends Component {
validatePassword = (values) => {
const is_valid = validPassword(values.password) &&
validLength(values.password, {
min: 8,
max: 30,
});
const errors = {};

if (!is_valid) {
errors.password = localize(
'The password must contain at least two of three types of characters (lower case, upper case and digits).');
}

return errors;
};

closeModal = () => {
setTimeout(() => this.props.setMt5Error(false), 400);
this.props.disableMt5PasswordModal();
};

closeOpenSuccess = () => {
setTimeout(() => this.props.setMt5Error(false), 400);
this.props.closeMt5AndOpenCashier('account_transfer');
};

render() {
const IconType = getIconFromType(this.props.account_type.type);
return (
<Modal
className='mt5-password-modal'
is_open={this.props.is_mt5_password_modal_enabled}
toggleModal={this.closeModal}
has_close_icon={false}
>
{this.props.has_mt5_error &&
<div className='error'>
<SuccessDialog
onCancel={this.closeModal}
onSubmit={this.closeOpenSuccess}
// message={getSubmitText(this.props.account_title)}
message={this.props.error_message}
icon={<IconType />}
icon_size='xlarge'
text_submit={localize('Transfer now')}
/>
</div>
}
{!this.props.has_mt5_error && !this.props.is_mt5_success_dialog_enabled &&
<Formik
initialValues={{
password: '',
}}
validate={this.validatePassword}
onSubmit={(values, actions) => {
this.props.submitMt5Password(
values.password,
actions.setSubmitting,
);
}}
render={({
handleSubmit,
// setFieldValue,
setFieldTouched,
handleChange,
handleBlur,
errors,
values,
isSubmitting,
touched,
}) => (
<form onSubmit={handleSubmit}>
<h2>
<Localize
i18n_default_text='Choose a password for your DMT5 {{ account_type }}'
values={{
account_type: this.props.account_title,
}}
/>
</h2>
<div
className='dc-modal__container_mt5-password-modal__body'
>
<div className='input-element'>
<PasswordMeter
input={values.password}
error={touched.password && errors.password}
>
<Input
autoComplete='password'
label={localize('MT5 Password')}
type='password'
name='password'
value={values.password}
onBlur={handleBlur}
onChange={(e) => {
setFieldTouched(
'password',
true,
);
handleChange(e);
}}
/>
</PasswordMeter>
</div>
<div
className='dc-modal__container_mt5-password-modal__description'
>
<p>
<Localize
i18n_default_text='Strong passwords contain at least 8 characters, combine uppercase and lowercase letters with numbers'
/>
</p>
</div>
</div>
<FormSubmitButton
is_disabled={
isSubmitting ||
!values.password ||
Object.keys(errors).length > 0
}
label='Add account' // Localization will be handled by component
form_error={this.props.form_error}
/>
</form>
)}
/>
}
{!this.props.has_mt5_error && this.props.is_mt5_success_dialog_enabled &&
<SuccessDialog
onCancel={this.closeModal}
onSubmit={this.closeOpenSuccess}
message={getSubmitText(this.props.account_title)}
// message={this.props.error_message}
icon={<IconType />}
icon_size='xlarge'
text_submit={localize('Transfer now')}
/>
}
</Modal>
);
}
}

Password.propTypes = {
account_title : PropTypes.string,
account_type : PropTypes.object,
closeMt5AndOpenCashier : PropTypes.func,
disableMt5PasswordModal : PropTypes.func,
error_message : PropTypes.string,
has_mt5_error : PropTypes.bool,
is_mt5_password_modal_enabled: PropTypes.bool,
is_mt5_success_dialog_enabled: PropTypes.bool,
setMt5Error : PropTypes.func,
submitMt5Password : PropTypes.func,
};
export default connect(({ ui, modules }) => ({
account_title : modules.mt5.account_title,
account_type : modules.mt5.account_type,
closeMt5AndOpenCashier : ui.closeMt5AndOpenCashier,
disableMt5PasswordModal : ui.disableMt5PasswordModal,
error_message : modules.mt5.error_message,
has_mt5_error : modules.mt5.has_mt5_error,
is_mt5_success_dialog_enabled: modules.mt5.is_mt5_success_dialog_enabled,
is_mt5_password_modal_enabled: ui.is_mt5_password_modal_enabled,
setMt5Error : modules.mt5.setError,
submitMt5Password : modules.mt5.submitMt5Password,
}))(Password);
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import classNames from 'classnames';
import { Modal } from 'deriv-components';
import React, { Component } from 'react';
import { localize } from 'App/i18n';
import Localize from 'App/Components/Elements/localize.jsx';
import { connect } from 'Stores/connect';
import AccountWizard from './account-wizard.jsx';
import AddOrManageAccounts from './add-or-manage-accounts.jsx';
import FinishedSetCurrency from './finished-set-currency.jsx';
import SuccessCurrencyDialog from './success-currency-dialog.jsx';
import classNames from 'classnames';
import { Modal } from 'deriv-components';
import React, { Component } from 'react';
import { localize } from 'App/i18n';
import Localize from 'App/Components/Elements/localize.jsx';
import Icon from 'Assets/icon.jsx';
import { connect } from 'Stores/connect';
import AccountWizard from './account-wizard.jsx';
import AddOrManageAccounts from './add-or-manage-accounts.jsx';
import FinishedSetCurrency from './finished-set-currency.jsx';
import SuccessDialog from '../Modals/success-dialog.jsx';
import 'Sass/account-wizard.scss';
import 'Sass/real-account-signup.scss';

Expand Down Expand Up @@ -54,11 +55,12 @@ class RealAccountSignup extends Component {
{
label: false,
value: () => (
<SuccessCurrencyDialog
current={this.state.current_currency}
<SuccessDialog
onCancel={this.closeModal}
onSubmit={this.closeModalThenOpenCashier}
success_message={this.state.success_message}
message={this.state.success_message}
icon={<Icon type={this.state.current_currency} icon='IconAccountsCurrency' />}
text_submit={localize('Deposit now')}
/>
)
}
Expand Down
Loading

0 comments on commit 0e0ee4c

Please sign in to comment.