+
+
+
+ Address
+
+
+ Address where to send reserved tokens.
+
+
+
+
+
+ Dimension
+
+
+
+
+
+ tokens
+
+
+
+
+
+ percentage
+
+
+
+
+ Fixed amount or % of crowdsaled tokens. Will be deposited to the account after finalization of the crowdsale.
+
+
+
+
+ Value
+
+
- Value in tokens or percents. Don't forget to press + button for each reserved token.
+ Value in tokens. Don't forget to click + button for each reserved token.
+
Date: Mon, 26 Feb 2018 11:17:58 -0300
Subject: [PATCH 06/16] Fix error display when decimals is empty
---
src/components/stepTwo/index.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/components/stepTwo/index.js b/src/components/stepTwo/index.js
index e0def6c02..9e019b222 100644
--- a/src/components/stepTwo/index.js
+++ b/src/components/stepTwo/index.js
@@ -44,6 +44,11 @@ export class stepTwo extends Component {
showErrorMessages = (parent) => {
this.props.tokenStore.invalidateToken();
+ this.updateDecimalsStore({
+ value: this.state.decimals,
+ pristine: false,
+ valid: this.state.validation.decimals.valid
+ })
}
updateTokenStore = (event, property) => {
@@ -57,6 +62,7 @@ export class stepTwo extends Component {
validation: {
decimals: {
$set: {
+ disabled: this.state.validation.decimals.disabled,
pristine: pristine,
valid: valid
},
@@ -75,7 +81,7 @@ export class stepTwo extends Component {
disableDecimals = () => {
if (this.state.decimals === '') {
- this.updateDecimalsStore({ value: 0, pristine: false, valid: true })
+ this.updateDecimalsStore({ value: 0, pristine: false, valid: VALID })
}
this.setState({ validation: { decimals: { disabled: true } } })
From 6f24fb06906b2711668a5e991a690f8dcb03ca04 Mon Sep 17 00:00:00 2001
From: fernandomg
Date: Mon, 26 Feb 2018 11:29:42 -0300
Subject: [PATCH 07/16] Update NumericInput implementation for custom GasPrice
value
---
src/components/stepThree/index.js | 47 +++++++++++++++++++------------
1 file changed, 29 insertions(+), 18 deletions(-)
diff --git a/src/components/stepThree/index.js b/src/components/stepThree/index.js
index c59647082..d7d114a45 100644
--- a/src/components/stepThree/index.js
+++ b/src/components/stepThree/index.js
@@ -22,9 +22,10 @@ import { inject, observer } from "mobx-react";
import { Loader } from '../Common/Loader'
import { noGasPriceAvailable, warningOnMainnetAlert } from '../../utils/alerts'
import { NumericInput } from '../Common/NumericInput'
+import update from 'immutability-helper'
const { CROWDSALE_SETUP } = NAVIGATION_STEPS;
-const { EMPTY, VALID } = VALIDATION_TYPES;
+const { EMPTY, VALID, INVALID } = VALIDATION_TYPES;
const {
START_TIME,
END_TIME,
@@ -55,7 +56,13 @@ export class stepThree extends React.Component {
this.state = {
loading: true,
- gasPriceSelected: gasPriceStore.slow.id
+ gasPriceSelected: gasPriceStore.slow.id,
+ validation: {
+ gasPrice: {
+ pristine: true,
+ valid: INVALID
+ }
+ }
}
}
@@ -100,13 +107,6 @@ export class stepThree extends React.Component {
this.addCrowdsaleBlock(num);
}
- updateCrowdsaleBlockListStore = (event, property, index) => {
- const { crowdsaleBlockListStore } = this.props;
- const value = event.target.value;
- crowdsaleBlockListStore.setCrowdsaleBlockProperty(value, property, index);
- crowdsaleBlockListStore.validateCrowdsaleListBlockProperty(property, index);
- };
-
updateTierStore = (event, property, index) => {
const { tierStore } = this.props;
const value = event.target.value;
@@ -114,12 +114,6 @@ export class stepThree extends React.Component {
tierStore.validateTiers(property, index);
};
- updatePricingStrategyStore = (event, index, property) => {
- const { pricingStrategyStore } = this.props;
- const value = event.target.value;
- pricingStrategyStore.setStrategyProperty(value, property, index);
- };
-
goToDeploymentStage = () => {
this.props.history.push('/4')
}
@@ -150,14 +144,17 @@ export class stepThree extends React.Component {
e.preventDefault();
e.stopPropagation();
- const { tierStore } = this.props;
+ const { tierStore, gasPriceStore } = this.props;
+ const gasPriceIsValid = gasPriceStore.custom.id === this.state.gasPriceSelected && this.state.validation.gasPrice.valid === VALID
+
+ console.log('gasPriceIsValid', gasPriceIsValid)
for (let index = 0; index < tierStore.tiers.length; index++) {
tierStore.validateTiers("endTime", index);
tierStore.validateTiers("startTime", index);
}
- if (tierStore.areTiersValid) {
+ if (tierStore.areTiersValid && gasPriceIsValid) {
const { reservedTokenStore, deploymentStore } = this.props
const tiersCount = tierStore.tiers.length
const reservedCount = reservedTokenStore.tokens.length
@@ -217,7 +214,19 @@ export class stepThree extends React.Component {
}
}
- updateGasPrice = value => {
+ updateGasPrice = ({value, pristine, valid}) => {
+ const newState = update(this.state, {
+ validation: {
+ gasPrice: {
+ $set: {
+ pristine: pristine,
+ valid: valid
+ }
+ }
+ }
+ })
+
+ this.setState(newState)
this.props.generalStore.setGasPrice(gweiToWei(value))
}
@@ -284,6 +293,8 @@ export class stepThree extends React.Component {
maxDecimals={9}
acceptFloat={true}
value={weiToGwei(generalStore.gasPrice)}
+ pristine={this.state.validation.gasPrice.pristine}
+ valid={this.state.validation.gasPrice.valid}
errorMessage="Gas Price must be greater than 0.1 with up to 9 decimals"
onValueUpdate={this.updateGasPrice}
/> :
From d53f56fc73ba4dd7e35fb02297f1274b7c2dc5de Mon Sep 17 00:00:00 2001
From: fernandomg
Date: Mon, 26 Feb 2018 14:24:11 -0300
Subject: [PATCH 08/16] Update minCap to properly use of NumericInput
---
src/components/stepThree/index.js | 33 ++++++++++++++++++++++++++++---
src/stores/TierStore.js | 15 +++++++-------
src/utils/constants.js | 2 +-
src/utils/utils.js | 4 +---
4 files changed, 39 insertions(+), 15 deletions(-)
diff --git a/src/components/stepThree/index.js b/src/components/stepThree/index.js
index d7d114a45..c1a67a9bb 100644
--- a/src/components/stepThree/index.js
+++ b/src/components/stepThree/index.js
@@ -38,7 +38,7 @@ const {
ENABLE_WHITELISTING
} = TEXT_FIELDS;
-@inject("contractStore", "crowdsaleBlockListStore", "pricingStrategyStore", "web3Store", "tierStore", "generalStore", "gasPriceStore", "reservedTokenStore", "deploymentStore")
+@inject("contractStore", "crowdsaleBlockListStore", "pricingStrategyStore", "web3Store", "tierStore", "generalStore", "gasPriceStore", "reservedTokenStore", "deploymentStore", "tokenStore")
@observer
export class stepThree extends React.Component {
constructor(props) {
@@ -57,10 +57,15 @@ export class stepThree extends React.Component {
this.state = {
loading: true,
gasPriceSelected: gasPriceStore.slow.id,
+ minCap: '',
validation: {
gasPrice: {
pristine: true,
valid: INVALID
+ },
+ minCap: {
+ pristine: true,
+ valid: INVALID
}
}
}
@@ -230,6 +235,23 @@ export class stepThree extends React.Component {
this.props.generalStore.setGasPrice(gweiToWei(value))
}
+ updateMinCap = ({ value, pristine, valid }) => {
+ const newState = update(this.state, {
+ validation: {
+ minCap: {
+ $set: {
+ pristine: pristine,
+ valid: valid
+ }
+ }
+ }
+ })
+ newState.minCap = value
+
+ this.setState(newState)
+ this.props.tierStore.setGlobalMinCap(value)
+ }
+
renderGasPriceInput() {
const { generalStore, gasPriceStore } = this.props
@@ -337,9 +359,14 @@ export class stepThree extends React.Component {
title={MINCAP}
description="Minimum amount tokens to buy. Not a minimal size of a transaction. If minCap is 1 and user bought 1 token in a previous transaction and buying 0.1 token it will allow him to buy."
disabled={tierStore.tiers[0].whitelistEnabled === "yes"}
- min={0}
+ min={this.props.tokenStore.decimals ? Number(`1e-${this.props.tokenStore.decimals}`) : 1}
+ acceptFloat={!!this.props.tokenStore.decimals}
+ maxDecimals={this.props.tokenStore.decimals}
+ value={this.state.minCap}
+ pristine={this.state.validation.minCap.pristine}
+ valid={this.state.validation.minCap.valid}
errorMessage={VALIDATION_MESSAGES.MINCAP}
- onValueUpdate={tierStore.setGlobalMinCap}
+ onValueUpdate={this.updateMinCap}
/>
{
- return Object.keys(tier)
- .every((key) => {
- console.log('key', key, this.validTiers[index][key])
- return this.validTiers[index][key] === VALID
- })
- })
+ const isValid = this.validTiers.every((tier, index) => {
+ return Object.keys(tier)
+ .every((key) => {
+ console.log('key', key, this.validTiers[index][key])
+ return this.validTiers[index][key] === VALID
+ })
+ })
console.log('isValid', isValid)
diff --git a/src/utils/constants.js b/src/utils/constants.js
index 67481ad74..fd840992c 100644
--- a/src/utils/constants.js
+++ b/src/utils/constants.js
@@ -139,7 +139,7 @@ export const VALIDATION_MESSAGES = {
EDITED_END_TIME: 'Please enter a valid date later than start time and previous than start time of next tier',
EDITED_START_TIME: 'Please enter a valid date later than now, less than end time and later than the end time of the previous tier',
RATE: 'Please enter a valid number greater than 0',
- MINCAP: 'Please enter a valid number greater than 0'
+ MINCAP: 'Value must be positive and decimals should not exceed the amount of decimals specified'
}
//descriptions of input fields
diff --git a/src/utils/utils.js b/src/utils/utils.js
index 7e0b4f6bc..1d5e6747c 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -76,7 +76,7 @@ export const validateName = (name) => typeof name === 'string' && name.length >
export const validateSupply = (supply) => isNaN(Number(supply)) === false && Number(supply) > 0
-export const validateTicker = (ticker) => typeof ticker === 'string' && ticker.length <= 5 && ticker.length > 0
+export const validateTicker = (ticker) => /^[a-z0-9]{1,5}$/i.test(ticker)
export const validateTime = (time) => getTimeAsNumber(time) > Date.now()
@@ -88,8 +88,6 @@ export const validateRate = (rate) => isNaN(Number(rate)) === false && Number(ra
export const validateAddress = (address) => !(!address || address.length !== 42)
-export const validateMinCap = minCap => /^$|^([0-9]+)$/.test(minCap)
-
export function toFixed(x) {
if (Math.abs(x) < 1.0) {
let e = parseInt(x.toString().split('e-')[1], 10);
From 2a0c13dd4f56c033e0111a8476f825178a8aa2ee Mon Sep 17 00:00:00 2001
From: fernandomg
Date: Mon, 26 Feb 2018 14:25:40 -0300
Subject: [PATCH 09/16] Fix keyPress NumericInput to allow numbers to be
expressed as exponential (i.e.: 1e-10)
---
src/components/Common/NumericInput.js | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/src/components/Common/NumericInput.js b/src/components/Common/NumericInput.js
index 0c6c8f9d8..3dfe13be2 100644
--- a/src/components/Common/NumericInput.js
+++ b/src/components/Common/NumericInput.js
@@ -25,22 +25,12 @@ export class NumericInput extends Component {
}
onKeyPress = e => {
- const { value, min, max, acceptFloat } = this.props
- const isFirstCharacter = value === '' || value === undefined
- const isMinus = e.key === '-'
+ const { min, max, acceptFloat } = this.props
const allowsNegative = min < 0 || max < 0
- if (isFirstCharacter) {
- if (isMinus) {
- if (!allowsNegative) {
- e.preventDefault()
- }
- }
- } else {
- if (!acceptFloat) {
- if (isNaN(parseInt(e.key, 10))) {
- e.preventDefault()
- }
+ if (!acceptFloat && !allowsNegative) {
+ if (isNaN(parseInt(e.key, 10))) {
+ e.preventDefault()
}
}
}
From 1909acc2cc00971147d86771529e55e15d14b554 Mon Sep 17 00:00:00 2001
From: fernandomg
Date: Mon, 26 Feb 2018 14:25:57 -0300
Subject: [PATCH 10/16] Update tests
---
src/components/Common/NumericInput.spec.js | 24 ---------
.../ReservedTokensInputBlock.spec.js.snap | 4 ++
src/utils/utils.spec.js | 50 +------------------
3 files changed, 5 insertions(+), 73 deletions(-)
diff --git a/src/components/Common/NumericInput.spec.js b/src/components/Common/NumericInput.spec.js
index e96a55456..3a69c369e 100644
--- a/src/components/Common/NumericInput.spec.js
+++ b/src/components/Common/NumericInput.spec.js
@@ -85,14 +85,6 @@ describe('NumericInput', () => {
input().simulate(INPUT_EVENT.CHANGE, changeMock)
expect(numericInputComponent.onValueUpdate).toHaveBeenCalled()
})
- it('Should reject "-" symbol if it is not the first character', () => {
- numericInputComponent.min = -10
- numericInputComponent.value = 5
- keypressMock.key = '-'
-
- input().simulate(INPUT_EVENT.KEYPRESS, keypressMock)
- expect(keypressMock.preventDefault).toHaveBeenCalled()
- })
describe('min', () => {
it('Should accept "-" symbol if min is negative', () => {
@@ -114,14 +106,6 @@ describe('NumericInput', () => {
numericInputComponent.min = 0
keypressMock.key = '-'
- input().simulate(INPUT_EVENT.KEYPRESS, keypressMock)
- expect(keypressMock.preventDefault).toHaveBeenCalled()
- })
- it('Should reject "-" symbol if min is not negative and accepts floating numbers', () => {
- numericInputComponent.min = 0
- numericInputComponent.acceptFloat = true
- keypressMock.key = '-'
-
input().simulate(INPUT_EVENT.KEYPRESS, keypressMock)
expect(keypressMock.preventDefault).toHaveBeenCalled()
})
@@ -147,14 +131,6 @@ describe('NumericInput', () => {
numericInputComponent.max = 10
keypressMock.key = '-'
- input().simulate(INPUT_EVENT.KEYPRESS, keypressMock)
- expect(keypressMock.preventDefault).toHaveBeenCalled()
- })
- it('Should reject "-" symbol if max is not negative and accepts floating numbers', () => {
- numericInputComponent.max = 0
- numericInputComponent.acceptFloat = true
- keypressMock.key = '-'
-
input().simulate(INPUT_EVENT.KEYPRESS, keypressMock)
expect(keypressMock.preventDefault).toHaveBeenCalled()
})
diff --git a/src/components/Common/__snapshots__/ReservedTokensInputBlock.spec.js.snap b/src/components/Common/__snapshots__/ReservedTokensInputBlock.spec.js.snap
index 6107b6540..7ad506985 100644
--- a/src/components/Common/__snapshots__/ReservedTokensInputBlock.spec.js.snap
+++ b/src/components/Common/__snapshots__/ReservedTokensInputBlock.spec.js.snap
@@ -25,6 +25,7 @@ exports[`percentage 1`] = `
onChange={[Function]}
onKeyPress={undefined}
onPaste={undefined}
+ style={undefined}
type="text"
value=""
/>
@@ -108,6 +109,7 @@ exports[`percentage 1`] = `
onChange={[Function]}
onKeyPress={[Function]}
onPaste={[Function]}
+ style={undefined}
type="number"
value=""
/>
@@ -294,6 +296,7 @@ exports[`tokens 1`] = `
onChange={[Function]}
onKeyPress={undefined}
onPaste={undefined}
+ style={undefined}
type="text"
value=""
/>
@@ -377,6 +380,7 @@ exports[`tokens 1`] = `
onChange={[Function]}
onKeyPress={[Function]}
onPaste={[Function]}
+ style={undefined}
type="number"
value=""
/>
diff --git a/src/utils/utils.spec.js b/src/utils/utils.spec.js
index 11f0cf72e..29e75bde7 100644
--- a/src/utils/utils.spec.js
+++ b/src/utils/utils.spec.js
@@ -1,4 +1,4 @@
-import { countDecimalPlaces, validateDecimals, validateTicker, validateMinCap } from './utils'
+import { countDecimalPlaces, validateTicker } from './utils'
describe('countDecimalPlaces', () => {
[
@@ -33,27 +33,6 @@ describe('countDecimalPlaces', () => {
})
})
-describe('validateDecimals', () => {
- [
- { value: '', expected: true },
- { value: '0', expected: true },
- { value: '9', expected: true },
- { value: '10', expected: true },
- { value: '18', expected: true },
- { value: '19', expected: false },
- { value: '-1', expected: false },
- { value: '0.5', expected: false },
- { value: '3.5', expected: false },
- { value: '1e10', expected: false }
- ].forEach(testCase => {
- const action = testCase.expected ? 'pass' : 'fail'
-
- it(`Should ${action} for '${testCase.value}'`, () => {
- expect(validateDecimals(testCase.value)).toBe(testCase.expected)
- })
- })
-})
-
describe('validateTicker', () => {
[
{value: '', expected: false},
@@ -76,30 +55,3 @@ describe('validateTicker', () => {
})
})
})
-
-describe('validateMinCap', () => {
- [
- { value: '', expected: true },
- { value: '0', expected: true },
- { value: '00', expected: true },
- { value: '1', expected: true },
- { value: '001', expected: true },
- { value: '150', expected: true },
- { value: '999', expected: true },
- { value: '-10', expected: false },
- { value: .123, expected: false },
- { value: '1.12', expected: false },
- { value: '1.', expected: false },
- { value: '1e10', expected: false },
- { value: '+1', expected: false },
- { value: null, expected: false },
- { value: false, expected: false },
- { value: undefined, expected: false }
- ].forEach(testCase => {
- const action = testCase.expected ? 'pass' : 'fail'
-
- it(`Should ${action} for '${testCase.value}'`, () => {
- expect(validateMinCap(testCase.value)).toBe(testCase.expected)
- })
- })
-})
From ebba9a916a15c61f117742ac2e9bf13b4a53327f Mon Sep 17 00:00:00 2001
From: fernandomg
Date: Tue, 27 Feb 2018 14:11:00 -0300
Subject: [PATCH 11/16] Fix enable/disable decimals methods
---
src/components/stepTwo/index.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/components/stepTwo/index.js b/src/components/stepTwo/index.js
index 9e019b222..828440519 100644
--- a/src/components/stepTwo/index.js
+++ b/src/components/stepTwo/index.js
@@ -84,11 +84,11 @@ export class stepTwo extends Component {
this.updateDecimalsStore({ value: 0, pristine: false, valid: VALID })
}
- this.setState({ validation: { decimals: { disabled: true } } })
+ this.setState(update(this.state, { validation: { decimals: { disabled: { $set: true } } } }))
}
enableDecimals = () => {
- this.setState({ validation: { decimals: { disabled: false } } })
+ this.setState(update(this.state, { validation: { decimals: { disabled: { $set: false } } } }))
}
renderLink () {
From 20535ba33c76bb217937b327c0148dfa4288b62f Mon Sep 17 00:00:00 2001
From: fernandomg
Date: Wed, 28 Feb 2018 09:07:34 -0300
Subject: [PATCH 12/16] Remove commented code
---
.../Common/ReservedTokensInputBlock.spec.js | 52 -------------------
1 file changed, 52 deletions(-)
diff --git a/src/components/Common/ReservedTokensInputBlock.spec.js b/src/components/Common/ReservedTokensInputBlock.spec.js
index dd657a4f4..0cd3db329 100644
--- a/src/components/Common/ReservedTokensInputBlock.spec.js
+++ b/src/components/Common/ReservedTokensInputBlock.spec.js
@@ -383,56 +383,4 @@ describe('ReservedTokensInputBlock', () => {
})
})
})
-
- // it('Should reset state after adding a new address', () => {
- // const newReserved = {
- // addr: '0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1',
- // dim: 'percentage',
- // val: '120'
- // }
- // const addressEvent = { target: { value: newReserved.addr } }
- // const valueEvent = { target: { value: newReserved.val } }
- //
- // const handleAddressChange = jest.spyOn(wrapper().instance(), 'handleAddressChange')
- // const handleValueChange = jest.spyOn(wrapper().instance(), 'handleValueChange')
- //
- // wrapper().update()
- //
- // expect(addressState().pristine).toBeTruthy()
- // expect(addressState().valid).toBe(INVALID)
- // expect(valueState().pristine).toBeTruthy()
- // expect(valueState().valid).toBe(INVALID)
- // expect(wrapper().state('addr')).toBe('')
- // expect(wrapper().state('dim')).toBe('tokens')
- // expect(wrapper().state('val')).toBe('')
- //
- // addressInput().simulate('change', addressEvent)
- // valueInput().simulate('change', valueEvent)
- // wrapper().find('input[type="radio"]').at(1).simulate('change')
- //
- // expect(addressState().pristine).toBeFalsy()
- // expect(addressState().valid).toBe(VALID)
- // expect(wrapper().state('addr')).toBe(newReserved.addr)
- // expect(handleAddressChange).toHaveBeenCalledTimes(1)
- // expect(handleAddressChange).toHaveBeenCalledWith(newReserved.addr)
- //
- // expect(valueState().pristine).toBeFalsy()
- // expect(valueState().valid).toBe(VALID)
- // expect(wrapper().state('val')).toBe(newReserved.val)
- // expect(handleValueChange).toHaveBeenCalledTimes(1)
- // expect(handleValueChange).toHaveBeenCalledWith(newReserved.val)
- //
- // expect(wrapper().state('dim')).toBe(newReserved.dim)
- //
- // wrapper().find('.plus-button-container').childAt(0).simulate('click')
- //
- // expect(addressState().pristine).toBeTruthy()
- // expect(addressState().valid).toBe(INVALID)
- // expect(valueState().pristine).toBeTruthy()
- // expect(valueState().valid).toBe(INVALID)
- // expect(wrapper().state('addr')).toBe('')
- // expect(wrapper().state('dim')).toBe('tokens')
- // expect(wrapper().state('val')).toBe('')
- // })
-
})
From ff17edd1253871ee53d462d3ec856e906b20a936 Mon Sep 17 00:00:00 2001
From: fernandomg
Date: Wed, 28 Feb 2018 09:09:49 -0300
Subject: [PATCH 13/16] Fix default pristine value
---
src/components/Common/NumericInput.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/components/Common/NumericInput.js b/src/components/Common/NumericInput.js
index 3dfe13be2..a6f7bbbeb 100644
--- a/src/components/Common/NumericInput.js
+++ b/src/components/Common/NumericInput.js
@@ -13,7 +13,7 @@ export class NumericInput extends Component {
this.state = {
value: props.value || '',
- pristine: props.pristine || true,
+ pristine: props.pristine !== undefined ? props.pristine : true,
valid: props.valid || VALID
}
}
From 89d5a3885084591c90d9b167af7e16196f3999af Mon Sep 17 00:00:00 2001
From: fernandomg
Date: Wed, 28 Feb 2018 10:04:17 -0300
Subject: [PATCH 14/16] Fix special symbols handling in NumericInput
---
src/components/Common/NumericInput.js | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/components/Common/NumericInput.js b/src/components/Common/NumericInput.js
index a6f7bbbeb..7aa19c353 100644
--- a/src/components/Common/NumericInput.js
+++ b/src/components/Common/NumericInput.js
@@ -28,10 +28,13 @@ export class NumericInput extends Component {
const { min, max, acceptFloat } = this.props
const allowsNegative = min < 0 || max < 0
- if (!acceptFloat && !allowsNegative) {
- if (isNaN(parseInt(e.key, 10))) {
- e.preventDefault()
- }
+ if ((e.key === 'e' || e.key === '.' || e.key === '+') && !acceptFloat) {
+ e.preventDefault()
+ }
+
+ // '-' symbol is required for scientific notation and negative values
+ if (e.key === '-' && !allowsNegative && !acceptFloat) {
+ e.preventDefault()
}
}
From 7c43800ca0ce8924af3b78c8eee8dc9504059c65 Mon Sep 17 00:00:00 2001
From: fernandomg
Date: Wed, 28 Feb 2018 10:04:31 -0300
Subject: [PATCH 15/16] Add tests for NumericInput
---
src/components/Common/NumericInput.spec.js | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/components/Common/NumericInput.spec.js b/src/components/Common/NumericInput.spec.js
index 3a69c369e..8a1773b31 100644
--- a/src/components/Common/NumericInput.spec.js
+++ b/src/components/Common/NumericInput.spec.js
@@ -135,6 +135,30 @@ describe('NumericInput', () => {
expect(keypressMock.preventDefault).toHaveBeenCalled()
})
})
+
+ it('Should prevent "." if no float is allowed', () => {
+ numericInputComponent.value = '10'
+ keypressMock.key = '.'
+
+ input().simulate(INPUT_EVENT.KEYPRESS, keypressMock)
+ expect(keypressMock.preventDefault).toHaveBeenCalledTimes(1)
+ })
+
+ it('Should prevent "+" if no float is allowed', () => {
+ numericInputComponent.value = '10'
+ keypressMock.key = '+'
+
+ input().simulate(INPUT_EVENT.KEYPRESS, keypressMock)
+ expect(keypressMock.preventDefault).toHaveBeenCalledTimes(1)
+ })
+
+ it('Should prevent "e" if no float is allowed', () => {
+ numericInputComponent.value = '10'
+ keypressMock.key = 'e'
+
+ input().simulate(INPUT_EVENT.KEYPRESS, keypressMock)
+ expect(keypressMock.preventDefault).toHaveBeenCalledTimes(1)
+ })
})
describe('integer numbers', () => {
From 1810e9f5d94b72e4d1d4a1c2a8fe83ba767039e9 Mon Sep 17 00:00:00 2001
From: fernandomg
Date: Wed, 28 Feb 2018 10:05:10 -0300
Subject: [PATCH 16/16] Prevent infinite loops if for any reason decimals is
not a positive integer
---
src/components/stepTwo/index.js | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/components/stepTwo/index.js b/src/components/stepTwo/index.js
index 828440519..25def2124 100644
--- a/src/components/stepTwo/index.js
+++ b/src/components/stepTwo/index.js
@@ -123,6 +123,10 @@ export class stepTwo extends Component {
}
render () {
+ const decimals = this.state.validation.decimals.valid === VALID && this.state.decimals >= 0
+ ? parseInt(this.state.decimals, 10)
+ : 0
+
return (
@@ -171,7 +175,7 @@ export class stepTwo extends Component {