diff --git a/src/components/stepThree/index.js b/src/components/stepThree/index.js index 8f5597980..5f8aa388a 100644 --- a/src/components/stepThree/index.js +++ b/src/components/stepThree/index.js @@ -132,15 +132,24 @@ export class stepThree extends React.Component { const { tierStore, gasPriceStore } = this.props const gasPriceIsValid = gasPriceStore.custom.id !== this.state.gasPriceSelected || this.state.validation.gasPrice.valid === VALID - - console.log('gasPriceIsValid', gasPriceIsValid) + const isMinCapValid = tierStore.globalMinCap <= tierStore.maxSupply for (let index = 0; index < tierStore.tiers.length; index++) { tierStore.validateTiers('endTime', index) tierStore.validateTiers('startTime', index) } - if (tierStore.areTiersValid && gasPriceIsValid) { + if (!isMinCapValid) { + this.setState(update(this.state, { + validation: { + minCap: { + valid: { $set: INVALID } + } + } + })) + } + + if (tierStore.areTiersValid && gasPriceIsValid && isMinCapValid) { const { reservedTokenStore, deploymentStore } = this.props const tiersCount = tierStore.tiers.length const reservedCount = reservedTokenStore.tokens.length diff --git a/src/stores/TierStore.js b/src/stores/TierStore.js index fe4b972d0..f7a7e7506 100644 --- a/src/stores/TierStore.js +++ b/src/stores/TierStore.js @@ -186,6 +186,10 @@ class TierStore { whitelist[whitelistNum].deleted = true this.setTierProperty(whitelist, 'whitelist', crowdsaleNum) } + + @computed get maxSupply () { + return this.tiers.map(tier => +tier.supply).reduce((a, b) => Math.max(a, b), 0) + } } export default TierStore; diff --git a/src/stores/TierStore.spec.js b/src/stores/TierStore.spec.js new file mode 100644 index 000000000..1bb2d8bee --- /dev/null +++ b/src/stores/TierStore.spec.js @@ -0,0 +1,37 @@ +import TierStore from './TierStore' + +describe('TierStore', () => { + describe('maxSupply', () => { + const testCases = [{ + tiers: [], + expected: 0 + }, { + tiers: [5], + expected: 5 + }, { + tiers: [5, 10], + expected: 10 + }, { + tiers: [10, 5], + expected: 10 + }, { + tiers: [10, 10], + expected: 10 + }] + + testCases.forEach(({ tiers, expected }) => { + it(`should get the max supply for tiers ${JSON.stringify(tiers)}`, () => { + const tierStore = new TierStore() + + tierStore.emptyList() + tiers.forEach(tier => tierStore.addTier({ + supply: tier + })) + + const result = tierStore.maxSupply + + expect(result).toEqual(expected) + }) + }) + }) +}) diff --git a/src/utils/constants.js b/src/utils/constants.js index 0e35038f8..46aca01c1 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -117,7 +117,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: 'Value must be positive and decimals should not exceed the amount of decimals specified' + MINCAP: 'Value must be positive, decimals should not exceed the amount of decimals specified and min cap should be less or equal than the supply of some tier' } //descriptions of input fields