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

[DTRA]/Ahmad/DTRA-1490/Deal Cancellation Status Fix Trader-V2 #16121

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
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