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

V20190612_0 #153

Merged
merged 19 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f39b911
cleanup contract store on account switch from 404 contract, explicitl…
oskar-binary May 29, 2019
c59bf40
Merge branch 'dev' of github.com:binary-com/deriv-app into oskar/hand…
oskar-binary May 29, 2019
2cdfbc2
update location check
oskar-binary May 29, 2019
fee6f52
redirect to trade if switch account from ErrorComponent
oskar-binary May 29, 2019
4be80c5
Merge branch 'dev' of github.com:binary-com/deriv-app into oskar/hand…
oskar-binary May 29, 2019
21d488c
clear error_message on account switch, remount contract-replay on acc…
oskar-binary May 30, 2019
94b016b
remove withrouter from acc-switcher
oskar-binary May 30, 2019
76cdc5c
Merge branch 'dev' of github.com:binary-com/deriv-app into oskar/hand…
oskar-binary May 30, 2019
d298c0f
remove forgetting poc if error response, style fixes
oskar-binary May 30, 2019
ae32ceb
remove trade parameters merge
arash-fs May 28, 2019
366242b
change detecting favorite market
arash-fs May 22, 2019
129305f
change the default pick symbol
arash-fs May 28, 2019
31f7ae5
send userId
negar-binary Jun 12, 2019
59072f7
Merge branch 'dev' into oskar/handle_404_account_switch
negarn Jun 12, 2019
ec9b0db
Merge pull request #114 from OskarAhl/oskar/handle_404_account_switch
negarn Jun 12, 2019
f87c936
Merge branch 'dev' into default-symbol-weekends
negarn Jun 12, 2019
4dad86e
Merge pull request #47 from arash-binary/default-symbol-weekends
negarn Jun 12, 2019
35468f5
Merge branch 'dev' into negar/add_user_id
ashkanx Jun 12, 2019
0be6200
Merge pull request #151 from negarn/negar/add_user_id
ashkanx Jun 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ContractAudit from 'App/Components/Elements/PositionsDrawer/resul
import ContractTypeCell from 'App/Components/Elements/PositionsDrawer/contract-type-cell.jsx';
import ProgressSlider from 'App/Components/Elements/PositionsDrawer/ProgressSlider';
import { getTimePercentage } from 'App/Components/Elements/PositionsDrawer/helpers';
import routes from 'Constants/routes';
import ProfitLossCardContent from 'Modules/Reports/Components/profit-loss-card-content.jsx';
import ContractCardBody from './contract-card-body.jsx';
import ContractCardFooter from './contract-card-footer.jsx';
Expand Down Expand Up @@ -164,14 +165,23 @@ class ContractDrawer extends Component {
);
}

redirectBackToReports = () => {
// history.goBack() will go to the wrong location if user goes to contract by pasting it in the url.
if (this.props.history.location.state) {
this.props.history.goBack();
} else {
this.props.history.push(routes.reports);
}
};

