From fffd70b58906abb502bbab684dcdee41e5af49f6 Mon Sep 17 00:00:00 2001 From: Thisyahlen Nair Date: Thu, 13 Apr 2023 16:21:34 +0800 Subject: [PATCH 1/3] fix: Reduce of empty array with no initial value --- packages/bot-skeleton/src/scratch/hooks/workspace_svg.js | 4 ++-- .../src/App/Containers/RealAccountSignup/account-wizard.jsx | 2 +- packages/core/src/Stores/Modules/Trading/Helpers/currency.js | 2 +- packages/indicators/src/indicators/relative-strength-index.js | 4 ++-- packages/indicators/src/utils/math.js | 2 +- .../trader/src/Stores/Modules/Trading/Helpers/currency.js | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/bot-skeleton/src/scratch/hooks/workspace_svg.js b/packages/bot-skeleton/src/scratch/hooks/workspace_svg.js index e8c40ce2660b..348c1b5130ae 100644 --- a/packages/bot-skeleton/src/scratch/hooks/workspace_svg.js +++ b/packages/bot-skeleton/src/scratch/hooks/workspace_svg.js @@ -146,7 +146,7 @@ Blockly.WorkspaceSvg.prototype.cleanUp = function (x = 0, y = 0, blocks_to_clean const start = (column_index - 1) * blocks_per_column; const fat_neighbour_block = root_blocks .slice(start, start + blocks_per_column) - .reduce((a, b) => (a.getHeightWidth().width > b.getHeightWidth().width ? a : b)); + .reduce((a, b) => (a.getHeightWidth().width > b.getHeightWidth().width ? a : b), null); let position_x = cursor_x + fat_neighbour_block.getHeightWidth().width + Blockly.BlockSvg.MIN_BLOCK_X; if (!is_import) { @@ -166,7 +166,7 @@ Blockly.WorkspaceSvg.prototype.cleanUp = function (x = 0, y = 0, blocks_to_clean const a_metrics = a.getRelativeToSurfaceXY().y + a.getHeightWidth().height; const b_metrics = b.getRelativeToSurfaceXY().y + b.getHeightWidth().height; return a_metrics > b_metrics ? a : b; - }); + }, null); original_cursor_y = lowest_root_block.getRelativeToSurfaceXY().y + diff --git a/packages/core/src/App/Containers/RealAccountSignup/account-wizard.jsx b/packages/core/src/App/Containers/RealAccountSignup/account-wizard.jsx index a72d6f2eb98b..d1cdd2e58aeb 100644 --- a/packages/core/src/App/Containers/RealAccountSignup/account-wizard.jsx +++ b/packages/core/src/App/Containers/RealAccountSignup/account-wizard.jsx @@ -168,7 +168,7 @@ const AccountWizard = props => { ...obj, ...values, }; - }); + }, {}); }; const clearError = () => { diff --git a/packages/core/src/Stores/Modules/Trading/Helpers/currency.js b/packages/core/src/Stores/Modules/Trading/Helpers/currency.js index 24db24f66577..d7920e2272b4 100644 --- a/packages/core/src/Stores/Modules/Trading/Helpers/currency.js +++ b/packages/core/src/Stores/Modules/Trading/Helpers/currency.js @@ -17,7 +17,7 @@ export const buildCurrenciesList = payout_currencies => { }; export const getDefaultCurrency = (currencies_list, currency = '') => { - const supported_currencies = Object.values(currencies_list).reduce((a, b) => [...a, ...b]); + const supported_currencies = Object.values(currencies_list).reduce((a, b) => [...a, ...b], []); const default_currency = supported_currencies.find(c => c.value === currency) ? currency : supported_currencies[0].value; diff --git a/packages/indicators/src/indicators/relative-strength-index.js b/packages/indicators/src/indicators/relative-strength-index.js index b6f184ef5dfa..5787c8414cb4 100644 --- a/packages/indicators/src/indicators/relative-strength-index.js +++ b/packages/indicators/src/indicators/relative-strength-index.js @@ -14,7 +14,7 @@ const calcFirstAvgDiff = (vals, comp, periods) => { const diff = comp(prev, q); prev = q; return diff + (i === 1 ? 0 : r); - }) / periods + }, 0) / periods ); }; @@ -32,7 +32,7 @@ const calcSecondAvgDiff = (vals, comp, periods, init_avg) => { prev = q; const prev_avg = i === 1 ? init_avg : r; return (prev_avg * (periods - 1) + diff) / periods; - }); + }, 0); }; /** diff --git a/packages/indicators/src/utils/math.js b/packages/indicators/src/utils/math.js index f2cfc55403ca..9b6e0a4fe35f 100644 --- a/packages/indicators/src/utils/math.js +++ b/packages/indicators/src/utils/math.js @@ -4,7 +4,7 @@ export const takeLast = (arr, n, field) => takeField(arr.slice(n > arr.length ? export const sum = data => data.reduce((acc, x) => acc + x); -export const mean = data => data.reduce((a, b) => a + b) / data.length; +export const mean = data => data.reduce((a, b) => a + b, 0) / data.length; export const stddev = data => { const data_mean = mean(data); diff --git a/packages/trader/src/Stores/Modules/Trading/Helpers/currency.js b/packages/trader/src/Stores/Modules/Trading/Helpers/currency.js index a964df5c3b06..bb8e707b1793 100644 --- a/packages/trader/src/Stores/Modules/Trading/Helpers/currency.js +++ b/packages/trader/src/Stores/Modules/Trading/Helpers/currency.js @@ -17,7 +17,7 @@ export const buildCurrenciesList = payout_currencies => { }; export const getDefaultCurrency = (currencies_list, currency = '') => { - const supported_currencies = Object.values(currencies_list).reduce((a, b) => [...a, ...b]); + const supported_currencies = Object.values(currencies_list).reduce((a, b) => [...a, ...b], []); const default_currency = supported_currencies.find(c => c.value === currency) ? currency : supported_currencies[0].value; From a30eb26e9f6aa177cd9221a5a4e2fb1783fcb029 Mon Sep 17 00:00:00 2001 From: Thisyahlen Nair Date: Thu, 13 Apr 2023 16:57:59 +0800 Subject: [PATCH 2/3] fix: revert indicator --- packages/indicators/src/indicators/relative-strength-index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/indicators/src/indicators/relative-strength-index.js b/packages/indicators/src/indicators/relative-strength-index.js index 5787c8414cb4..1246b1114aa2 100644 --- a/packages/indicators/src/indicators/relative-strength-index.js +++ b/packages/indicators/src/indicators/relative-strength-index.js @@ -32,7 +32,7 @@ const calcSecondAvgDiff = (vals, comp, periods, init_avg) => { prev = q; const prev_avg = i === 1 ? init_avg : r; return (prev_avg * (periods - 1) + diff) / periods; - }, 0); + }); }; /** From 55f30fbb78d4242df2b24958980b4bb7a30b779b Mon Sep 17 00:00:00 2001 From: thisyahlen <104053934+thisyahlen-deriv@users.noreply.github.com> Date: Thu, 13 Apr 2023 17:15:59 +0800 Subject: [PATCH 3/3] Update relative-strength-index.js --- packages/indicators/src/indicators/relative-strength-index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/indicators/src/indicators/relative-strength-index.js b/packages/indicators/src/indicators/relative-strength-index.js index 1246b1114aa2..b6f184ef5dfa 100644 --- a/packages/indicators/src/indicators/relative-strength-index.js +++ b/packages/indicators/src/indicators/relative-strength-index.js @@ -14,7 +14,7 @@ const calcFirstAvgDiff = (vals, comp, periods) => { const diff = comp(prev, q); prev = q; return diff + (i === 1 ? 0 : r); - }, 0) / periods + }) / periods ); };