Skip to content

Commit

Permalink
Merge branch 'master' into validate-whitelist-min-max-#578
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/utils/validations.js
#	src/utils/validations.spec.js
  • Loading branch information
fernandomg committed Apr 10, 2018
2 parents 9f6d574 + 31c3a22 commit eec87c0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 39 deletions.
8 changes: 6 additions & 2 deletions src/components/Common/TokenDecimals.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React from 'react'
import { validateDecimals } from '../../utils/validations'
import { composeValidators, isLessOrEqualThan, isNonNegative, isRequired } from '../../utils/validations'
import { TEXT_FIELDS } from '../../utils/constants'
import { Field } from 'react-final-form'
import { InputField2 } from './InputField2'
import { acceptPositiveIntegerOnly } from '../../utils/utils'

export const TokenDecimals = ({ disabled, errorStyle }) => (
<Field
validate={validateDecimals}
validate={composeValidators(
isRequired(),
isNonNegative(),
isLessOrEqualThan("Should not be greater than 18")(18)
)}
component={InputField2}
parse={acceptPositiveIntegerOnly}
side="left"
Expand Down
2 changes: 1 addition & 1 deletion src/components/stepTwo/StepTwoForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const errorStyle = {
fontWeight: 'bold',
fontSize: '12px',
width: '100%',
height: '10px',
height: '20px',
}

export const StepTwoForm = ({
Expand Down
30 changes: 27 additions & 3 deletions src/components/stepTwo/__snapshots__/StepTwoForm.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports[`StepTwoForm Should render the component 1`] = `
"color": "red",
"fontSize": "12px",
"fontWeight": "bold",
"height": "10px",
"height": "20px",
"width": "100%",
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ exports[`StepTwoForm Should render the component 1`] = `
"color": "red",
"fontSize": "12px",
"fontWeight": "bold",
"height": "10px",
"height": "20px",
"width": "100%",
}
}
Expand Down Expand Up @@ -125,7 +125,31 @@ exports[`StepTwoForm Should render the component 1`] = `
"color": "red",
"fontSize": "12px",
"fontWeight": "bold",
"height": "10px",
"height": "20px",
"width": "100%",
}
}
/>
<p
className="error"
style={
Object {
"color": "red",
"fontSize": "12px",
"fontWeight": "bold",
"height": "20px",
"width": "100%",
}
}
/>
<p
className="error"
style={
Object {
"color": "red",
"fontSize": "12px",
"fontWeight": "bold",
"height": "20px",
"width": "100%",
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/stepTwo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class stepTwo extends Component {
tokenValues: {
name: this.props.tokenStore.name,
ticker: this.props.tokenStore.ticker,
decimals: this.props.tokenStore.decimals,
decimals: this.props.tokenStore.decimals || 0,
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/utils/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const validators = (type, value) => {
return {
name: value && typeof value === 'string' && 1 <= value.length && value.length <= 30,
ticker: /^[a-zA-Z0-9]{1,5}$/.test(value),
decimals: (value === undefined || value === '') || (/^[0-9]+$/.test(value) && 0 <= value && value <= 18),
}[type] || false
}

Expand All @@ -21,11 +20,6 @@ export const validateTicker = (value) => {
return isValid ? undefined : VALIDATION_MESSAGES.TICKER
}

export const validateDecimals = (value) => {
const isValid = validators('decimals', value)
return isValid ? undefined : VALIDATION_MESSAGES.DECIMALS
}

export const validateWhitelistMin = ({ min, max, decimals }) => {
const listOfErrors = composeValidators(
isRequired(),
Expand Down
26 changes: 0 additions & 26 deletions src/utils/validations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
isNonNegative,
isPositive,
isRequired,
validateDecimals,
validateTicker,
validateTokenName,
validateWhitelistMax,
Expand Down Expand Up @@ -65,30 +64,6 @@ describe('validateTicker', () => {
})
})

describe('validateDecimals', () => {
[
{ value: '100', expected: VALIDATION_MESSAGES.DECIMALS },
{ value: '-10', expected: VALIDATION_MESSAGES.DECIMALS },
{ value: '20', expected: VALIDATION_MESSAGES.DECIMALS },
{ value: '1.5', expected: VALIDATION_MESSAGES.DECIMALS },
{ value: '1.', expected: VALIDATION_MESSAGES.DECIMALS },
{ value: '1e1', expected: VALIDATION_MESSAGES.DECIMALS },
{ value: '--', expected: VALIDATION_MESSAGES.DECIMALS },
{ value: undefined, expected: undefined },
{ value: '', expected: undefined },
{ value: '0', expected: undefined },
{ value: '1', expected: undefined },
{ value: '10', expected: undefined },
{ value: '18', expected: undefined },
].forEach(testCase => {
const action = testCase.expected === undefined ? 'pass' : 'fail'

it(`Should ${action} for '${testCase.value}'`, () => {
expect(validateDecimals(testCase.value)).toBe(testCase.expected)
})
})
})

describe('validateWhitelistMin', () => {
const testCases = [
{ value: { min: '0', max: '1', decimals: '0' }, expected: '' },
Expand Down Expand Up @@ -595,4 +570,3 @@ describe('composeValidators', () => {
expect(listOfErrors).toBeUndefined()
})
})

0 comments on commit eec87c0

Please sign in to comment.