render() {
if (!this.props.contract_info) return null;
const body_content = this.getBodyContent();
return (
<div className={classNames('contract-drawer', {})}>
<div
className='contract-drawer__heading'
onClick={() => this.props.history.goBack()}
onClick={this.redirectBackToReports}
>
<Icon icon='IconBack' />
<h2><Localize str={this.props.heading || 'Contract'} /></h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ const TableRow = ({

return (
to ?
<NavLink className={row_class_name} to={to}>
<NavLink
className={row_class_name}
to={{
pathname: to,
state : {
from_table_row: true,
},
}}
>
{cells}
</NavLink>
:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class AccountSwitcher extends React.Component {
this.props.toggle();
if (this.props.account_loginid === loginid) return;
await this.props.switchAccount(loginid);

if (this.props.has_error) {
this.props.clearError();
}
}

render() {
Expand Down Expand Up @@ -140,6 +144,8 @@ AccountSwitcher.propTypes = {
account_list : PropTypes.array,
account_loginid : PropTypes.string,
cleanUp : PropTypes.func,
clearError : PropTypes.func,
has_error : PropTypes.bool,
is_logged_in : PropTypes.bool,
is_positions_drawer_on: PropTypes.bool,
is_upgrade_enabled : PropTypes.bool,
Expand All @@ -153,7 +159,7 @@ AccountSwitcher.propTypes = {
};

const account_switcher = connect(
({ client, ui }) => ({
({ client, ui, modules }) => ({
account_list : client.account_list,
account_loginid : client.loginid,
is_logged_in : client.is_logged_in,
Expand All @@ -162,6 +168,8 @@ const account_switcher = connect(
upgrade_info : client.upgrade_info,
cleanUp : client.cleanUp,
virtual_loginid : client.virtual_account_loginid,
clearError : modules.contract.clearError,
has_error : modules.contract.has_error,
is_positions_drawer_on: ui.is_positions_drawer_on,
togglePositionsDrawer : ui.togglePositionsDrawer,

Expand Down
73 changes: 39 additions & 34 deletions src/javascript/app/Modules/Contract/Containers/contract.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,46 @@ import ErrorComponent from 'App/Components/Elements/Errors';
import { connect } from 'Stores/connect';
import ContractReplay from './contract-replay.jsx';

const Contract = ({
error_message,
has_error,
history,
match,
}) => (
<React.Fragment>
{
has_error ?
<ErrorComponent
message={error_message}
redirect_label={localize('Go back to trading')}
redirectOnClick={() => history.push(routes.trade)}
should_show_refresh={false}
/>
:
<CSSTransition
in={!has_error}
timeout={400}
classNames={{
enter : 'contract--enter',
enterDone: 'contract--enter-done',
exit : 'contract--exit',
}}
unmountOnExit
>
<ContractReplay
contract_id={match.params.contract_id}
key={match.params.contract_id}
/>
</CSSTransition>
}
</React.Fragment>
);
class Contract extends React.Component {
componentWillUnmount() {
if (this.props.has_error) this.props.clearError();
}

render () {
return (
<React.Fragment>
{
this.props.has_error ?
<ErrorComponent
message={this.props.error_message}
redirect_label={localize('Go back to trading')}
redirectOnClick={() => this.props.history.push(routes.trade)}
should_show_refresh={false}
/>
:
<CSSTransition
in={!this.props.has_error}
timeout={400}
classNames={{
enter : 'contract--enter',
enterDone: 'contract--enter-done',
exit : 'contract--exit',
}}
unmountOnExit
>
<ContractReplay
contract_id={this.props.match.params.contract_id}
key={this.props.match.params.contract_id}
/>
</CSSTransition>
}
</React.Fragment>
);
}
}

Contract.propTypes = {
clearError : PropTypes.func,
error_message: PropTypes.string,
has_error : PropTypes.bool,
history : PropTypes.object,
Expand All @@ -54,6 +58,7 @@ Contract.propTypes = {

export default withRouter(connect(
({ modules, ui }) => ({
clearError : modules.contract.clearError,
error_message: modules.contract.error_message,
has_error : modules.contract.has_error,
is_mobile : ui.is_mobile,
Expand Down
45 changes: 35 additions & 10 deletions src/javascript/app/Stores/Modules/Contract/contract-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export default class ContractStore extends BaseStore {
replay_prev_indicative = 0;
replay_indicative = 0;

// Forget old proposal_open_contract stream on account switch from ErrorComponent
should_forget_first = false;

// -------------------
// ----- Actions -----
// -------------------
Expand Down Expand Up @@ -111,6 +114,20 @@ export default class ContractStore extends BaseStore {
}
}

handleSubscribeProposalOpenContract = (contract_id, cb) => {
// TODO: remove .toString() when API is ready
const proposal_open_contract_request = [contract_id.toString(), cb, false];

if (this.should_forget_first) {
WS.forgetAll('proposal_open_contract').then(() => {
this.should_forget_first = false;
WS.subscribeProposalOpenContract(...proposal_open_contract_request);
});
} else {
WS.subscribeProposalOpenContract(...proposal_open_contract_request);
}
}

@action.bound
onMount(contract_id, is_from_positions) {
if (contract_id === +this.contract_id) return;
Expand All @@ -129,7 +146,7 @@ export default class ContractStore extends BaseStore {
}
this.smart_chart.saveAndClearTradeChartLayout('contract');
this.smart_chart.setContractMode(true);
WS.subscribeProposalOpenContract(this.contract_id.toString(), this.updateProposal, false);
this.handleSubscribeProposalOpenContract(this.contract_id, this.updateProposal);
}
}

Expand All @@ -140,7 +157,7 @@ export default class ContractStore extends BaseStore {
this.smart_chart = this.root_store.modules.smart_chart;
this.smart_chart.setContractMode(true);
this.replay_contract_id = contract_id;
WS.subscribeProposalOpenContract(this.replay_contract_id.toString(), this.populateConfig, false);
this.handleSubscribeProposalOpenContract(this.replay_contract_id, this.populateConfig);
}
}

Expand Down Expand Up @@ -193,15 +210,16 @@ export default class ContractStore extends BaseStore {
@action.bound
populateConfig(response) {
if ('error' in response) {
this.has_error = true;
this.has_error = true;
this.contract_config = {};
this.smart_chart.setIsChartLoading(false);
return;
}
if (isEmptyObject(response.proposal_open_contract)) {
this.has_error = true;
this.error_message = localize('Sorry, you can\'t view this contract because it doesn\'t belong to this account.');
this.contract_config = {};
this.has_error = true;
this.error_message = localize('Sorry, you can\'t view this contract because it doesn\'t belong to this account.');
this.should_forget_first = true;
this.contract_config = {};
this.smart_chart.setContractMode(false);
this.smart_chart.setIsChartLoading(false);
return;
Expand Down Expand Up @@ -257,10 +275,11 @@ export default class ContractStore extends BaseStore {
return;
}
if (isEmptyObject(response.proposal_open_contract)) {
this.has_error = true;
this.error_message = localize('Sorry, you can\'t view this contract because it doesn\'t belong to this account.');
this.contract_info = {};
this.contract_id = null;
this.has_error = true;
this.error_message = localize('Sorry, you can\'t view this contract because it doesn\'t belong to this account.');
this.should_forget_first = true;
this.contract_info = {};
this.contract_id = null;
this.smart_chart.setContractMode(false);
this.smart_chart.setIsChartLoading(false);
return;
Expand Down Expand Up @@ -352,6 +371,12 @@ export default class ContractStore extends BaseStore {
delete this.error_message;
}

@action.bound
clearError() {
this.error_message = null;
this.has_error = false;
}

@action.bound
setIsDigitContract(contract_type) {
this.contract_info.contract_type = contract_type;
Expand Down
Loading