diff --git a/packages/trader/src/AppV2/Components/BottomNav/bottom-nav.tsx b/packages/trader/src/AppV2/Components/BottomNav/bottom-nav.tsx index cc6d4dfe4ee9..66dd66889c58 100644 --- a/packages/trader/src/AppV2/Components/BottomNav/bottom-nav.tsx +++ b/packages/trader/src/AppV2/Components/BottomNav/bottom-nav.tsx @@ -9,7 +9,6 @@ import { } from '@deriv/quill-icons'; import BottomNavItem from './bottom-nav-item'; import { Badge } from '@deriv-com/quill-ui'; -import ContractDetailsFooter from '../ContractDetailsFooter'; type BottomNavProps = { className?: string; @@ -47,10 +46,6 @@ const bottomNavItems = [ icon: , label: , }, - { - icon: , - label: , - }, ]; const BottomNav = ({ className, children }: BottomNavProps) => { @@ -59,7 +54,6 @@ const BottomNav = ({ className, children }: BottomNavProps) => { return (
{children[selectedIndex]}
- {selectedIndex === 4 && }
{bottomNavItems.map((item, index) => ( { +type ContractInfoProps = { + contract_info: TContractInfo; +}; + +const ContractDetailsFooter = observer(({ contract_info }: ContractInfoProps) => { + const { + bid_price, + currency, + contract_id, + cancellation: { date_expiry: cancellation_date_expiry } = {}, + profit, + contract_type, + } = contract_info; + + const { contract_replay, common } = useStore(); + const { server_time } = common; + const { onClickCancel, onClickSell, is_sell_requested } = contract_replay; + const is_valid_to_sell = isValidToSell(contract_info); + const is_valid_to_cancel = isValidToCancel(contract_info); + const is_multiplier = isMultiplierContract(contract_type); + return (
-
); -}; +}); export default ContractDetailsFooter; diff --git a/packages/trader/src/AppV2/Components/OrderDetails/order-details.tsx b/packages/trader/src/AppV2/Components/OrderDetails/order-details.tsx index ccbc5d33e486..52a21e32b9a7 100644 --- a/packages/trader/src/AppV2/Components/OrderDetails/order-details.tsx +++ b/packages/trader/src/AppV2/Components/OrderDetails/order-details.tsx @@ -14,30 +14,28 @@ const OrderDetails = ({ contract_info }: ContractInfoProps) => { const details = orderDetails ? orderDetails.details : {}; return (
- -
- {Object.entries(details).map(([key, value], index) => ( -
-
- - - -
-
- {Array.isArray(value) ? ( - value.map((val, i) => ( - - {val} - - )) - ) : ( - {value as string | number} - )} -
+
+ {Object.entries(details).map(([key, value], index) => ( +
+
+ + {key} +
- ))} -
- +
+ {Array.isArray(value) ? ( + value.map((val, i) => ( + + {val} + + )) + ) : ( + {value as string | number} + )} +
+
+ ))} +
); }; diff --git a/packages/trader/src/AppV2/Components/RiskManagementItem/risk-management-item.tsx b/packages/trader/src/AppV2/Components/RiskManagementItem/risk-management-item.tsx index 2d175c6f5b5c..33a505aff47a 100644 --- a/packages/trader/src/AppV2/Components/RiskManagementItem/risk-management-item.tsx +++ b/packages/trader/src/AppV2/Components/RiskManagementItem/risk-management-item.tsx @@ -6,31 +6,61 @@ import DealCancellationRemainingTime from '../DealCancellationRemainingTime/deal import { observer } from '@deriv/stores'; import useContractDetails from 'AppV2/Hooks/useContractDetails'; import { CONTRACT_TYPES, isAccumulatorContract, isValidToCancel } from '@deriv/shared'; -import { useTraderStore } from 'Stores/useTraderStores'; type RiskManagementItemProps = { label: React.ReactNode; modal_body_content: React.ReactNode; validation_message?: React.ReactNode; is_deal_cancellation?: boolean; + value?: number | null; + type?: string; }; const RiskManagementItem = observer( - ({ label, modal_body_content, validation_message, is_deal_cancellation = false }: RiskManagementItemProps) => { - const [toggle, setToggle] = React.useState(false); - const [isOpen, setIsOpen] = React.useState(false); - const dummy_boolean = false; // This will be flag from backend - const { has_take_profit } = useTraderStore(); - const { contract_info } = useContractDetails(); + ({ + label, + modal_body_content, + validation_message, + is_deal_cancellation = false, + value, + type, + }: RiskManagementItemProps) => { + const [toggle, setToggle] = React.useState(Boolean(value)); + const [isSheetOpen, setIsSheetOpen] = React.useState(false); + const [isEnabled, setIsEnabled] = React.useState(false); + const dummy_boolean = false; + const [stepperValue, setStepperValue] = React.useState(0); + const { contract_info, contract } = useContractDetails(); const { contract_type, currency } = contract_info; + const { validation_errors, updateLimitOrder, clearContractUpdateConfigValues } = contract; const is_valid_to_cancel = isValidToCancel(contract_info); const is_accumulator = isAccumulatorContract(contract_type); + React.useEffect(() => { + if (value) { + setStepperValue(value); + setToggle(Boolean(value)); + } + return () => clearContractUpdateConfigValues(); + }, [clearContractUpdateConfigValues, value]); + + const isDealCancellation = is_valid_to_cancel; + const finalValue = Math.abs(value as number); + + const errorKey = `contract_update_${type}` as 'contract_update_stop_loss' | 'contract_update_take_profit'; + const errorMessage = validation_errors[errorKey]?.length > 0 ? validation_errors[errorKey][0] : ''; + const info_message = { [CONTRACT_TYPES.ACCUMULATOR]: ( ), - [CONTRACT_TYPES.MULTIPLIER.UP || CONTRACT_TYPES.MULTIPLIER.DOWN]: + [CONTRACT_TYPES.MULTIPLIER.UP]: + is_valid_to_cancel && !is_deal_cancellation ? ( + + ) : ( + '' + ), + [CONTRACT_TYPES.MULTIPLIER.DOWN]: is_valid_to_cancel && !is_deal_cancellation ? ( ) : ( @@ -38,6 +68,42 @@ const RiskManagementItem = observer( ), } as const; + const onChange = ( + e: React.ChangeEvent | { target: { name: string; value: number | string | boolean } } + ) => { + const { value } = e.target; + setStepperValue(value as number); + contract.onChange?.({ + name: `contract_update_${type}`, + value, + }); + }; + + const handleToggleSwitch = (value: boolean) => { + clearContractUpdateConfigValues(); + if (value) { + setIsSheetOpen(true); + setIsEnabled(true); + } else { + contract.onChange?.({ + name: `has_contract_update_${type}`, + value, + }); + updateLimitOrder(); + setToggle(!toggle); + } + }; + + const onSave = () => { + if (isEnabled) { + contract.onChange?.({ + name: `has_contract_update_${type}`, + value: true, + }); + setIsEnabled(false); + } + updateLimitOrder(); + }; return (
@@ -50,44 +116,68 @@ const RiskManagementItem = observer( /> {!is_deal_cancellation && - (has_take_profit && is_accumulator ? ( - 5 USD + (is_accumulator ? ( + + {finalValue} {currency} + ) : ( - setToggle(!toggle)} /> + ))} {is_valid_to_cancel && is_deal_cancellation && }
- {toggle && ( + {!is_accumulator && toggle && ( setIsOpen(true)} - onFocus={() => setIsOpen(true)} + value={`${finalValue.toFixed(2)} ${currency}`} + onClick={() => { + clearContractUpdateConfigValues(); + setStepperValue(finalValue); + setIsSheetOpen(true); + }} + onFocus={() => setIsSheetOpen(true)} /> )} - setIsOpen(false)}> + { + setIsEnabled(false); + setIsSheetOpen(false); + }} + > - + {isSheetOpen && ( + + )} { - //do the save - }, + onAction: onSave, }} /> diff --git a/packages/trader/src/AppV2/Components/StopLoss/stop-loss.tsx b/packages/trader/src/AppV2/Components/StopLoss/stop-loss.tsx index 348327046e73..ff6b62003bc7 100644 --- a/packages/trader/src/AppV2/Components/StopLoss/stop-loss.tsx +++ b/packages/trader/src/AppV2/Components/StopLoss/stop-loss.tsx @@ -7,6 +7,7 @@ import RiskManagementItem from '../RiskManagementItem'; const StopLoss = observer(() => { const { contract_info } = useContractDetails(); + const { limit_order } = contract_info; const { is_stop_loss_visible } = getContractDetailsConfig(contract_info.contract_type ?? ''); return is_stop_loss_visible ? ( @@ -15,6 +16,8 @@ const StopLoss = observer(() => { modal_body_content={ } + value={limit_order?.stop_loss?.order_amount} + type='stop_loss' validation_message='hello' /> ) : null; diff --git a/packages/trader/src/AppV2/Components/TakeProfit/take-profit.tsx b/packages/trader/src/AppV2/Components/TakeProfit/take-profit.tsx index f38ae0728e92..1c82a5b59fc4 100644 --- a/packages/trader/src/AppV2/Components/TakeProfit/take-profit.tsx +++ b/packages/trader/src/AppV2/Components/TakeProfit/take-profit.tsx @@ -7,8 +7,8 @@ import RiskManagementItem from '../RiskManagementItem'; const TakeProfit = observer(() => { const { contract_info } = useContractDetails(); + const { limit_order } = contract_info; const { is_take_profit_visible } = getContractDetailsConfig(contract_info.contract_type ?? ''); - return ( is_take_profit_visible && ( { modal_body_content={ } + value={limit_order?.take_profit?.order_amount} + type='take_profit' validation_message='hello' /> ) diff --git a/packages/trader/src/AppV2/Containers/Chart/chart.scss b/packages/trader/src/AppV2/Containers/Chart/chart.scss index fb44e0aac07f..254c3baba39e 100644 --- a/packages/trader/src/AppV2/Containers/Chart/chart.scss +++ b/packages/trader/src/AppV2/Containers/Chart/chart.scss @@ -1,5 +1,5 @@ .chart-placeholder { - height: 360px; + min-height: 360px; background-color: var(--core-color-solid-grape-100); border: 1px dashed var(--core-color-solid-grape-700); .placeholder-text { diff --git a/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.scss b/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.scss index 0d3b6238d943..487f74cc3cc2 100644 --- a/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.scss +++ b/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.scss @@ -3,10 +3,19 @@ padding: 8px; display: flex; flex-direction: column; + overflow: auto; + height: 100vh; gap: var(--semantic-spacing-general-sm); + padding-bottom: 20px; + &--two-buttons { + padding-bottom: 180px; + } + + &--one-button { + padding-bottom: 90px; + } } .placeholder { - min-height: 100px; margin: 4px 0; background-color: #fff; } diff --git a/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.tsx b/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.tsx index dc7e53300753..61f98a6ce95e 100644 --- a/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.tsx +++ b/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.tsx @@ -12,12 +12,13 @@ import { getContractDetailsConfig } from 'AppV2/Utils/contract-details-config'; import TakeProfit from 'AppV2/Components/TakeProfit/take-profit'; import StopLoss from 'AppV2/Components/StopLoss/stop-loss'; import DealCancellation from 'AppV2/Components/DealCancellation/deal-cancellation'; -import { isOpen } from '@deriv/shared'; +import { hasContractStarted, isForwardStarting, isMultiplierContract, isOpen, isValidToCancel } from '@deriv/shared'; +import classNames from 'classnames'; +import ContractDetailsFooter from 'AppV2/Components/ContractDetailsFooter'; const ContractDetails = observer(() => { const { contract_info, is_loading } = useContractDetails(); if (is_loading) return <>; - const { is_tp_history_visible } = getContractDetailsConfig(contract_info.contract_type ?? ''); const historyData = [ { date: '01 Jan 2024', time: '12:00:00 GMT', action: 'Take profit', amount: '5.00 USD' }, { date: '02 Jan 2024', time: '13:00:00 GMT', action: 'Take profit', amount: '10.00 USD' }, @@ -26,8 +27,21 @@ const ContractDetails = observer(() => { { date: '05 Jan 2024', time: '12:00:00 GMT', action: 'Take profit', amount: '5.00 USD' }, { date: '06 Jan 2024', time: '13:00:00 GMT', action: 'Take profit', amount: '10.00 USD' }, ]; + const is_multiplier = isMultiplierContract(contract_info.contract_type); + const is_valid_to_cancel = isValidToCancel(contract_info); + const should_show_sell = + (hasContractStarted(contract_info) || + isForwardStarting(contract_info?.shortcode ?? '', contract_info.purchase_time)) && + isOpen(contract_info); + const { is_tp_history_visible } = getContractDetailsConfig(contract_info.contract_type ?? ''); + const show_cancel_button = is_multiplier && is_valid_to_cancel; return ( -
+
{/* TODO: remove temp contract card */}
@@ -61,12 +75,13 @@ const ContractDetails = observer(() => { )} -
+ -
+ {is_tp_history_visible && } + {should_show_sell && }
); }); diff --git a/packages/trader/src/AppV2/Hooks/useContractDetails.ts b/packages/trader/src/AppV2/Hooks/useContractDetails.ts index 135e33308dfb..8e31d3cbea8e 100644 --- a/packages/trader/src/AppV2/Hooks/useContractDetails.ts +++ b/packages/trader/src/AppV2/Hooks/useContractDetails.ts @@ -4,10 +4,13 @@ import { useStore } from '@deriv/stores'; const useContractDetails = () => { const store = useStore(); - const { contract_replay } = store; + const { contract_replay, contract_trade } = store; + const { getContractById } = contract_trade; const { contract_store, onMount } = contract_replay; - const location = useLocation(); const { contract_info } = contract_store; + const contract = getContractById(contract_info.contract_id); + + const location = useLocation(); useEffect(() => { if (!contract_info.contract_id) { @@ -21,6 +24,7 @@ const useContractDetails = () => { return { contract_info, + contract, is_loading: !contract_info.contract_id, }; }; diff --git a/packages/trader/src/AppV2/Hooks/useOrderDetails.ts b/packages/trader/src/AppV2/Hooks/useOrderDetails.ts index 24950c810605..e5486eacdc5f 100644 --- a/packages/trader/src/AppV2/Hooks/useOrderDetails.ts +++ b/packages/trader/src/AppV2/Hooks/useOrderDetails.ts @@ -1,4 +1,5 @@ import { + CONTRACT_TYPES, TContractInfo, addComma, getDurationPeriod, @@ -8,7 +9,7 @@ import { isAccumulatorContract, isResetContract, } from '@deriv/shared'; -import { localize } from '@deriv/translations'; +import { Localize, localize } from '@deriv/translations'; import { getBarrierValue } from 'App/Components/Elements/PositionsDrawer/helpers'; // Contains all key values that are used more than once in different transform objects @@ -20,16 +21,16 @@ const getCommonFields = (data: TContractInfo) => { : `${tick_count} ${ticks_label}`; return { - 'Reference ID': [ + [localize('Reference ID')]: [ data.transaction_ids?.buy ? `${data.transaction_ids.buy} (Buy)` : '', data.transaction_ids?.sell ? `${data.transaction_ids.sell} (Sell)` : '', ], - Stake: data.buy_price ? `${data.buy_price.toFixed(2)} ${data.currency}` : '', - Duration: + [localize('Stake')]: data.buy_price ? `${data.buy_price.toFixed(2)} ${data.currency}` : '', + [localize('Duration')]: Number(tick_count) > 0 ? ticks_duration_text : `${getDurationTime(data) ?? ''} ${getDurationUnitText(getDurationPeriod(data)) ?? ''}`, - 'Payout per point': data.display_number_of_contracts ? `${data.display_number_of_contracts}` : '', + [localize('Payout per point')]: data.display_number_of_contracts ? `${data.display_number_of_contracts}` : '', }; }; @@ -37,17 +38,17 @@ const getCommonFields = (data: TContractInfo) => { const transformMultiplierData = (data: TContractInfo) => { const commonFields = getCommonFields(data); return { - 'Reference ID': commonFields['Reference ID'], - Multiplier: data.multiplier ? `x${data.multiplier}` : '', - Stake: commonFields.Stake, - Commission: data.commission ? `${data.commission} ${data.currency}` : '', - 'Take Profit': data.limit_order?.take_profit?.order_amount + [localize('Reference ID')]: commonFields[localize('Reference ID')], + [localize('Multiplier')]: data.multiplier ? `x${data.multiplier}` : '', + [localize('Stake')]: commonFields[localize('Stake')], + [localize('Commission')]: data.commission ? `${data.commission} ${data.currency}` : '', + [localize('Take Profit')]: data.limit_order?.take_profit?.order_amount ? `${data.limit_order.take_profit.order_amount.toFixed(2)} ${data.currency}` - : 'Not set', - 'Stop loss': data.limit_order?.stop_loss?.order_amount + : localize('Not set'), + [localize('Stop loss')]: data.limit_order?.stop_loss?.order_amount ? `${data.limit_order.stop_loss.order_amount.toFixed(2)} ${data.currency}` - : 'Not set', - 'Stop out level': data.limit_order?.stop_out?.order_amount + : localize('Not set'), + [localize('Stop out level')]: data.limit_order?.stop_out?.order_amount ? `${data.limit_order.stop_out.order_amount.toFixed(2)} ${data.currency}` : '', }; @@ -57,10 +58,10 @@ const transformMultiplierData = (data: TContractInfo) => { const transformRiseData = (data: TContractInfo) => { const commonFields = getCommonFields(data); return { - 'Reference ID': commonFields['Reference ID'], - Duration: commonFields.Duration, - Barrier: data.barrier ? data.barrier : '', - Stake: commonFields.Stake, + [localize('Reference ID')]: commonFields[localize('Reference ID')], + [localize('Duration')]: commonFields[localize('Duration')], + [localize('Barrier')]: data.barrier ? data.barrier : '', + [localize('Stake')]: commonFields[localize('Stake')], }; }; @@ -68,14 +69,14 @@ const transformRiseData = (data: TContractInfo) => { const transformTurbosData = (data: TContractInfo) => { const commonFields = getCommonFields(data); return { - 'Reference ID': commonFields['Reference ID'], - Duration: commonFields.Duration, - Barrier: data.barrier ? data.barrier : '', - 'Payout per point': commonFields['Payout per point'], - Stake: commonFields.Stake, - 'Take Profit': data.limit_order?.take_profit?.order_amount + [localize('Reference ID')]: commonFields[localize('Reference ID')], + [localize('Duration')]: commonFields[localize('Duration')], + [localize('Barrier')]: data.barrier ? data.barrier : '', + [localize('Payout per point')]: commonFields[localize('Payout per point')], + [localize('Stake')]: commonFields[localize('Stake')], + [localize('Take Profit')]: data.limit_order?.take_profit?.order_amount ? `${data.limit_order.take_profit.order_amount.toFixed(2)} ${data.currency}` - : 'Not set', + : localize('Not set'), }; }; @@ -83,25 +84,25 @@ const transformTurbosData = (data: TContractInfo) => { const transformMatcherData = (data: TContractInfo) => { const commonFields = getCommonFields(data); return { - 'Reference ID': commonFields['Reference ID'], - Duration: `${getDurationTime(data) ?? ''} ${getDurationUnitText(getDurationPeriod(data)) ?? ''}`, - Target: getBarrierValue(data), - Stake: commonFields.Stake, + [localize('Reference ID')]: commonFields[localize('Reference ID')], + [localize('Duration')]: `${getDurationTime(data) ?? ''} ${getDurationUnitText(getDurationPeriod(data)) ?? ''}`, + [localize('Target')]: getBarrierValue(data), + [localize('Stake')]: commonFields[localize('Stake')], }; }; - // For Accumulators const transformAccumulatorData = (data: TContractInfo) => { const commonFields = getCommonFields(data); return { - 'Reference ID': commonFields['Reference ID'], - 'Growth rate': data.growth_rate ? `${getGrowthRatePercentage(data.growth_rate)}%` : '', - Stake: commonFields.Stake, + [localize('Reference ID')]: commonFields[localize('Reference ID')], + [localize('Growth rate')]: data.growth_rate ? `${getGrowthRatePercentage(data.growth_rate)}%` : '', + [localize('Duration')]: `${getDurationTime(data) ?? ''} ${getDurationUnitText(getDurationPeriod(data)) ?? ''}`, + [localize('Stake')]: commonFields[localize('Stake')], ...{ ...(data.limit_order?.take_profit && { - 'Take Profit': data.limit_order?.take_profit?.order_amount + [localize('Take Profit')]: data.limit_order?.take_profit?.order_amount ? `${data.limit_order.take_profit.order_amount} ${data.currency}` - : 'Not set', + : localize('Not set'), }), }, }; @@ -111,42 +112,42 @@ const transformAccumulatorData = (data: TContractInfo) => { const transformVanillaData = (data: TContractInfo) => { const commonFields = getCommonFields(data); return { - 'Reference ID': commonFields['Reference ID'], - 'Strike Price': + [localize('Reference ID')]: commonFields[localize('Reference ID')], + [localize('Strike Price')]: (isResetContract(data.contract_type) ? addComma(data.entry_spot_display_value) : getBarrierValue(data)) || ' - ', - Duration: `${getDurationTime(data) ?? ''} ${getDurationUnitText(getDurationPeriod(data)) ?? ''}`, - 'Payout per point': commonFields['Payout per point'], - Stake: commonFields.Stake, + [localize('Duration')]: `${getDurationTime(data) ?? ''} ${getDurationUnitText(getDurationPeriod(data)) ?? ''}`, + [localize('Payout per point')]: commonFields[localize('Payout per point')], + [localize('Stake')]: commonFields[localize('Stake')], }; }; // Map of contract types to their respective transform functions const transformFunctionMap: Record Record> = { - TURBOSLONG: transformTurbosData, - TURBOSSHORT: transformTurbosData, - MULTDOWN: transformMultiplierData, - MULTUP: transformMultiplierData, - DIGITMATCH: transformMatcherData, - DIGITDIFF: transformMatcherData, - DIGITEVEN: transformMatcherData, - DIGITODD: transformMatcherData, - DIGITOVER: transformMatcherData, - DIGITUNDER: transformMatcherData, - CALL: transformRiseData, - PUT: transformRiseData, - ONETOUCH: transformRiseData, - NOTOUCH: transformRiseData, - ACCU: transformAccumulatorData, - VANILLALONGCALL: transformVanillaData, - VANILLALONGPUT: transformVanillaData, + [CONTRACT_TYPES.TURBOS.LONG]: transformTurbosData, + [CONTRACT_TYPES.TURBOS.SHORT]: transformTurbosData, + [CONTRACT_TYPES.MULTIPLIER.DOWN]: transformMultiplierData, + [CONTRACT_TYPES.MULTIPLIER.UP]: transformMultiplierData, + [CONTRACT_TYPES.MATCH_DIFF.MATCH]: transformMatcherData, + [CONTRACT_TYPES.MATCH_DIFF.DIFF]: transformMatcherData, + [CONTRACT_TYPES.EVEN_ODD.EVEN]: transformMatcherData, + [CONTRACT_TYPES.EVEN_ODD.ODD]: transformMatcherData, + [CONTRACT_TYPES.OVER_UNDER.OVER]: transformMatcherData, + [CONTRACT_TYPES.OVER_UNDER.UNDER]: transformMatcherData, + [CONTRACT_TYPES.RESET.CALL]: transformRiseData, + [CONTRACT_TYPES.PUT]: transformRiseData, + [CONTRACT_TYPES.CALL]: transformRiseData, + [CONTRACT_TYPES.TOUCH.ONE_TOUCH]: transformRiseData, + [CONTRACT_TYPES.TOUCH.NO_TOUCH]: transformRiseData, + [CONTRACT_TYPES.ACCUMULATOR]: transformAccumulatorData, + [CONTRACT_TYPES.VANILLA.CALL]: transformVanillaData, + [CONTRACT_TYPES.VANILLA.PUT]: transformVanillaData, }; const useOrderDetails = (contract_info: TContractInfo) => { const contractInfo = contract_info; if (!contractInfo.contract_type) return; - const transformFunction = transformFunctionMap[contractInfo.contract_type]; const details = transformFunction ? transformFunction(contractInfo) : {}; diff --git a/packages/trader/src/AppV2/Utils/contract-details-config.ts b/packages/trader/src/AppV2/Utils/contract-details-config.ts index c10fb80a1eec..8fce879d0048 100644 --- a/packages/trader/src/AppV2/Utils/contract-details-config.ts +++ b/packages/trader/src/AppV2/Utils/contract-details-config.ts @@ -15,13 +15,25 @@ export const getContractDetailsConfig = (contract_type: string) => { is_stop_loss_visible: false, is_tp_history_visible: true, }, - [CONTRACT_TYPES.MULTIPLIER.UP || CONTRACT_TYPES.MULTIPLIER.DOWN]: { + [CONTRACT_TYPES.MULTIPLIER.UP]: { is_take_profit_visible: true, is_deal_cancellation_visible: true, is_stop_loss_visible: true, is_tp_history_visible: true, }, - [CONTRACT_TYPES.TURBOS.LONG || CONTRACT_TYPES.TURBOS.SHORT]: { + [CONTRACT_TYPES.MULTIPLIER.DOWN]: { + is_take_profit_visible: true, + is_deal_cancellation_visible: true, + is_stop_loss_visible: true, + is_tp_history_visible: true, + }, + [CONTRACT_TYPES.TURBOS.LONG]: { + is_take_profit_visible: true, + is_deal_cancellation_visible: false, + is_stop_loss_visible: false, + is_tp_history_visible: true, + }, + [CONTRACT_TYPES.TURBOS.SHORT]: { is_take_profit_visible: true, is_deal_cancellation_visible: false, is_stop_loss_visible: false, diff --git a/packages/trader/src/AppV2/Utils/helper.ts b/packages/trader/src/AppV2/Utils/helper.ts new file mode 100644 index 000000000000..eae745b55c06 --- /dev/null +++ b/packages/trader/src/AppV2/Utils/helper.ts @@ -0,0 +1,22 @@ +import { TGetCardLables } from '@deriv/components'; +import { formatDuration, getDiffDuration } from '@deriv/shared'; + +type TRemainingTimeProps = { + end_time?: number; + start_time: moment.Moment; + format?: string; + getCardLabels: TGetCardLables; +}; + +export const getRemainingTime = ({ end_time, format, getCardLabels, start_time }: TRemainingTimeProps) => { + if (!end_time || start_time.unix() > +end_time) { + return; + } + + const { days, timestamp } = formatDuration(getDiffDuration(start_time.unix(), end_time), format); + let remaining_time = timestamp; + if (days > 0) { + remaining_time = `${days} ${days > 1 ? getCardLabels().DAYS : getCardLabels().DAY} ${timestamp}`; + } + return remaining_time; +}; diff --git a/packages/trader/src/AppV2/app.tsx b/packages/trader/src/AppV2/app.tsx index e83b82de0ea6..c88dc83488c3 100644 --- a/packages/trader/src/AppV2/app.tsx +++ b/packages/trader/src/AppV2/app.tsx @@ -12,6 +12,7 @@ import { NotificationsProvider } from '@deriv-com/quill-ui'; import 'Sass/app.scss'; import ContractDetails from './Containers/ContractDetails'; import '@deriv-com/quill-tokens/dist/quill.css'; +import { useLocation } from 'react-router'; import Notifications from './Containers/Notifications'; type Apptypes = { @@ -26,17 +27,21 @@ const App = ({ passthrough }: Apptypes) => { React.useEffect(() => { return () => root_store.ui.setPromptHandler(false); }, [root_store]); - + const location = useLocation(); return ( - - - - - - + {location.pathname.includes('/contract/') ? ( + + ) : ( + + + + + + + )} );