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

[DTRA]fix: stake error not to be shown when error in only one payout #17491

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ 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 proposal_error_message =
proposal_error_message_1 || proposal_error_message_2 || validation_errors?.amount?.[0];
const has_both_errors = has_error_1 && has_error_2;
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;
Expand All @@ -88,7 +94,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
Expand All @@ -99,14 +105,15 @@ 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] || amount.toString() === '') && proposal_error_message) || '';
const [details, setDetails] = React.useState({
first_contract_payout,
max_payout,
Expand Down
Loading