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

Jim/93604/replace connect with use store in positions drawer positions modal card toggle positions mobile time picker populate header #81

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -1,5 +1,4 @@
import classNames from 'classnames';
import { PropTypes as MobxPropTypes } from 'mobx-react';
import PropTypes from 'prop-types';
import React from 'react';
import { NavLink } from 'react-router-dom';
Expand All @@ -8,8 +7,9 @@ import { Icon, DataList, Text, PositionsDrawerCard } from '@deriv/components';
import { routes, useNewRowTransition } from '@deriv/shared';
import { localize } from '@deriv/translations';
import EmptyPortfolioMessage from '../EmptyPortfolioMessage';
import { connect } from 'Stores/connect';
import { filterByContractType } from './helpers';
import { useTraderStore } from 'Stores/useTraderStores';
import { observer, useStore } from '@deriv/stores';

const PositionsDrawerCardItem = ({
row: portfolio_position,
Expand Down Expand Up @@ -56,17 +56,33 @@ const PositionsDrawerCardItem = ({
);
};

const PositionsDrawer = ({
all_positions,
error,
is_positions_drawer_on,
onHoverPosition,
symbol,
toggleDrawer,
trade_contract_type,
onMount,
...props
}) => {
const PositionsDrawer = observer(({ ...props }) => {
const { symbol, contract_type: trade_contract_type } = useTraderStore();
const { client, common, contract_trade, portfolio, ui } = useStore();
const { currency } = client;
const { server_time } = common;
const { getContractById } = contract_trade;
const {
all_positions,
error,
onHoverPosition,
onMount,
onClickCancel,
onClickSell,
removePositionById: onClickRemove,
} = portfolio;
const {
is_mobile,
is_positions_drawer_on,
togglePositionsDrawer: toggleDrawer,
addToast,
current_focus,
removeToast,
setCurrentFocus,
should_show_cancellation_warning,
toggleCancellationWarning,
toggleUnsupportedContractModal,
} = ui;
const drawer_ref = React.useRef(null);
const list_ref = React.useRef(null);
const scrollbar_ref = React.useRef(null);
Expand All @@ -91,7 +107,26 @@ const PositionsDrawer = ({
<DataList
data_source={positions}
rowRenderer={args => (
<PositionsDrawerCardItem onHoverPosition={onHoverPosition} symbol={symbol} {...args} {...props} />
<PositionsDrawerCardItem
onHoverPosition={onHoverPosition}
symbol={symbol}
currency={currency}
addToast={addToast}
onClickCancel={onClickCancel}
onClickSell={onClickSell}
onClickRemove={onClickRemove}
server_time={server_time}
getContractById={getContractById}
is_mobile={is_mobile}
current_focus={current_focus}
removeToast={removeToast}
setCurrentFocus={setCurrentFocus}
should_show_cancellation_warning={should_show_cancellation_warning}
toggleCancellationWarning={toggleCancellationWarning}
toggleUnsupportedContractModal={toggleUnsupportedContractModal}
{...args}
{...props}
/>
)}
keyMapper={row => row.id}
row_gap={8}
Expand Down Expand Up @@ -140,57 +175,12 @@ const PositionsDrawer = ({
</div>
</React.Fragment>
);
};
});

PositionsDrawer.propTypes = {
all_positions: MobxPropTypes.arrayOrObservableArray,
children: PropTypes.node,
error: PropTypes.string,
is_mobile: PropTypes.bool,
is_positions_drawer_on: PropTypes.bool,
onChangeContractUpdate: PropTypes.func,
onClickContractUpdate: PropTypes.func,
onHoverPosition: PropTypes.func,
onMount: PropTypes.func,
symbol: PropTypes.string,
toggleDrawer: PropTypes.func,
currency: PropTypes.string,
server_time: PropTypes.object,
addToast: PropTypes.func,
current_focus: PropTypes.string,
onClickCancel: PropTypes.func,
onClickSell: PropTypes.func,
onClickRemove: PropTypes.func,
getContractById: PropTypes.func,
removeToast: PropTypes.func,
setCurrentFocus: PropTypes.func,
should_show_cancellation_warning: PropTypes.bool,
toggleCancellationWarning: PropTypes.func,
toggleUnsupportedContractModal: PropTypes.func,
trade_contract_type: PropTypes.string,
};

export default connect(({ modules, ui, client, common, portfolio, contract_trade }) => ({
all_positions: portfolio.all_positions,
error: portfolio.error,
onHoverPosition: portfolio.onHoverPosition,
onMount: portfolio.onMount,
symbol: modules.trade.symbol,
trade_contract_type: modules.trade.contract_type,
is_mobile: ui.is_mobile,
is_positions_drawer_on: ui.is_positions_drawer_on,
toggleDrawer: ui.togglePositionsDrawer,
currency: client.currency,
server_time: common.server_time,
addToast: ui.addToast,
current_focus: ui.current_focus,
onClickCancel: portfolio.onClickCancel,
onClickSell: portfolio.onClickSell,
onClickRemove: portfolio.removePositionById,
getContractById: contract_trade.getContractById,
removeToast: ui.removeToast,
setCurrentFocus: ui.setCurrentFocus,
should_show_cancellation_warning: ui.should_show_cancellation_warning,
toggleCancellationWarning: ui.toggleCancellationWarning,
toggleUnsupportedContractModal: ui.toggleUnsupportedContractModal,
}))(PositionsDrawer);
export default PositionsDrawer;
Loading