Skip to content

Commit

Permalink
Merge branch 'master' into metamask-not-being-called-#632
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/stores/TierStore.js
  • Loading branch information
fernandomg committed Mar 6, 2018
2 parents 4b92529 + 5a228c4 commit dd31fd4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/components/stepThree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/stores/TierStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
37 changes: 37 additions & 0 deletions src/stores/TierStore.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
})
2 changes: 1 addition & 1 deletion src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd31fd4

Please sign in to comment.