Skip to content

Commit

Permalink
Merge pull request #1062 from poanetwork/issue#1051
Browse files Browse the repository at this point in the history
(Bug) Dutch: Deployment is failed if minRate=maxRate in Step2
  • Loading branch information
vbaranov committed Jul 25, 2018
2 parents 7ce53ca + f7e1fc3 commit 12b87a7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/components/Common/DutchAuctionBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
isDatePreviousThan,
isDateSameOrLaterThan,
isDateSameOrPreviousThan,
isGreaterOrEqualThan,
isInteger,
isLessThan,
isGreaterThan,
isLessOrEqualThan,
isPositive,
isRequired
Expand Down Expand Up @@ -104,7 +105,7 @@ export const DutchAuctionBlock = inject('tierStore', 'tokenStore')(
const errors = composeValidators(
isPositive(),
isInteger(),
isLessOrEqualThan('Should be less than or equal to Max Rate')(allValues.tiers[index].maxRate),
isLessThan('Should be less than Max Rate')(allValues.tiers[index].maxRate),
isLessOrEqualThan('Should be less than or equal to 1 quintillion (10^18)')('1e18')
)(value)

Expand All @@ -123,9 +124,7 @@ export const DutchAuctionBlock = inject('tierStore', 'tokenStore')(
const errors = composeValidators(
isPositive(),
isInteger(),
isGreaterOrEqualThan('Should be greater than or equal to Min Rate')(
allValues.tiers[index].minRate
),
isGreaterThan('Should be greater than Min Rate')(allValues.tiers[index].minRate),
isLessOrEqualThan('Should less than or equal to 1 quintillion (10^18)')('1e18')
)(value)

Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ export const VALIDATION_MESSAGES = {
ADDRESS: 'Please enter a valid address',
REQUIRED: 'This field is required',
DECIMAL_PLACES: 'Decimals should not exceed the amount of decimals specified',
LESS: 'Should be less than the specified value',
LESS_OR_EQUAL: 'Should be less or equal than the specified value',
GREATER: 'Should be greater than the specified value',
GREATER_OR_EQUAL: 'Should be greater or equal than the specified value',
INTEGER: 'Should be integer',
DATE_IN_FUTURE: 'Should be set in the future',
Expand Down
20 changes: 20 additions & 0 deletions src/utils/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ export const isDecimalPlacesNotGreaterThan = (
return isValid ? undefined : errorMsg
}

export const isLessThan = (errorMsg = VALIDATION_MESSAGES.LESS) => (maxValue = Infinity) => value => {
try {
const max = toBigNumber(String(maxValue), false)
const isValid = max && max.gt(value)
return isValid ? undefined : errorMsg
} catch (e) {
return errorMsg
}
}

export const isLessOrEqualThan = (errorMsg = VALIDATION_MESSAGES.LESS_OR_EQUAL) => (maxValue = Infinity) => value => {
try {
const max = toBigNumber(String(maxValue), false)
Expand All @@ -71,6 +81,16 @@ export const isLessOrEqualThan = (errorMsg = VALIDATION_MESSAGES.LESS_OR_EQUAL)
}
}

export const isGreaterThan = (errorMsg = VALIDATION_MESSAGES.GREATER) => (minValue = Number.MIN_VALUE) => value => {
try {
const min = toBigNumber(String(minValue), false)
const isValid = min && min.lt(value)
return isValid ? undefined : errorMsg
} catch (e) {
return errorMsg
}
}

export const isGreaterOrEqualThan = (errorMsg = VALIDATION_MESSAGES.GREATER_OR_EQUAL) => (
minValue = Number.MIN_VALUE
) => value => {
Expand Down

0 comments on commit 12b87a7

Please sign in to comment.