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

Maryia/86616/fix barriers to show won/lost distinctively #69

Closed
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
Expand Up @@ -17,8 +17,8 @@ const AccumulatorsChartElements = ({
);
const last_contract_info = accumulators_positions.slice().pop()?.contract_info;
const should_highlight_tick_without_contract = !!current_symbol_spot_time && is_stats_highlighted;
const should_highlight_contract_tick =
last_contract_info?.status === 'lost' && current_symbol_spot_time === last_contract_info?.exit_tick_time;
const diff = Date.now() / 1000 - last_contract_info?.exit_tick_time;
const should_highlight_contract_tick = last_contract_info?.status === 'lost' && diff <= 1.3;
const should_highlight_tick = should_highlight_tick_without_contract || should_highlight_contract_tick;
const current_spot = should_highlight_contract_tick ? last_contract_info?.exit_tick : current_symbol_spot;
const current_spot_time = should_highlight_contract_tick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import AccumulatorsProfitLossText from './accumulators-profit-loss-text';

const AccumulatorsProfitLossTooltip = ({
alignment = 'right',
current_spot,
current_spot_time,
className = 'sc-accumulators-profit-loss-tooltip',
currency,
exit_tick,
exit_tick_time,
high_barrier,
is_sold,
low_barrier,
profit,
}) => {
const [is_tooltip_open, setIsTooltipOpen] = React.useState(false);
Expand Down Expand Up @@ -68,15 +68,18 @@ const AccumulatorsProfitLossTooltip = ({
};

if (typeof profit !== 'number') return null;
if (!is_sold && current_spot_time && high_barrier)
const time_now = Date.now() / 1000;
const diff = time_now - exit_tick_time;
if ((!is_sold || diff <= 1.3) && current_spot_time && high_barrier) {
return (
<AccumulatorsProfitLossText
currency={currency}
current_spot={current_spot}
current_spot={+low_barrier + (+high_barrier - +low_barrier) / 2}
current_spot_time={current_spot_time}
profit={profit}
/>
);
}
return is_sold && exit_tick_time ? (
<FastMarker markerRef={onRef} className={classNames(className, won ? 'won' : 'lost')}>
<span
Expand Down Expand Up @@ -112,14 +115,14 @@ const AccumulatorsProfitLossTooltip = ({

AccumulatorsProfitLossTooltip.propTypes = {
alignment: PropTypes.string,
current_spot: PropTypes.number,
current_spot_time: PropTypes.number,
className: PropTypes.string,
currency: PropTypes.string,
exit_tick: PropTypes.number,
exit_tick_time: PropTypes.number,
high_barrier: PropTypes.string,
is_sold: PropTypes.number,
low_barrier: PropTypes.string,
profit: PropTypes.number,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const TickContract = RawMarkerMaker(
granularity,
contract_info: {
contract_type,
// exit_tick_time,
exit_tick_time,
status,
profit,
is_accumulators_trade_without_contract,
Expand Down Expand Up @@ -264,7 +264,12 @@ const TickContract = RawMarkerMaker(

if (is_accumulators_contract) {
// draw custom barrier shadows with borders and labels for accumulators:
if (barrier && barrier_2 && previous_tick && (status === 'open' || is_in_contract_details)) {
if (
barrier &&
barrier_2 &&
previous_tick &&
(status === 'open' || Date.now() / 1000 - exit_tick_time <= 1.3 || is_in_contract_details)
) {
// draw 2 barriers with a shade between them for an open ACCU contract
draw_shaded_barriers({
ctx,
Expand Down
16 changes: 14 additions & 2 deletions packages/trader/src/Stores/Modules/Trading/trade-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getBarrierPipSize,
isBarrierSupported,
removeBarrier,
isAccumulatorContract,
} from '@deriv/shared';
import { localize } from '@deriv/translations';
import { getValidationRules, getMultiplierValidationRules } from 'Stores/Modules/Trading/Constants/validation-rules';
Expand Down Expand Up @@ -1098,8 +1099,19 @@ export default class TradeStore extends BaseStore {
spot,
spot_time,
} = this.proposal_info.ACCU;
this.root_store.contract_trade.current_symbol_spot = spot;
this.root_store.contract_trade.current_symbol_spot_time = spot_time;
const accu_contracts = this.root_store.portfolio.all_positions.filter(
({ contract_info, type }) => isAccumulatorContract(type) && contract_info.underlying === this.symbol
);
const { status, exit_tick_time } = accu_contracts[accu_contracts.length - 1]?.contract_info || {};
const diff = Date.now() / 1000 - exit_tick_time;
if (status === 'open' || (status && diff < 1.3)) {
// hide barriers from proposal while last contract barriers are shown
this.root_store.contract_trade.current_symbol_spot = null;
this.root_store.contract_trade.current_symbol_spot_time = null;
} else {
this.root_store.contract_trade.current_symbol_spot = spot;
this.root_store.contract_trade.current_symbol_spot_time = spot_time;
}
this.ticks_history_stats = getUpdatedTicksHistoryStats({
previous_ticks_history_stats: this.ticks_history_stats,
new_ticks_history_stats: ticks_stayed_in,
Expand Down