Skip to content

Commit

Permalink
Maryia/dtra-270/TS migration: trade-store (#5)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
maryia-deriv committed Aug 9, 2023
1 parent 8a31dd4 commit 5e341bd
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 332 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/shared/src/utils/digital-options/digital-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type TShowError = {
message: string;
header: string;
redirect_label: string;
redirectOnClick: (() => void) | null;
redirectOnClick?: (() => void) | null;
should_show_refresh: boolean;
redirect_to: string;
should_clear_error_on_click: boolean;
Expand All @@ -25,8 +25,8 @@ type TAccounts = {
export const showDigitalOptionsUnavailableError = (
showError: (t: TShowError) => void,
message: TMessage,
redirectOnClick: (() => void) | null,
should_redirect: boolean,
redirectOnClick?: (() => void) | null,
should_redirect = false,
should_clear_error_on_click = true
) => {
const { title, text, link } = message;
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/utils/helpers/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ export const hasIntradayDurationUnit = (duration_units_list: TUnit[]) => {
* On switching symbols, end_time value of volatility indices should be set to today
*
* @param {String} symbol
* @param {String} expiry_type
* @param {String | null} expiry_type
* @returns {*}
*/
export const resetEndTimeOnVolatilityIndices = (symbol: string, expiry_type: string) =>
export const resetEndTimeOnVolatilityIndices = (symbol: string, expiry_type: string | null) =>
/^R_/.test(symbol) && expiry_type === 'endtime' ? toMoment(null).format('DD MMM YYYY') : null;

export const getDurationMinMaxValues = (
Expand Down
1 change: 1 addition & 0 deletions packages/trader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"devDependencies": {
"@babel/eslint-parser": "^7.17.0",
"@babel/preset-react": "^7.16.7",
"@types/lodash.debounce": "^4.0.7",
"@types/react": "^18.0.7",
"@types/react-dom": "^18.0.0",
"babel-loader": "^8.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ type TBasis = {
setAmountError: (has_error: boolean) => void;
};

type TObject = {
duration_unit: string;
duration: number;
basis: string;
amount: string | number;
};

const Basis = observer(
({
basis,
Expand Down Expand Up @@ -57,7 +50,7 @@ const Basis = observer(
const formatAmount = (value: number | string) =>
!isNaN(+value) && value !== '' ? Number(value).toFixed(user_currency_decimal_places) : value;
const setBasisAndAmount = (amount: number | string) => {
const on_change_obj = {} as TObject;
const on_change_obj: Partial<ReturnType<typeof useTraderStore>> = {};

// Check for any duration changes in Duration trade params Tab before sending onChange object
if (duration_unit !== trade_duration_unit && !has_duration_error)
Expand All @@ -66,7 +59,7 @@ const Basis = observer(

if (amount !== trade_amount || basis !== trade_basis) {
on_change_obj.basis = basis;
on_change_obj.amount = amount;
on_change_obj.amount = +amount;
}

if (!isEmptyObject(on_change_obj)) onChangeMultiple(on_change_obj);
Expand Down
2 changes: 0 additions & 2 deletions packages/trader/src/Modules/Trading/Containers/trade.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ const ChartTrade = observer(props => {
wsSubscribe,
active_symbols,
has_alternative_source,
refToAddTick,
} = useTraderStore();

const settings = {
Expand Down Expand Up @@ -384,7 +383,6 @@ const ChartTrade = observer(props => {
onExportLayout={exportLayout}
shouldFetchTradingTimes={!end_epoch}
hasAlternativeSource={has_alternative_source}
refToAddTick={refToAddTick}
getMarketsOrder={getMarketsOrder}
yAxisMargin={{
top: isMobile() ? 76 : 106,
Expand Down
Loading

0 comments on commit 5e341bd

Please sign in to comment.