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

Kate / DTRA-378 / TS migration: Multiplier components and containers in Trader package #26

Conversation

kate-deriv
Copy link
Owner

Changes:

  • TS migration
  • Refactoring

Screenshots:

Please provide some screenshots of the change.

@coveralls
Copy link

coveralls commented Aug 30, 2023

Pull Request Test Coverage Report for Build 6037712395

  • 0 of 33 (0.0%) changed or added relevant lines in 6 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.002%) to 10.043%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/components/src/components/dialog/dialog.tsx 0 1 0.0%
packages/trader/src/Modules/Trading/Components/Form/TradeParams/amount-mobile.tsx 0 3 0.0%
packages/trader/src/Modules/Trading/Components/Elements/Multiplier/cancel-deal-mobile.tsx 0 5 0.0%
packages/trader/src/Modules/Trading/Containers/Multiplier/multiplier-options.tsx 0 5 0.0%
packages/trader/src/Modules/Trading/Containers/Multiplier/risk-management-dialog.tsx 0 9 0.0%
packages/trader/src/Modules/Trading/Containers/Multiplier/multiplier-amount-modal.tsx 0 10 0.0%
Files with Coverage Reduction New Missed Lines %
packages/cfd/src/Containers/cfd-password-modal.tsx 1 76.76%
Totals Coverage Status
Change from base Build 5961064117: -0.002%
Covered Lines: 10125
Relevant Lines: 84444

💛 - Coveralls

@@ -98,7 +98,7 @@ const Dialog = ({
}
};

const validateClickOutside = () => dismissable || (has_close_icon && is_visible && is_closed_on_cancel);
const validateClickOutside = () => !!dismissable || !!(has_close_icon && is_visible && is_closed_on_cancel);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function validateClickOutside is passed as an argument inside of useOnClickOutside hook. This hook is expecting function, which is returning boolean.


