From 98513f25ecabcea94fb01939af3a1933b6c72d2c Mon Sep 17 00:00:00 2001 From: Henry Hein Date: Thu, 9 Mar 2023 14:32:42 +0800 Subject: [PATCH 1/7] fix: TS migration Positions Drawer Card --- ...wer-card.jsx => positions-drawer-card.tsx} | 92 +++++++++---------- .../src/utils/contract/contract-types.ts | 2 + packages/shared/src/utils/helpers/logic.ts | 5 +- 3 files changed, 51 insertions(+), 48 deletions(-) rename packages/components/src/components/positions-drawer-card/{positions-drawer-card.jsx => positions-drawer-card.tsx} (78%) diff --git a/packages/components/src/components/positions-drawer-card/positions-drawer-card.jsx b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx similarity index 78% rename from packages/components/src/components/positions-drawer-card/positions-drawer-card.jsx rename to packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx index 69ab1c1b4d08..8b7fb507e3d7 100644 --- a/packages/components/src/components/positions-drawer-card/positions-drawer-card.jsx +++ b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx @@ -1,5 +1,4 @@ import classNames from 'classnames'; -import PropTypes from 'prop-types'; import React from 'react'; import { NavLink } from 'react-router-dom'; import ContractCard from '../contract-card'; @@ -11,15 +10,56 @@ import { getContractTypeDisplay, getEndTime, } from '@deriv/shared'; +import type { ContractUpdate } from '@deriv/api-types'; +import moment from 'moment'; + +type TToastConfig = { + key?: number; + content: string; + timeout?: number; + is_bottom?: boolean; + type?: string; +}; + +type TPositionsDrawerCardProps = { + addToast: (toast_config: TToastConfig) => void; + className?: string; + contract_info: Parameters[0]; + contract_update: ContractUpdate; + currency: string; + current_focus: string; + display_name: string; + getContractById: (contract_id: string) => unknown; //// + is_mobile: boolean; + is_sell_requested: boolean; + is_unsupported: boolean; + is_link_disabled: boolean; + profit_loss: number; + onClickCancel: (contract_id: string) => void; + onClickSell: (contract_id: string) => void; + onClickRemove: () => void; + onFooterEntered: () => void; + onMouseEnter: () => void; + onMouseLeave: () => void; + removeToast: (key: number) => void; + result: string; + setCurrentFocus: (value: string) => void; + server_time: moment.Moment; + should_show_transition: boolean; + should_show_cancellation_warning: boolean; + status: string; + toggleCancellationWarning: (value: boolean) => void; + toggleUnsupportedContractModal: (value: boolean) => void; +}; const PositionsDrawerCard = ({ addToast, className, - display_name, contract_info, contract_update, currency, current_focus, + display_name, getContractById, is_mobile, is_sell_requested, @@ -41,9 +81,9 @@ const PositionsDrawerCard = ({ status, toggleCancellationWarning, toggleUnsupportedContractModal, -}) => { - const is_multiplier = isMultiplierContract(contract_info.contract_type); - const is_crypto = isCryptoContract(contract_info.underlying); +}: TPositionsDrawerCardProps) => { + const is_multiplier = isMultiplierContract(contract_info.contract_type || ''); + const is_crypto = isCryptoContract(contract_info.underlying || ''); const has_progress_slider = !is_multiplier || (is_crypto && is_multiplier); const has_ended = !!getEndTime(contract_info); @@ -61,7 +101,6 @@ const PositionsDrawerCard = ({ getContractTypeDisplay={getContractTypeDisplay} has_progress_slider={!is_mobile && has_progress_slider} is_mobile={is_mobile} - is_positions={true} is_sell_requested={is_sell_requested} onClickSell={onClickSell} server_time={server_time} @@ -184,45 +223,4 @@ const PositionsDrawerCard = ({ ); }; -PositionsDrawerCard.propTypes = { - addToast: PropTypes.func, - className: PropTypes.string, - contract_info: PropTypes.object, - contract_update: PropTypes.object, - currency: PropTypes.string, - current_focus: PropTypes.string, - current_tick: PropTypes.number, - display_name: PropTypes.string, - duration: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), - duration_unit: PropTypes.string, - exit_spot: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), - getContractById: PropTypes.func, - id: PropTypes.number, - indicative: PropTypes.number, - is_link_disabled: PropTypes.bool, - is_loading: PropTypes.bool, - is_mobile: PropTypes.bool, - is_sell_requested: PropTypes.bool, - is_unsupported: PropTypes.bool, - is_valid_to_sell: PropTypes.oneOfType([PropTypes.number, PropTypes.bool]), - onClickRemove: PropTypes.func, - onClickSell: PropTypes.func, - onClickCancel: PropTypes.func, - onFooterEntered: PropTypes.func, - onMouseEnter: PropTypes.func, - onMouseLeave: PropTypes.func, - profit_loss: PropTypes.number, - removeToast: PropTypes.func, - result: PropTypes.string, - sell_time: PropTypes.number, - server_time: PropTypes.object, - setCurrentFocus: PropTypes.func, - should_show_cancellation_warning: PropTypes.bool, - should_show_transition: PropTypes.bool, - status: PropTypes.string, - toggleCancellationWarning: PropTypes.func, - toggleUnsupportedContractModal: PropTypes.func, - type: PropTypes.string, -}; - export default PositionsDrawerCard; diff --git a/packages/shared/src/utils/contract/contract-types.ts b/packages/shared/src/utils/contract/contract-types.ts index 5af91ba65d80..534bce5a4d04 100644 --- a/packages/shared/src/utils/contract/contract-types.ts +++ b/packages/shared/src/utils/contract/contract-types.ts @@ -32,6 +32,8 @@ export type TContractInfo = { current_spot?: number; barrier?: string; contract_type?: string; + underlying?: string; + contract_id?: string; exit_tick_time?: number; date_expiry?: number; is_path_dependent?: 0 | 1; diff --git a/packages/shared/src/utils/helpers/logic.ts b/packages/shared/src/utils/helpers/logic.ts index 78c7fdb3e1bb..2cc8c1d5f0a2 100644 --- a/packages/shared/src/utils/helpers/logic.ts +++ b/packages/shared/src/utils/helpers/logic.ts @@ -24,7 +24,10 @@ type TIsSoldBeforeStart = Required>; -type TGetEndTime = Pick & +type TGetEndTime = Pick< + TContractInfo, + 'is_expired' | 'sell_time' | 'status' | 'tick_count' | 'contract_type' | 'underlying' | 'contract_id' +> & Required>; type TGetBuyPrice = { From 868622c3df01508449744d9bdd7f9ec7fc8cf451 Mon Sep 17 00:00:00 2001 From: Henry Hein Date: Thu, 9 Mar 2023 14:44:12 +0800 Subject: [PATCH 2/7] fix: handle circleCI error --- .../components/positions-drawer-card/positions-drawer-card.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx index 8b7fb507e3d7..ac88b3217d64 100644 --- a/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx +++ b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx @@ -29,7 +29,7 @@ type TPositionsDrawerCardProps = { currency: string; current_focus: string; display_name: string; - getContractById: (contract_id: string) => unknown; //// + getContractById: (contract_id: string) => Record; is_mobile: boolean; is_sell_requested: boolean; is_unsupported: boolean; From 3bf14d5d79375d2ef6f427ac75a6e8c7015343b1 Mon Sep 17 00:00:00 2001 From: Henry Hein Date: Thu, 9 Mar 2023 15:08:20 +0800 Subject: [PATCH 3/7] fix: circlci --- .../components/positions-drawer-card/positions-drawer-card.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx index ac88b3217d64..37822f43046c 100644 --- a/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx +++ b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx @@ -29,7 +29,7 @@ type TPositionsDrawerCardProps = { currency: string; current_focus: string; display_name: string; - getContractById: (contract_id: string) => Record; + getContractById: (contract_id: string) => Record; is_mobile: boolean; is_sell_requested: boolean; is_unsupported: boolean; From 2b10b7290f878e984db49d69dd2b09d353d18c2f Mon Sep 17 00:00:00 2001 From: Henry Hein Date: Thu, 9 Mar 2023 16:56:19 +0800 Subject: [PATCH 4/7] fix: CirclCi issues --- .../positions-drawer-card/positions-drawer-card.tsx | 9 ++++++++- packages/shared/src/utils/contract/contract-types.ts | 3 --- packages/shared/src/utils/helpers/logic.ts | 5 +---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx index 37822f43046c..c55fe0922fb9 100644 --- a/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx +++ b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx @@ -10,6 +10,7 @@ import { getContractTypeDisplay, getEndTime, } from '@deriv/shared'; +import { TContractInfo } from '@deriv/shared/src/utils/contract/contract-types'; import type { ContractUpdate } from '@deriv/api-types'; import moment from 'moment'; @@ -21,10 +22,16 @@ type TToastConfig = { type?: string; }; +type TGetEndTime = Pick< + TContractInfo, + 'is_expired' | 'sell_time' | 'status' | 'tick_count' | 'contract_type' | 'underlying' | 'contract_id' +> & + Required>; + type TPositionsDrawerCardProps = { addToast: (toast_config: TToastConfig) => void; className?: string; - contract_info: Parameters[0]; + contract_info: TGetEndTime; contract_update: ContractUpdate; currency: string; current_focus: string; diff --git a/packages/shared/src/utils/contract/contract-types.ts b/packages/shared/src/utils/contract/contract-types.ts index 534bce5a4d04..4ed9192a9795 100644 --- a/packages/shared/src/utils/contract/contract-types.ts +++ b/packages/shared/src/utils/contract/contract-types.ts @@ -31,9 +31,6 @@ export type TContractInfo = { current_spot_time?: number; current_spot?: number; barrier?: string; - contract_type?: string; - underlying?: string; - contract_id?: string; exit_tick_time?: number; date_expiry?: number; is_path_dependent?: 0 | 1; diff --git a/packages/shared/src/utils/helpers/logic.ts b/packages/shared/src/utils/helpers/logic.ts index 2cc8c1d5f0a2..78c7fdb3e1bb 100644 --- a/packages/shared/src/utils/helpers/logic.ts +++ b/packages/shared/src/utils/helpers/logic.ts @@ -24,10 +24,7 @@ type TIsSoldBeforeStart = Required>; -type TGetEndTime = Pick< - TContractInfo, - 'is_expired' | 'sell_time' | 'status' | 'tick_count' | 'contract_type' | 'underlying' | 'contract_id' -> & +type TGetEndTime = Pick & Required>; type TGetBuyPrice = { From a057ce4a1e8251bb0e46e2a27b67c85527251cba Mon Sep 17 00:00:00 2001 From: Henry Hein Date: Thu, 9 Mar 2023 16:58:05 +0800 Subject: [PATCH 5/7] fix: CirclCi issues --- packages/shared/src/utils/contract/contract-types.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/shared/src/utils/contract/contract-types.ts b/packages/shared/src/utils/contract/contract-types.ts index 4ed9192a9795..534bce5a4d04 100644 --- a/packages/shared/src/utils/contract/contract-types.ts +++ b/packages/shared/src/utils/contract/contract-types.ts @@ -31,6 +31,9 @@ export type TContractInfo = { current_spot_time?: number; current_spot?: number; barrier?: string; + contract_type?: string; + underlying?: string; + contract_id?: string; exit_tick_time?: number; date_expiry?: number; is_path_dependent?: 0 | 1; From 4d2355a8bc2a9942c92195468dc62f6f6d282fed Mon Sep 17 00:00:00 2001 From: henry-deriv <118344354+henry-deriv@users.noreply.github.com> Date: Mon, 13 Mar 2023 11:11:57 +0800 Subject: [PATCH 6/7] Update packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx Co-authored-by: Jim Daniels Wasswa <104334373+jim-deriv@users.noreply.github.com> --- .../components/positions-drawer-card/positions-drawer-card.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx index c55fe0922fb9..5ebf6cc77de4 100644 --- a/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx +++ b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx @@ -44,7 +44,7 @@ type TPositionsDrawerCardProps = { profit_loss: number; onClickCancel: (contract_id: string) => void; onClickSell: (contract_id: string) => void; - onClickRemove: () => void; + onClickRemove?: () => void; onFooterEntered: () => void; onMouseEnter: () => void; onMouseLeave: () => void; From 68ac4e5b5ac931e22567b15f3a410a2edc7ae1b9 Mon Sep 17 00:00:00 2001 From: henry-deriv <118344354+henry-deriv@users.noreply.github.com> Date: Mon, 13 Mar 2023 11:12:06 +0800 Subject: [PATCH 7/7] Update packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx Co-authored-by: Jim Daniels Wasswa <104334373+jim-deriv@users.noreply.github.com> --- .../positions-drawer-card/positions-drawer-card.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx index 5ebf6cc77de4..ec350cebe6e7 100644 --- a/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx +++ b/packages/components/src/components/positions-drawer-card/positions-drawer-card.tsx @@ -46,8 +46,8 @@ type TPositionsDrawerCardProps = { onClickSell: (contract_id: string) => void; onClickRemove?: () => void; onFooterEntered: () => void; - onMouseEnter: () => void; - onMouseLeave: () => void; + onMouseEnter?: () => void; + onMouseLeave?: () => void; removeToast: (key: number) => void; result: string; setCurrentFocus: (value: string) => void;