Skip to content

Commit

Permalink
[DTRA]/Ahmad/DTRA-1490/Deal Cancellation Status Fix Trader-V2 (#16121)
Browse files Browse the repository at this point in the history
* fix: cancellation active, executed and expired

* chore: revert last commit
  • Loading branch information
ahmadtaimoor-deriv committed Aug 5, 2024
1 parent 640cde4 commit b5bcb99
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/shared/src/utils/constants/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ export const getCardLabelsV2 = () =>
NOT_SET: localize('Not set'),
PAYOUT: localize('Sell price'),
ACTIVE: localize('active'),
EXECUTED: localize('executed'),
EXPIRED: localize('expired'),
PAYOUT_PER_POINT: localize('Payout per point'),
POTENTIAL_PAYOUT: localize('Potential payout'),
POTENTIAL_PROFIT_LOSS: localize('Potential profit/loss'),
Expand Down
25 changes: 20 additions & 5 deletions packages/trader/src/AppV2/Hooks/useOrderDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,28 @@ import {
isResetContract,
getCardLabelsV2,
formatMoney,
isUserCancelled,
} from '@deriv/shared';
import { getBarrierValue } from 'App/Components/Elements/PositionsDrawer/helpers';
import { isCancellationExpired } from 'Stores/Modules/Trading/Helpers/logic';

const CARD_LABELS = getCardLabelsV2();

const getDealCancelFee = (data: TContractInfo) => {
if (!data.cancellation?.ask_price || !data.currency) return undefined;

let status;
if (isUserCancelled(data)) {
status = CARD_LABELS.EXECUTED;
} else if (isCancellationExpired(data)) {
status = CARD_LABELS.EXPIRED;
} else {
status = CARD_LABELS.ACTIVE;
}

return [`${formatMoney(data.currency, data.cancellation.ask_price, true)} ${data.currency}`, `(${status})`];
};

// Contains all key values that are used more than once in different transform objects
const getCommonFields = (data: TContractInfo) => {
const { tick_count, tick_passed, contract_type } = data;
Expand Down Expand Up @@ -42,16 +59,14 @@ const getCommonFields = (data: TContractInfo) => {
// For Multiplier
const transformMultiplierData = (data: TContractInfo) => {
const commonFields = getCommonFields(data);
const dealCancelFee = getDealCancelFee(data);

return {
[CARD_LABELS.REFERENCE_ID]: commonFields[CARD_LABELS.REFERENCE_ID],
[CARD_LABELS.MULTIPLIER]: data.multiplier ? `x${data.multiplier}` : '',
[CARD_LABELS.STAKE]: commonFields[CARD_LABELS.STAKE],
[CARD_LABELS.COMMISSION]: data.commission ? `${data.commission} ${data.currency}` : '',
...{
...(data.cancellation?.ask_price && {
[CARD_LABELS.DEAL_CANCEL_FEE]: [data.cancellation?.ask_price, `(${CARD_LABELS.ACTIVE})`],
}),
},
...(dealCancelFee && { [CARD_LABELS.DEAL_CANCEL_FEE]: dealCancelFee }),
[CARD_LABELS.TAKE_PROFIT]:
data.limit_order?.take_profit?.order_amount && data.currency
? `${formatMoney(data.currency, data.limit_order.take_profit.order_amount, true)} ${data.currency}`
Expand Down

0 comments on commit b5bcb99

Please sign in to comment.