return (
<React.Fragment>
<Modal
id='dt_trade_parameters_mobile'
className='trade-params'
enableApp={enableApp}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<Modal /> is not expecting enableApp and disableApp props

@@ -76,7 +78,7 @@ const TradeParamsMobile = observer(({ toggleModal }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [stake_value]);

const setSelectedAmount = (basis, stake) => {
Copy link
Owner Author

@kate-deriv kate-deriv Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter basis isn't used inside of the function, but I didn't remove it because <AmountMobile /> is waiting for function with 2 params. Type of function inside of <AmountMobile /> is better not to change, because other components which are used <AmountMobile /> passed function with 2 params

@@ -104,10 +106,10 @@ const TradeParamsMobile = observer(({ toggleModal }) => {
toggleModal={toggleModal}
amount_tab_idx={0}
setSelectedAmount={setSelectedAmount}
setAmountError={() => {}}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this param optional in order not to pass 'empty' function

setState(applied_risk_management_state);
onClose(...args);
onClose();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onClose function is actually a () => setDialogOpen(false) (passed as a props from risk-management-info.tsx), so there is no need in ...args

@github-actions
Copy link

github-actions bot commented Aug 30, 2023

Generating Lighthouse report...

@@ -127,11 +127,14 @@ const Basis = observer(
}
);

type TAmountMobile = React.ComponentProps<typeof Basis> & {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need all props from <Basis />

@@ -314,8 +314,6 @@ const TradeParamsMobile = observer(
setAmountError={setAmountError}
stake_value={stake_value}
payout_value={payout_value}
basis={''}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this params optional

const { name, value } = e.target;
const new_state = { ...state };
new_state[name] = value;
new_state[name as 'take_profit' | 'stop_loss' | 'cancellation_duration'] = value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new_state[name as 'take_profit' | 'stop_loss' | 'cancellation_duration'] = value;
new_state[name as keyof typeof new_state] = value;

will this work?)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it wouldn't :(
Reason: new_state was created based on state object, which type is ⤵️

state: {
    take_profit: string | undefined;
    stop_loss: string | undefined;
    has_take_profit: boolean;
    has_stop_loss: boolean;
    has_cancellation: boolean;
    cancellation_duration: string;
}

So, some of the fields are boolean and a value (from e.target) is a string. And here comes an error, that string is not assignable to that type (which includes boolean). That is why I used union type

const stake_ref = React.useRef(amount);
const [stake_value, setStakeValue] = React.useState<string | number>(amount);
const [commission, setCommission] = React.useState<number | null>();
const [stop_out, setStopOut] = React.useState<number | null>();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commission and stop_out are passed as a props to <MultipliersInfo />, where there is a check if they exists (e.g. props.multiplier ?? ...). So it seems safe not to set default value as null, but to do it undefined. In this case there is no error with TTradeStore['onProposalResponse'], because there commission and stop_out can be number | null | undefined

@kate-deriv kate-deriv merged commit eba9fff into kate/ts_migration_trader_package_5 Sep 1, 2023
2 of 3 checks passed
kate-deriv added a commit that referenced this pull request Oct 11, 2023
* fix: ts-migrate trade-params

* fix: sonarcloud

* fix: pull in changes from tech debt 2 package

* fix: resolve comments

* fix: move type to common prop types

* fix: move type to common prop types

* fix: move type to common prop types file

* fix: resolve comments

* Kate / DTRA-321 / TS migration of trade-params and trade-params-mobile (#6)

* refactor: migrate trade params and started mobile version

* refactor: ts migration of trade params mobile

* chore: add nessasary prop

* refactor: apply suggestions

* chore: change todo text

* refactor: add import

* fix: circleCI error

* fix: ts migrate trade-footer-extensions.jsx

* fix: fix import

* fix: remove progress-slider-stream since its not used

* fix: resolve comments

* fix: reset with master

* fix: reset with master

* fix: reset with master

* fix: reset with master

* fix: circleCI

* fix: togglePositions folder

* fix: dtra-346 marketisclosed and marketcountdowntimer migration

* fix: bug

* Maryia/dtra-270/TS migration: trade-store (#5)

* chore: prepare for migration

* chore: add more types to trade-store

* chore: add more types to trade-store

* chore: add more types to trade-store

* chore: add more types to trade-store

* chore: migrated trade-store to ts

* chore: improve types in trade-store

* fix: type

* revert: hooks package installation

* refactor: address review

* fix: resolve comments

* feat: add ts migartion of store

* refactor: add prev changes

* chore: empty commit

* fix: add lost mocked

* fix: resolve comments

* Kate / DTRA-354 / Components/Form/Purchase files in Trader package (#21)

* refactor: ts migartion of purchase files

* refactor: remove duplicated types

* refactor: apply suggestions

* maryia/fix: sonarcloud warnings (#7)

* fix: sonarcloud warnings

* fix: Unexpected end of JSON input

* fix: bug

* fix: sonarcloud

* fix: reorder props

* fix: test cases

* fix: coveralls

* fix: coveralls

* fix: this component doesnt exist anymore, hence test was also removed

* henry/dtra-356/fix: ts-migration-digitsJSX (#24)

* fix: initial commit

* fix: ts migrate digits JSX

* fix: small type change

* fix: comment

* chore: removed unused state

* Maryia/dtra-355/Migrate ContractDrawer files to TS (#22)

* feat: migrated swipeable-components to TS

* feat: migrated market-closed-contract-overlay & index to TS

* chore: migrated contract-drawer-card.tsx to ts

* build: fix type

* chore: migrated contract-drawer to ts

* chore: fixed existing types in digits and logic

* chore: sort types properties in alphabetical order

* Kate/dtra 357/ts contract audit files (#23)

* refactor: apply suggestion from prev pr

* refactor: start ts migration of contract audit

* chore: change comment

* refactor: ts of contract audit item

* refactor: ts migration of contract details

* refactor: ts migration of contract history

* refactor: add preprepared types

* refactor: tests

* chore: apply nit

* refactor: apply suggestions

* refactor: apply suggestions

* chore: fix of sonar cloud

* Maryia/dtra-373/remove localize from ContractCardHeader component (#25)

* refactor: remove localize from contract-card-header

* refactor: use Localize component instead of localize helper

* build: install RTL deps in shared package

* feat: merge previous tech debt branch

* fix: sonar cloud codesmells

* Merge branch kate/ts_migration_trader_package_4 into kate/ts_migration_trader_package_5

* Kate / DTRA-378 / TS migration: Multiplier components and containers in Trader package (#26)

* refactor: ts of cancel deal and risk managment info

* fix: types in dialog tsx

* refactor: start ts of multiplier options

* refactor: ts of mult amount modal

* refactor: remove default val from basis component

* fix: type of amount mobile

* refactor: applied suggestions

* refactor: ts of multiplier info (#28)

* Henry/dtra 376/fix: ts migration positionsdrawer folder (#27)

* fix: positions drawer folder

* fix: coveralls

* fix: where is my commit

* fix: found commits

* fix: file rename

* fix: comments

* fix: comments

* fix: correct logic

* fix: remove unused props

* fix: types

* refactor: remove code mells

* fix: ts-migrate-populate header (#30)

* Maryia/DTRA-377/TS migration: TradingDatePicker + TradingTimePicker + TimePicker + Dialog (#29)

* chore: timepicker to ts

* chore: trading timepicker to ts

* chore: add types for TradingDatePicker & DatePicker

* refactor: added default values

* refactor: remove code small

* chore: empty commit

* fix: not using index as key (#31)

* fix: ternary bug

* fix: build TS errors (#32)

* refactor: apply suggestions

* refactor: change type of time

* chore: empty commit

* refactor: tests

* fix: conflicts

* fix: conflicts

* fix: tests

* fix: types in tests

* fix: test extention

* fix: add turbos to types back

* fix: add backup for target name

* fix: revert empty strings

---------

Co-authored-by: Henry Hein <henry@regentmarkets.com>
Co-authored-by: Maryia <103177211+maryia-deriv@users.noreply.github.com>
Co-authored-by: henry-deriv <118344354+henry-deriv@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants