From 045717c4f491ba8b1fa9b809d1d979209c9a51cb Mon Sep 17 00:00:00 2001 From: vinu-deriv Date: Wed, 13 Nov 2024 07:39:21 +0400 Subject: [PATCH 1/3] fix: stake error not to be shown when error in only one payout --- .../Components/TradeParameters/Stake/stake.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx b/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx index 90e82371bd7a..662475d5419e 100644 --- a/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx +++ b/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx @@ -76,8 +76,11 @@ const Stake = observer(({ is_minimized }: TTradeParametersProps) => { has_error_1 && (error_field_1 === 'amount' || error_field_1 === 'stake') ? message_1 : ''; const proposal_error_message_2 = has_error_2 && (error_field_2 === 'amount' || error_field_2 === 'stake') ? message_2 : ''; + const has_both_errors = has_error_1 && has_error_2; const proposal_error_message = - proposal_error_message_1 || proposal_error_message_2 || validation_errors?.amount?.[0]; + contract_types[1] && has_both_errors + ? proposal_error_message_1 || proposal_error_message_2 || validation_errors?.amount?.[0] + : (!(contract_types[1] && !has_both_errors) && proposal_error_message_1) || validation_errors?.amount?.[0]; /* TODO: stop using Max payout from error text as a default max payout and stop using error text for is_max_payout_exceeded after validation_params are added to proposal API (both success & error response): E.g., for is_max_payout_exceeded, we have to temporarily check the error text: Max payout error always contains 3 numbers, the check will work for any languages: */ const float_number_search_regex = /\d+(\.\d+)?/g; @@ -88,7 +91,7 @@ const Stake = observer(({ is_minimized }: TTradeParametersProps) => { is_max_payout_exceeded && proposal_error_message ? Number(proposal_error_message.match(float_number_search_regex)?.[1]) : 0; - const { payout, stake } = validation_params[contract_types[0]] ?? {}; + const { payout, stake } = (validation_params[contract_types[0]] || validation_params[contract_types[1]]) ?? {}; const { max: max_payout = error_max_payout } = payout ?? {}; const { max: max_stake = 0, min: min_stake = 0 } = stake ?? {}; const error_payout_1 = proposal_error_message_1 @@ -99,14 +102,12 @@ const Stake = observer(({ is_minimized }: TTradeParametersProps) => { : 0; const first_contract_payout = payout_1 || error_payout_1; const second_contract_payout = payout_2 || error_payout_2; - const validation_error_text = contract_types[1] ? validation_errors?.amount[0] : proposal_error_message; const main_error_message = - (validation_error_text && error_payout_1 > error_payout_2 + (proposal_error_message && error_payout_1 > error_payout_2 ? proposal_error_message_2 - : proposal_error_message_1) || validation_error_text; - const has_both_errors = has_error_1 && has_error_2; + : proposal_error_message_1) || proposal_error_message; const two_contracts_error = has_both_errors || amount.toString() === '' ? main_error_message : ''; - const stake_error = has_both_errors ? two_contracts_error : validation_error_text; + const stake_error = (has_both_errors ? two_contracts_error : !contract_types[1] && proposal_error_message) || ''; const [details, setDetails] = React.useState({ first_contract_payout, max_payout, From 9bc3181ff727c8d6e061634f2ee32e3532c3ea32 Mon Sep 17 00:00:00 2001 From: vinu-deriv Date: Wed, 13 Nov 2024 10:52:33 +0400 Subject: [PATCH 2/3] fix: refactor the stake error logic --- .../AppV2/Components/TradeParameters/Stake/stake.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx b/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx index 662475d5419e..74bfa2a4591d 100644 --- a/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx +++ b/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx @@ -77,10 +77,13 @@ const Stake = observer(({ is_minimized }: TTradeParametersProps) => { const proposal_error_message_2 = has_error_2 && (error_field_2 === 'amount' || error_field_2 === 'stake') ? message_2 : ''; const has_both_errors = has_error_1 && has_error_2; - const proposal_error_message = - contract_types[1] && has_both_errors - ? proposal_error_message_1 || proposal_error_message_2 || validation_errors?.amount?.[0] - : (!(contract_types[1] && !has_both_errors) && proposal_error_message_1) || validation_errors?.amount?.[0]; + const proposal_error_with_two_contract = contract_types[1] && has_both_errors; + + const proposal_error_with_one_contract = !(contract_types[1] && !has_both_errors) && proposal_error_message_1; + + const proposal_error_message = proposal_error_with_two_contract + ? proposal_error_message_1 || proposal_error_message_2 || validation_errors?.amount?.[0] + : proposal_error_with_one_contract || validation_errors?.amount?.[0]; /* TODO: stop using Max payout from error text as a default max payout and stop using error text for is_max_payout_exceeded after validation_params are added to proposal API (both success & error response): E.g., for is_max_payout_exceeded, we have to temporarily check the error text: Max payout error always contains 3 numbers, the check will work for any languages: */ const float_number_search_regex = /\d+(\.\d+)?/g; From 8057e56db1c7de18a45876d07618ec89d9eb55bd Mon Sep 17 00:00:00 2001 From: vinu-deriv Date: Wed, 13 Nov 2024 15:11:14 +0400 Subject: [PATCH 3/3] fix: stake error to be displayed when amount is empty --- .../src/AppV2/Components/TradeParameters/Stake/stake.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx b/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx index 74bfa2a4591d..440cfa9226e5 100644 --- a/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx +++ b/packages/trader/src/AppV2/Components/TradeParameters/Stake/stake.tsx @@ -110,7 +110,10 @@ const Stake = observer(({ is_minimized }: TTradeParametersProps) => { ? proposal_error_message_2 : proposal_error_message_1) || proposal_error_message; const two_contracts_error = has_both_errors || amount.toString() === '' ? main_error_message : ''; - const stake_error = (has_both_errors ? two_contracts_error : !contract_types[1] && proposal_error_message) || ''; + const stake_error = + (has_both_errors + ? two_contracts_error + : (!contract_types[1] || amount.toString() === '') && proposal_error_message) || ''; const [details, setDetails] = React.useState({ first_contract_payout, max_payout,