Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Fix) Metamask not being called #654

Merged
merged 32 commits into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ed88d22
Update CrowdsaleBlock to be used for any tier
fernandomg Mar 5, 2018
7870264
Add CrowdsaleBlock tests
fernandomg Mar 5, 2018
e0a7239
Update StepThree to use CrowdsaleBlock for all tiers
fernandomg Mar 5, 2018
e681524
Update TierStore (remove default tiers/validTiers & create method to …
fernandomg Mar 5, 2018
7ba623c
Create BigNumberInput
fernandomg Mar 5, 2018
c9b8c55
Add test for BigNumberInput
fernandomg Mar 5, 2018
bde47cc
Update constants values for tiers/validTiers
fernandomg Mar 5, 2018
9a4e0b6
Update manage to use 'tier' attribute
fernandomg Mar 5, 2018
21aa27e
Remove unused stores
fernandomg Mar 5, 2018
ce62095
Add enzyme-to-json
fernandomg Mar 5, 2018
35e6dd5
Add bigNumber.js library
fernandomg Mar 5, 2018
56fa6d5
Add MockDate
fernandomg Mar 5, 2018
78f737f
Update package-lock
fernandomg Mar 5, 2018
5aa7432
Remove validateRate method
fernandomg Mar 5, 2018
ede0916
Move defaultCompanyEndDate function
fernandomg Mar 5, 2018
f25d900
Refactor defaultCompanyEndDate signature
fernandomg Mar 5, 2018
d77ade3
Update '_oneTokenInWei' calculus
fernandomg Mar 5, 2018
149cc22
Update 'oneTokenInETH' calculus
fernandomg Mar 5, 2018
a388a39
Add snapshots for tests
fernandomg Mar 5, 2018
ea73208
Add test for stepThree utils
fernandomg Mar 5, 2018
d57eb92
Change attribute name
fernandomg Mar 6, 2018
14ddc04
Remove no longer needed setup code for tierStore in manage screen
fernandomg Mar 6, 2018
8883cc6
Merge branch 'master' into metamask-not-being-called-#632
fernandomg Mar 6, 2018
b1b7c2b
Use BigNumber library for crowdsale page
fernandomg Mar 6, 2018
4b92529
Update snapshot
fernandomg Mar 6, 2018
96a286e
Merge branch 'master' into metamask-not-being-called-#632
fernandomg Mar 6, 2018
dd31fd4
Merge branch 'master' into metamask-not-being-called-#632
fernandomg Mar 6, 2018
4dfd0a6
Merge remote-tracking branch 'origin/metamask-not-being-called-#632' …
fernandomg Mar 6, 2018
5393ce4
Merge remote-tracking branch 'origin/metamask-not-being-called-#632' …
vbaranov Mar 11, 2018
b84a238
Merge remote-tracking branch 'origin/master' into metamask-not-being-…
vbaranov Mar 12, 2018
55f9c75
Merge branch 'master' into metamask-not-being-called-#632
fernandomg Mar 12, 2018
649fa6a
Merge remote-tracking branch 'origin/metamask-not-being-called-#632' …
fernandomg Mar 12, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"coveralls": "^3.0.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-15": "^1.0.5",
"enzyme-to-json": "^3.3.1",
"ethereumjs-testrpc": "^4.1.3",
"ganache-cli": "^6.1.0-beta.0",
"gulp": "^3.9.1",
Expand All @@ -26,6 +27,7 @@
"gulp-util": "^3.0.8",
"markdown-toc": "^1.2.0",
"mobx-react-devtools": "^4.2.15",
"mockdate": "^2.0.2",
"react-test-renderer": "^15.6.2",
"shelljs": "^0.7.8",
"truffle": "^3.4.9",
Expand All @@ -43,6 +45,7 @@
"babel-preset-stage-1": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babel-runtime": "6.23.0",
"bignumber.js": "^6.0.0",
"case-sensitive-paths-webpack-plugin": "2.1.1",
"chalk": "1.1.3",
"classnames": "^2.2.5",
Expand Down Expand Up @@ -186,6 +189,9 @@
"web.jsx",
"jsx",
"node"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
},
"babel": {
Expand Down
125 changes: 125 additions & 0 deletions src/components/Common/BigNumberInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import React, { Component } from 'react'
import { BigNumber } from 'bignumber.js'
import { VALIDATION_TYPES } from '../../utils/constants'
import { InputField } from './InputField'

const { VALID, INVALID } = VALIDATION_TYPES

export class BigNumberInput extends Component {
constructor (props) {
super(props)

this.state = {
value: props.value || '',
pristine: props.pristine !== undefined ? props.pristine : true,
valid: props.valid || VALID
}
}

componentWillReceiveProps (newProps) {
const { value, pristine, valid } = newProps

this.setState({ value, pristine, valid })
}

componentDidUpdate (prevProps) {
const { acceptEmpty, acceptFloat, minDecimals, maxDecimals, min, max } = prevProps

if (
prevProps.acceptEmpty !== acceptEmpty ||
prevProps.acceptFloat !== acceptFloat ||
prevProps.minDecimals !== minDecimals ||
prevProps.maxDecimals !== maxDecimals ||
prevProps.min !== min ||
prevProps.max !== max
) {
// re-check validity if any of the props had changed
this.validate(this.state.value)
}
}

validate = (value) => {
const { acceptEmpty, acceptFloat, minDecimals, maxDecimals, min, max } = this.props
const newState = {
pristine: false
}

if (isNaN(Number(value)) || isNaN(parseFloat(value))) {
newState.value = ''
newState.valid = acceptEmpty ? VALID : INVALID

} else {
const number = new BigNumber(value)
const decimals = number.decimalPlaces()
let isValid = true

if (acceptFloat) {
if (maxDecimals !== undefined) {
isValid = decimals <= maxDecimals
}

if (isValid && minDecimals !== undefined) {
isValid = decimals >= minDecimals
}

} else {
isValid = !decimals
}

if (isValid && min !== undefined) {
isValid = number.gte(min)
}

if (isValid && max !== undefined) {
isValid = number.lte(max)
}

newState.value = number.toFixed()
newState.valid = isValid ? VALID : INVALID
}

this.setState(newState)
this.props.onChange(newState)
}

onKeyPress = e => {
const { acceptFloat, min, max } = this.props
const { key } = e
const isValidNumericKey = /[0-9.+e-]/
const isValidIntegerKey = /[0-9-]/

if (!isValidNumericKey.test(key)) e.preventDefault()
if (!acceptFloat && !isValidIntegerKey.test(key)) e.preventDefault()
if (!acceptFloat && key === '-' && min >= 0 && max >= 0) e.preventDefault()
}

onPaste = e => {
if (isNaN(Number(e.clipboardData.getData('text/plain')))) e.preventDefault()
}

onChange = e => {
this.validate(e.target.value)
}

render () {
const { value, pristine, valid } = this.state
const { disabled, side, errorMessage, title, description } = this.props

return (
<InputField
disabled={disabled}
side={side}
type="text"
errorMessage={errorMessage}
value={value}
pristine={pristine}
valid={valid}
title={title}
onKeyPress={this.onKeyPress}
onChange={this.onChange}
onPaste={this.onPaste}
description={description}
/>
)
}
}
Loading