Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

nikolai.berestevich/fix/trader-tools-calculators: point is not a digit 30154 #1860

Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/pages/trader-tools/common/_utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,5 @@ export const numberSubmitFormatNegative = (input) => {
}
return result
}

export const getMaxLength = (input_field, input_length) => input_field?.includes(".") ? (input_length + 1).toString() : input_length.toString()
7 changes: 4 additions & 3 deletions src/pages/trader-tools/common/_validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const validation_regex = {

const validation_is_exceed_number = (input, maxDigit) => {
const max_digit = maxDigit || 15

if (input.length > max_digit) {
if (input.includes(".") && input.length > max_digit + 1) {
return false
}
if (!input.includes(".") && input.length > max_digit) {
return false
}

return true
}

Expand Down
18 changes: 8 additions & 10 deletions src/pages/trader-tools/margin-calculator/_margin-calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getContractSize,
getCurrency,
resetValidationMargin,
getMaxLength
} from '../common/_utility'
import {
optionItemDefault,
Expand Down Expand Up @@ -77,7 +78,7 @@ const MarginCalculator = () => {
const onTabClick = (tab) => {
setTab(tab)
}

return (
<>
<BreadCrumbContainer>
Expand Down Expand Up @@ -114,7 +115,7 @@ const MarginCalculator = () => {
assetPrice: '',
leverage: '',
optionList: syntheticItemLists,
contractSize: '',
contractSize: ''
}}
validate={resetValidationMargin}
onSubmit={(values, { setFieldValue }) => {
Expand All @@ -134,7 +135,7 @@ const MarginCalculator = () => {
setErrors,
resetForm,
isValid,
dirty,
dirty
}) => (
<CalculatorForm>
<CalculatorHeader>
Expand Down Expand Up @@ -193,11 +194,8 @@ const MarginCalculator = () => {
items={values.optionList}
label={localize('Symbol')}
onChange={(value) => {
setFieldValue('marginSymbol', getCurrency(value))
setFieldValue(
'contractSize',
getContractSize(value),
)
setFieldValue('marginSymbol', getCurrency(value));
setFieldValue('contractSize', getContractSize(value))
setFieldValue('symbol', value)
}}
selected_item={values.symbol}
Expand Down Expand Up @@ -226,7 +224,7 @@ const MarginCalculator = () => {
setFieldTouched('volume', false, false)
current_input.focus()
}}
maxLength="8"
maxLength={getMaxLength(values.volume,8)}
background="white"
/>
)}
Expand Down Expand Up @@ -261,7 +259,7 @@ const MarginCalculator = () => {
)
current_input.focus()
}}
maxLength="15"
maxLength={getMaxLength(values.assetPrice, 15)}
background="white"
/>
)}
Expand Down
26 changes: 10 additions & 16 deletions src/pages/trader-tools/pip-calculator/_pip-calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
getContractSize,
numberWithCommas,
numberSubmitFormat,
getMaxLength
} from '../common/_utility'
import {
optionItemDefault,
syntheticItemLists,
financialItemLists,
financialItemLists
} from '../common/_underlying-data'
import {
BreadCrumbContainer,
Expand All @@ -37,15 +38,15 @@ import {
StyledLinkButton,
StyledSection,
FormulaText,
StyledOl,
StyledOl
} from '../common/_style'
import {
Accordion,
AccordionItem,
Header,
LocalizedLinkText,
QueryImage,
Text,
Text
} from 'components/elements'
import Input from 'components/form/input'
import RightArrow from 'images/svg/black-right-arrow.svg'
Expand Down Expand Up @@ -119,7 +120,7 @@ const PipCalculator = () => {
volume: '',
pointValue: '',
optionList: syntheticItemLists,
contractSize: '',
contractSize: ''
}}
validate={resetValidationPip}
onSubmit={(values, { setFieldValue }) => {
Expand All @@ -139,7 +140,7 @@ const PipCalculator = () => {
setErrors,
resetForm,
isValid,
dirty,
dirty
}) => (
<CalculatorForm>
<CalculatorHeader>
Expand Down Expand Up @@ -199,10 +200,7 @@ const PipCalculator = () => {
id="symbol"
onChange={(value) => {
setFieldValue('marginSymbol', getCurrency(value))
setFieldValue(
'contractSize',
getContractSize(value),
)
setFieldValue('contractSize', getContractSize(value))
setFieldValue('symbol', value)
}}
error={touched.symbol && errors.symbol}
Expand Down Expand Up @@ -234,7 +232,7 @@ const PipCalculator = () => {
setFieldTouched('volume', false, false)
current_input.focus()
}}
maxLength="8"
maxLength={getMaxLength(values.volume,8)}
background="white"
/>
)}
Expand Down Expand Up @@ -263,14 +261,10 @@ const PipCalculator = () => {
handleError={(current_input) => {
setFieldValue('pointValue', '', false)
setFieldError('pointValue', '')
setFieldTouched(
'pointValue',
false,
false,
)
setFieldTouched('pointValue',false,false)
current_input.focus()
}}
maxLength="15"
maxLength={getMaxLength(values.pointValue,15)}
background="white"
/>
)}
Expand Down
Loading