Skip to content

Commit

Permalink
Merge 8277b81 into 0199fbe
Browse files Browse the repository at this point in the history
  • Loading branch information
mariano-aguero committed Aug 27, 2018
2 parents 0199fbe + 8277b81 commit de5a20e
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 65 deletions.
60 changes: 46 additions & 14 deletions src/components/stepFour/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { Component } from 'react'
import '../../assets/stylesheets/application.css'
import {
buildDeploymentSteps,
Expand All @@ -10,7 +10,7 @@ import {
scrollToBottom,
SUMMARY_FILE_CONTENTS
} from './utils'
import { noContractDataAlert, successfulDeployment, skippingTransaction } from '../../utils/alerts'
import { noContractDataAlert, successfulDeployment, skippingTransaction, deployHasEnded } from '../../utils/alerts'
import {
DESCRIPTION,
NAVIGATION_STEPS,
Expand All @@ -20,7 +20,7 @@ import {
PUBLISH_DESCRIPTION
} from '../../utils/constants'
import { DOWNLOAD_TYPE } from './constants'
import { toast } from '../../utils/utils'
import { getNetworkID, toast } from '../../utils/utils'
import { StepNavigation } from '../Common/StepNavigation'
import { DisplayField } from '../Common/DisplayField'
import { TxProgressStatus } from '../Common/TxProgressStatus'
Expand All @@ -34,6 +34,8 @@ import { PreventRefresh } from '../Common/PreventRefresh'
import cancelDeploy from '../../utils/cancelDeploy'
import PropTypes from 'prop-types'
import logdown from 'logdown'
import { checkNetWorkByID, getNetworkVersion } from '../../utils/blockchainHelpers'
import { CrowdsaleConfig } from '../Common/config'

const logger = logdown('TW:stepFour')

Expand Down Expand Up @@ -69,22 +71,26 @@ const {
'tokenStore',
'web3Store',
'deploymentStore',
'generalStore',
'crowdsaleStore'
)
@observer
export class stepFour extends React.Component {
export class stepFour extends Component {
state = {
contractDownloaded: false,
modal: false,
preventRefresh: true,
transactionFailed: false
}

constructor(props, context) {
super(props)
this.state = {
contractDownloaded: false,
modal: false,
preventRefresh: true,
transactionFailed: false
}

const { deploymentStore } = props

if (!deploymentStore.deployInProgress) {
logger.log(`Deployment progress`, deploymentStore.deployInProgress)
logger.log(`Deployment has ended`, deploymentStore.hasEnded)
if (!deploymentStore.deployInProgress && !deploymentStore.hasEnded) {
deploymentStore.setDeploymentStep(0)
deploymentStore.setDeployerAccount(context.selectedAccount)
}
Expand All @@ -100,15 +106,32 @@ export class stepFour extends React.Component {
toast.showToaster({ message: TOAST.MESSAGE.CONTRACT_DOWNLOAD_SUCCESS, options })
}

componentDidMount() {
async componentDidMount() {
const { deploymentStore, generalStore } = this.props

// Check if network has changed
const networkID = generalStore.networkID || CrowdsaleConfig.networkID || getNetworkID()
generalStore.setProperty('networkID', networkID)

const networkInfo = await checkNetWorkByID(networkID)

if (!networkInfo) {
return Promise.reject('invalid networkID')
}

// Check if deploy has ended
if (deploymentStore.hasEnded) {
return await deployHasEnded()
}

scrollToBottom()
copy('copy')
if (!this.props.deploymentStore.hasEnded) {
if (!deploymentStore.hasEnded) {
this.showModal()
}

// If user reloads with an invalid account, don't start the deploy automatically
if (!this.props.deploymentStore.invalidAccount) {
if (!deploymentStore.invalidAccount) {
this.deployCrowdsale()
}
}
Expand Down Expand Up @@ -154,6 +177,15 @@ export class stepFour extends React.Component {
logger.error([failedAt, err])
}

checkNetworkChanged = async () => {
const { generalStore } = this.props
const networkIDFromNifty = await getNetworkVersion()
const networkIDFromStore = generalStore.networkID
logger.log(`Network id from store`, networkIDFromStore)
logger.log(`Network id from nifty wallet`, networkIDFromNifty)
return +networkIDFromNifty !== +networkIDFromStore
}

skipTransaction = () => {
const { deploymentStore } = this.props

Expand Down
4 changes: 1 addition & 3 deletions src/components/stepThree/GasPriceInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ class GasPriceInput extends Component {
className="input"
value={this.state.customGasPrice}
name="gas-price-custom-value"
onChange={e => {
this.handleCustomGasPriceChange(e.target.value)
}}
onChange={e => this.handleCustomGasPriceChange(e.target.value)}
/>
) : null}
<p className="description">Slow is cheap, fast is expensive</p>
Expand Down
13 changes: 9 additions & 4 deletions src/components/stepThree/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { Component } from 'react'
import '../../assets/stylesheets/application.css'
import { Form } from 'react-final-form'
import arrayMutators from 'final-form-arrays'
Expand Down Expand Up @@ -30,7 +30,7 @@ const { CROWDSALE_SETUP } = NAVIGATION_STEPS
'crowdsaleStore'
)
@observer
export class stepThree extends React.Component {
export class stepThree extends Component {
state = {
loading: false,
reload: false,
Expand All @@ -44,14 +44,15 @@ export class stepThree extends React.Component {
await checkWeb3(web3Store.web3)

this.setState({ loading: true })
const { initialTiers, burnExcess, gasTypeSelected } = await this.load()

try {
await gasPriceStore.updateValues()
} catch (error) {
noGasPriceAvailable()
}

const { initialTiers, burnExcess, gasTypeSelected } = await this.load()

this.setState({
loading: false,
initialTiers: initialTiers,
Expand All @@ -62,7 +63,7 @@ export class stepThree extends React.Component {
}

async load() {
const { tierStore, generalStore, web3Store, crowdsaleStore } = this.props
const { tierStore, generalStore, web3Store, crowdsaleStore, gasPriceStore } = this.props

await sleep(1000)

Expand All @@ -83,6 +84,10 @@ export class stepThree extends React.Component {
initialTiers = JSON.parse(JSON.stringify(tierStore.tiers))
}

if (!generalStore.getGasTypeSelected) {
generalStore.setGasTypeSelected(gasPriceStore.gasPricesInGwei[0])
}

return {
initialTiers: initialTiers,
burnExcess: generalStore.burnExcess,
Expand Down
9 changes: 4 additions & 5 deletions src/stores/GeneralStore.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { observable, action, computed } from 'mobx'
import { GAS_PRICE } from '../utils/constants'
import autosave from './autosave'
import { objectKeysToLowerCase } from '../utils/utils'

class GeneralStore {
@observable networkID
@observable gasPrice = GAS_PRICE.FAST.PRICE
@observable gasPrice
@observable gasTypeSelected
@observable burnExcess

Expand Down Expand Up @@ -37,15 +36,15 @@ class GeneralStore {
@action
reset = () => {
this.networkID = undefined
this.gasPrice = GAS_PRICE.FAST.PRICE
this.gasTypeSelected = objectKeysToLowerCase(GAS_PRICE.SLOW)
this.gasPrice = GAS_PRICE.SLOW.PRICE
this.gasTypeSelected = undefined
this.burnExcess = 'no'
}

// Getters
@computed
get getGasTypeSelected() {
return this.gasTypeSelected || objectKeysToLowerCase(GAS_PRICE.SLOW)
return this.gasTypeSelected
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/stores/Web3Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Web3Store {
infuraLink = this.getInfuraLink(CHAINS.MAINNET)
break
}
let httpProvider = new Web3.providers.HttpProvider(infuraLink)
const httpProvider = new Web3.providers.HttpProvider(infuraLink)
web3 = new Web3(httpProvider)
}

Expand All @@ -77,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.
let myWeb3 = new Web3(web3.currentProvider)
const myWeb3 = new Web3(web3.currentProvider)

cb(myWeb3, false)
return myWeb3
Expand Down
16 changes: 16 additions & 0 deletions src/utils/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,19 @@ export function maxCapExceedsSupply(count) {
type: 'info'
})
}

export function networkChanged() {
return sweetAlert2({
title: 'Network changed',
html: 'The network id was modified, please set up nifty wallet with the network id which you started',
type: 'warning'
})
}

export function deployHasEnded() {
return sweetAlert2({
title: 'Deploy ended',
html: 'The deploy is finished',
type: 'info'
})
}
2 changes: 1 addition & 1 deletion src/utils/blockchainHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const checkNetWorkByID = async _networkIdFromGET => {

if (networkNameFromGET !== networkNameFromNetwork) {
logger.log(`${networkNameFromGET}!=${networkNameFromNetwork}`)
return incorrectNetworkAlert(networkNameFromGET, networkNameFromNetwork)
return await incorrectNetworkAlert(networkNameFromGET, networkNameFromNetwork)
}

return _networkIdFromNetwork
Expand Down
48 changes: 12 additions & 36 deletions test/components/manage/__snapshots__/ManageForm.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ exports[`ManageForm should render for Dutch Auction 1`] = `
generalStore={
GeneralStore {
"burnExcess": "no",
"gasPrice": 15000000000,
"gasTypeSelected": Object {
"description": "Safe and Cheap",
"id": "slow",
"price": 5000000000,
},
"gasPrice": 5000000000,
"gasTypeSelected": undefined,
"networkID": undefined,
}
}
Expand Down Expand Up @@ -261,12 +257,8 @@ exports[`ManageForm should render for Dutch Auction 1`] = `
generalStore={
GeneralStore {
"burnExcess": "no",
"gasPrice": 15000000000,
"gasTypeSelected": Object {
"description": "Safe and Cheap",
"id": "slow",
"price": 5000000000,
},
"gasPrice": 5000000000,
"gasTypeSelected": undefined,
"networkID": undefined,
}
}
Expand Down Expand Up @@ -348,12 +340,8 @@ exports[`ManageForm should render the component with tiers 1`] = `
generalStore={
GeneralStore {
"burnExcess": "no",
"gasPrice": 15000000000,
"gasTypeSelected": Object {
"description": "Safe and Cheap",
"id": "slow",
"price": 5000000000,
},
"gasPrice": 5000000000,
"gasTypeSelected": undefined,
"networkID": undefined,
}
}
Expand Down Expand Up @@ -1111,12 +1099,8 @@ exports[`ManageForm should render the component with tiers 1`] = `
generalStore={
GeneralStore {
"burnExcess": "no",
"gasPrice": 15000000000,
"gasTypeSelected": Object {
"description": "Safe and Cheap",
"id": "slow",
"price": 5000000000,
},
"gasPrice": 5000000000,
"gasTypeSelected": undefined,
"networkID": undefined,
}
}
Expand Down Expand Up @@ -4426,12 +4410,8 @@ exports[`ManageForm should render the component without tiers 1`] = `
generalStore={
GeneralStore {
"burnExcess": "no",
"gasPrice": 15000000000,
"gasTypeSelected": Object {
"description": "Safe and Cheap",
"id": "slow",
"price": 5000000000,
},
"gasPrice": 5000000000,
"gasTypeSelected": undefined,
"networkID": undefined,
}
}
Expand Down Expand Up @@ -4668,12 +4648,8 @@ exports[`ManageForm should render the component without tiers 1`] = `
generalStore={
GeneralStore {
"burnExcess": "no",
"gasPrice": 15000000000,
"gasTypeSelected": Object {
"description": "Safe and Cheap",
"id": "slow",
"price": 5000000000,
},
"gasPrice": 5000000000,
"gasTypeSelected": undefined,
"networkID": undefined,
}
}
Expand Down

0 comments on commit de5a20e

Please sign in to comment.