From d8c7c17e45ce546a51ce5c0d704ee9430743beca Mon Sep 17 00:00:00 2001 From: Mariano Aguero Date: Tue, 14 Aug 2018 08:20:18 -0300 Subject: [PATCH 01/40] Added callback to button continue --- src/components/Common/ButtonContinue.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Common/ButtonContinue.js b/src/components/Common/ButtonContinue.js index c8d9a5ed3..1a413acf4 100644 --- a/src/components/Common/ButtonContinue.js +++ b/src/components/Common/ButtonContinue.js @@ -7,13 +7,13 @@ export class ButtonContinue extends Component { * @returns {*} */ render() { - const { status, type } = this.props + const { status, type, onClick } = this.props const submitButtonClass = classNames('button', 'button_fill', 'button_no_border', { button_disabled: !status }) return ( - ) From 76fc2727d186ba4b2e2c60d8cd5350a217c3543e Mon Sep 17 00:00:00 2001 From: Mariano Aguero Date: Tue, 14 Aug 2018 08:21:06 -0300 Subject: [PATCH 02/40] Add function to convert keys to lowercase --- src/utils/utils.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/utils/utils.js b/src/utils/utils.js index c7f2b357d..1967a77d5 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -178,3 +178,18 @@ export const toBigNumber = (value, force = true) => { export const sleep = async ms => { return new Promise(resolve => setTimeout(resolve, ms)) } + +export const objectKeysToLowerCase = input => { + if (typeof input !== 'object') { + return input + } + if (Array.isArray(input)) { + return input.map(objectKeysToLowerCase) + } + return Object.keys(input).reduce((newObj, key) => { + let val = input[key] + let newVal = typeof val === 'object' ? objectKeysToLowerCase(val) : val + newObj[key.toLowerCase()] = newVal + return newObj + }, {}) +} From 4cd18b5e09a79fd2ce8fe951e72ef61a3b76b092 Mon Sep 17 00:00:00 2001 From: Mariano Aguero Date: Tue, 14 Aug 2018 08:22:13 -0300 Subject: [PATCH 03/40] Refactoring, add setProperty --- src/stores/Web3Store.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/stores/Web3Store.js b/src/stores/Web3Store.js index 8739813c1..d16d5d6c0 100644 --- a/src/stores/Web3Store.js +++ b/src/stores/Web3Store.js @@ -1,5 +1,5 @@ import Web3 from 'web3' -import { observable } from 'mobx' +import { observable, action } from 'mobx' import { getNetworkID } from '../utils/utils' import { CrowdsaleConfig } from '../components/Common/config' import { CHAINS, REACT_PREFIX } from '../utils/constants' @@ -12,20 +12,25 @@ class Web3Store { @observable curAddress @observable accounts - constructor(strategies) { + constructor() { this.getWeb3(web3 => { if (web3) { this.web3 = web3 web3.eth.getAccounts().then(accounts => { this.accounts = accounts if (accounts.length > 0) { - this.curAddress = accounts[0] + this.setProperty('curAddress', accounts[0]) } }) } }) } + @action + setProperty = (property, value) => { + this[property] = value + } + getInfuraLink = network => { const infuraTokenEnvVar = process.env[`${REACT_PREFIX}INFURA_TOKEN`] return `https://${network}.infura.io/${infuraTokenEnvVar}` @@ -72,7 +77,7 @@ class Web3Store { } else { // window.web3 == web3 most of the time. Don't override the provided, // web3, just wrap it in your Web3. - var myWeb3 = new Web3(web3.currentProvider) + let myWeb3 = new Web3(web3.currentProvider) cb(myWeb3, false) return myWeb3 From 40d1ee1f2b99be96aa45b746edb9dc61b37347db Mon Sep 17 00:00:00 2001 From: Mariano Aguero Date: Tue, 14 Aug 2018 08:22:50 -0300 Subject: [PATCH 04/40] Validate tiers on key 0 --- src/stores/TierStore.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/stores/TierStore.js b/src/stores/TierStore.js index 0bc5296ca..3232f4431 100644 --- a/src/stores/TierStore.js +++ b/src/stores/TierStore.js @@ -103,14 +103,32 @@ class TierStore { @action updateWalletAddress = (value, validity) => { - this.tiers[0].walletAddress = value - this.validTiers[0].walletAddress = validity + if (this.tiers.length > 0) { + this.tiers[0].walletAddress = value + } else { + this.tiers.push({ walletAddress: value }) + } + + if (this.validTiers.length > 0) { + this.validTiers[0].walletAddress = validity + } else { + this.validTiers.push({ walletAddress: validity }) + } } @action updateBurnExcess = (value, validity) => { - this.tiers[0].burnExcess = value - this.validTiers[0].burnExcess = validity + if (this.tiers.length > 0) { + this.tiers[0].burnExcess = value + } else { + this.tiers.push({ burnExcess: value }) + } + + if (this.validTiers[0].length > 0) { + this.validTiers[0].burnExcess = validity + } else { + this.validTiers.push({ burnExcess: validity }) + } } @action From a468e4e44aef22169f315116046a0cc8c5b2a005 Mon Sep 17 00:00:00 2001 From: Mariano Aguero Date: Tue, 14 Aug 2018 08:23:45 -0300 Subject: [PATCH 05/40] keep type of gas selected --- src/stores/GeneralStore.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/stores/GeneralStore.js b/src/stores/GeneralStore.js index 4c496e2c3..bd97474fc 100644 --- a/src/stores/GeneralStore.js +++ b/src/stores/GeneralStore.js @@ -1,10 +1,11 @@ -import { observable, action } from 'mobx' +import { observable, action, computed } from 'mobx' import { GAS_PRICE } from '../utils/constants' import autosave from './autosave' class GeneralStore { @observable networkID @observable gasPrice = GAS_PRICE.FAST.PRICE + @observable gasTypeSelected constructor() { this.reset() @@ -21,10 +22,22 @@ class GeneralStore { this.gasPrice = gasPrice } + @action + setGasTypeSelected = gasTypeSeleted => { + this.gasTypeSelected = gasTypeSeleted + } + @action reset = () => { this.networkID = undefined this.gasPrice = GAS_PRICE.FAST.PRICE + this.gasTypeSelected = GAS_PRICE.SLOW + } + + // Getters + @computed + get getGasTypeSelected() { + return this.gasTypeSelected } } From efd197a528119654a7221c9aca6cbf41f18c4d47 Mon Sep 17 00:00:00 2001 From: Mariano Aguero Date: Tue, 14 Aug 2018 08:24:31 -0300 Subject: [PATCH 06/40] Refactoring to keep data --- src/components/stepThree/GasPriceInput.js | 86 +++++++++++++++-------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/src/components/stepThree/GasPriceInput.js b/src/components/stepThree/GasPriceInput.js index f1e6d29bf..9847b223b 100644 --- a/src/components/stepThree/GasPriceInput.js +++ b/src/components/stepThree/GasPriceInput.js @@ -1,14 +1,28 @@ import React, { Component } from 'react' import { GAS_PRICE } from '../../utils/constants' +import { objectKeysToLowerCase } from '../../utils/utils' import { Error } from '../Common/Error' +import { inject, observer } from 'mobx-react' +@inject('generalStore') +@observer class GasPriceInput extends Component { - constructor(props) { - super(props) + state = { + isCustom: false, + customGasPrice: 0, + gasTypeSelected: {} + } + + async componentDidMount() { + const { generalStore } = this.props + const gasTypeSelected = objectKeysToLowerCase(generalStore.getGasTypeSelected) + this.setState({ gasTypeSelected: gasTypeSelected }) - this.state = { - isCustom: false, - customGasPrice: undefined + if (gasTypeSelected.id === GAS_PRICE.CUSTOM.ID) { + this.setState({ + isCustom: true, + customGasPrice: gasTypeSelected.price + }) } } @@ -16,36 +30,44 @@ class GasPriceInput extends Component { this.setState({ isCustom: false }) - this.props.input.onChange(value) + + const gasTypeSelected = objectKeysToLowerCase(value) + this.handleGasType(gasTypeSelected) + this.props.input.onChange(gasTypeSelected) } handleCustomSelected = () => { - const { input, gasPrices } = this.props - - const newState = { isCustom: true } + this.setState({ + isCustom: true + }) - if (this.state.customGasPrice === undefined) { - const slow = gasPrices.find(gasPrice => gasPrice.id === GAS_PRICE.SLOW.ID) - newState.customGasPrice = slow.price + let gasTypeSelected = objectKeysToLowerCase(GAS_PRICE.CUSTOM) + if (this.state.customGasPrice) { + gasTypeSelected.price = this.state.customGasPrice } - this.setState(newState, () => { - input.onChange( - Object.assign( - {}, - { - id: GAS_PRICE.CUSTOM.ID, - price: this.state.customGasPrice - } - ) - ) + this.handleGasType(gasTypeSelected) + this.props.input.onChange(gasTypeSelected) + } + + handleGasType = value => { + const { updateGasTypeSelected } = this.props + + updateGasTypeSelected(value) + this.setState({ + gasTypeSelected: value }) } handleCustomGasPriceChange = value => { - const { input } = this.props + const { updateGasTypeSelected, input } = this.props + + let gasTypeSelected = this.state.gasTypeSelected + gasTypeSelected.price = value + updateGasTypeSelected(gasTypeSelected) this.setState({ + gasTypeSelected: gasTypeSelected, customGasPrice: value }) @@ -60,9 +82,12 @@ class GasPriceInput extends Component { ) } + compareChecked = value => { + return new String(this.state.gasTypeSelected.id).valueOf() === new String(value).valueOf() + } + render() { const { input, side, gasPrices } = this.props - return (
From 92f42779a5f6397fa3206879fdb3ed949f2fa37a Mon Sep 17 00:00:00 2001 From: Mariano Aguero Date: Tue, 14 Aug 2018 08:42:52 -0300 Subject: [PATCH 09/40] Add button continue and callback --- .../stepThree/StepThreeFormDutchAuction.js | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/stepThree/StepThreeFormDutchAuction.js b/src/components/stepThree/StepThreeFormDutchAuction.js index 968013c08..b85b2c1ea 100644 --- a/src/components/stepThree/StepThreeFormDutchAuction.js +++ b/src/components/stepThree/StepThreeFormDutchAuction.js @@ -4,8 +4,8 @@ import { FieldArray } from 'react-final-form-arrays' import { WhenFieldChanges } from '../Common/WhenFieldChanges' import { InputField2 } from '../Common/InputField2' import GasPriceInput from './GasPriceInput' +import { ButtonContinue } from '../Common/ButtonContinue' import { gweiToWei } from '../../utils/utils' -import classnames from 'classnames' import { composeValidators, isAddress, @@ -33,10 +33,17 @@ const inputErrorStyle = { height: '20px' } -export const StepThreeFormDutchAuction = ({ handleSubmit, invalid, pristine, ...props }) => { - const submitButtonClass = classnames('button', 'button_fill', { - button_disabled: pristine || invalid - }) +export const StepThreeFormDutchAuction = ({ handleSubmit, invalid, submitting, pristine, ...props }) => { + const status = !(submitting || invalid) + + /** + * Set gas type selected on gas price input + * @param value + */ + const updateGasTypeSelected = value => { + const { generalStore } = props + generalStore.setGasTypeSelected(value) + } const handleOnChange = ({ values }) => { props.tierStore.updateWalletAddress(values.walletAddress, VALID) @@ -125,6 +132,7 @@ export const StepThreeFormDutchAuction = ({ handleSubmit, invalid, pristine, ... component={GasPriceInput} side="right" gasPrices={props.gasPricesInGwei} + updateGasTypeSelected={updateGasTypeSelected} validate={value => composeValidators( isDecimalPlacesNotGreaterThan(VALIDATION_MESSAGES.DECIMAL_PLACES_9)(9), @@ -141,9 +149,7 @@ export const StepThreeFormDutchAuction = ({ handleSubmit, invalid, pristine, ...
- - Continue - +
From 6de6eef8b553ee8c8bdfec088eb683397cbd7f56 Mon Sep 17 00:00:00 2001 From: Mariano Aguero Date: Tue, 14 Aug 2018 10:59:59 -0300 Subject: [PATCH 10/40] Update snapshots --- .../__snapshots__/ManageForm.spec.js.snap | 30 +++++++++++++++++++ .../__snapshots__/StepTwoForm.spec.js.snap | 2 ++ 2 files changed, 32 insertions(+) diff --git a/test/components/manage/__snapshots__/ManageForm.spec.js.snap b/test/components/manage/__snapshots__/ManageForm.spec.js.snap index 89e5b4a01..1bdea1b6e 100644 --- a/test/components/manage/__snapshots__/ManageForm.spec.js.snap +++ b/test/components/manage/__snapshots__/ManageForm.spec.js.snap @@ -19,6 +19,11 @@ exports[`ManageForm should render for Dutch Auction 1`] = ` generalStore={ GeneralStore { "gasPrice": 15000000000, + "gasTypeSelected": Object { + "DESCRIPTION": "Safe and Cheap", + "ID": "slow", + "PRICE": 5000000000, + }, "networkID": undefined, } } @@ -255,6 +260,11 @@ exports[`ManageForm should render for Dutch Auction 1`] = ` generalStore={ GeneralStore { "gasPrice": 15000000000, + "gasTypeSelected": Object { + "DESCRIPTION": "Safe and Cheap", + "ID": "slow", + "PRICE": 5000000000, + }, "networkID": undefined, } } @@ -336,6 +346,11 @@ exports[`ManageForm should render the component with tiers 1`] = ` generalStore={ GeneralStore { "gasPrice": 15000000000, + "gasTypeSelected": Object { + "DESCRIPTION": "Safe and Cheap", + "ID": "slow", + "PRICE": 5000000000, + }, "networkID": undefined, } } @@ -1093,6 +1108,11 @@ exports[`ManageForm should render the component with tiers 1`] = ` generalStore={ GeneralStore { "gasPrice": 15000000000, + "gasTypeSelected": Object { + "DESCRIPTION": "Safe and Cheap", + "ID": "slow", + "PRICE": 5000000000, + }, "networkID": undefined, } } @@ -4402,6 +4422,11 @@ exports[`ManageForm should render the component without tiers 1`] = ` generalStore={ GeneralStore { "gasPrice": 15000000000, + "gasTypeSelected": Object { + "DESCRIPTION": "Safe and Cheap", + "ID": "slow", + "PRICE": 5000000000, + }, "networkID": undefined, } } @@ -4638,6 +4663,11 @@ exports[`ManageForm should render the component without tiers 1`] = ` generalStore={ GeneralStore { "gasPrice": 15000000000, + "gasTypeSelected": Object { + "DESCRIPTION": "Safe and Cheap", + "ID": "slow", + "PRICE": 5000000000, + }, "networkID": undefined, } } diff --git a/test/components/stepTwo/__snapshots__/StepTwoForm.spec.js.snap b/test/components/stepTwo/__snapshots__/StepTwoForm.spec.js.snap index a824a2a52..49b559e8e 100644 --- a/test/components/stepTwo/__snapshots__/StepTwoForm.spec.js.snap +++ b/test/components/stepTwo/__snapshots__/StepTwoForm.spec.js.snap @@ -183,6 +183,7 @@ exports[`StepTwoForm should render StepTwoForm for Dutch Auction Crowdsale 1`] =