Skip to content

Commit

Permalink
Merge pull request #1103 from poanetwork/issue#1033#manage
Browse files Browse the repository at this point in the history
(Bug) Keep data between the steps (Manage Page)
  • Loading branch information
fernandomg committed Aug 30, 2018
2 parents 0cbeef0 + 83b7d70 commit 4b9c771
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 70 deletions.
47 changes: 6 additions & 41 deletions src/components/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CrowdsalesList from '../Common/CrowdsalesList'
import { Loader } from '../Common/Loader'
import { loadRegistryAddresses } from '../../utils/blockchainHelpers'
import { ModalContainer } from '../Common/ModalContainer'
import { toast } from '../../utils/utils'
import { toast, clearStorage } from '../../utils/utils'
import { TOAST, NAVIGATION_STEPS, DOWNLOAD_STATUS } from '../../utils/constants'
import { inject, observer } from 'mobx-react'
import { checkWeb3, getNetworkVersion } from '../../utils/blockchainHelpers'
Expand Down Expand Up @@ -55,23 +55,23 @@ export class Home extends Component {
try {
await loadRegistryAddresses()
this.setState({
loading: false,
showModal: true
})
} catch (e) {
logger.error('There was a problem loading the crowdsale addresses from the registry', e)
this.setState({
loading: false
})
}

this.setState({
loading: false
})
}

goNextStep = async () => {
// Clear local storage if there is no incomplete deployment, and reload
if (storage.has('DeploymentStore') && storage.get('DeploymentStore').deploymentStep) {
this.props.history.push('/')
} else {
this.clearStorage()
clearStorage(this.props)
await this.reloadStorage()
this.props.history.push('1')
}
Expand Down Expand Up @@ -99,41 +99,6 @@ export class Home extends Component {
}
}

clearStorage() {
// Generate of stores to clear
const toArray = ({
generalStore,
contractStore,
crowdsaleStore,
gasPriceStore,
deploymentStore,
reservedTokenStore,
stepTwoValidationStore,
tierStore,
tokenStore
}) => {
return [
generalStore,
contractStore,
crowdsaleStore,
gasPriceStore,
deploymentStore,
reservedTokenStore,
stepTwoValidationStore,
tierStore,
tokenStore
]
}

const storesToClear = toArray(this.props)
for (let storeToClear of storesToClear) {
if (typeof storeToClear.reset === 'function') {
logger.log('Store to be cleared:', storeToClear.constructor.name)
storeToClear.reset()
}
}
}

onClick = crowdsaleAddress => {
this.props.history.push(`manage/${crowdsaleAddress}`)
}
Expand Down
20 changes: 16 additions & 4 deletions src/components/manage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
checkWeb3,
isAddressValid
} from '../../utils/blockchainHelpers'
import { isExecIDValid, isNetworkIDValid, toast, toBigNumber } from '../../utils/utils'
import { isExecIDValid, isNetworkIDValid, toast, toBigNumber, clearStorage } from '../../utils/utils'
import { getCrowdsaleAssets } from '../../stores/utils'
import { getFieldsToUpdate, processTier, updateTierAttribute } from './utils'
import { Loader } from '../Common/Loader'
Expand All @@ -39,7 +39,18 @@ import logdown from 'logdown'

const logger = logdown('TW:manage')

@inject('crowdsaleStore', 'web3Store', 'tierStore', 'contractStore', 'generalStore', 'tokenStore', 'gasPriceStore')
@inject(
'crowdsaleStore',
'web3Store',
'tierStore',
'contractStore',
'reservedTokenStore',
'stepTwoValidationStore',
'generalStore',
'tokenStore',
'gasPriceStore',
'deploymentStore'
)
@observer
export class Manage extends Component {
constructor(props) {
Expand All @@ -65,8 +76,9 @@ export class Manage extends Component {
setTimeout(() => window.scrollTo(0, 0), 500)
}

componentWillMount() {
this.preparePage()
async componentWillMount() {
clearStorage(this.props)
await this.preparePage()
}

preparePage = async () => {
Expand Down
12 changes: 10 additions & 2 deletions src/components/stepFour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { PreventRefresh } from '../Common/PreventRefresh'
import cancelDeploy from '../../utils/cancelDeploy'
import PropTypes from 'prop-types'
import logdown from 'logdown'
import { checkNetWorkByID } from '../../utils/blockchainHelpers'
import { checkNetWorkByID, getNetworkVersion } from '../../utils/blockchainHelpers'
import { CrowdsaleConfig } from '../Common/config'
import { ButtonContinue } from '../Common/ButtonContinue'
import classNames from 'classnames'
Expand Down Expand Up @@ -120,7 +120,6 @@ export class stepFour extends Component {
if (!networkInfo) {
return Promise.reject('invalid networkID')
}

// Check if deploy has ended
if (deploymentStore.hasEnded) {
return await deployHasEnded()
Expand Down Expand Up @@ -179,6 +178,15 @@ export class stepFour extends 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
42 changes: 19 additions & 23 deletions src/utils/blockchainHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,33 +347,29 @@ async function getOwnerApplicationsInstancesForProxy() {
const proxiesRegistryContract = await attachToSpecificCrowdsaleContract('ProxiesRegistry')
const accounts = await web3.eth.getAccounts()

const promises = []
const crowdsales = []
const proxyAddrs = await proxiesRegistryContract.methods.getCrowdsalesForUser(accounts[0]).call()
const proxyAddress = await proxiesRegistryContract.methods.getCrowdsalesForUser(accounts[0]).call()
const mintedCapped = process.env[`${REACT_PREFIX}MINTED_CAPPED_APP_NAME`].toLowerCase()
const dutchAuction = process.env[`${REACT_PREFIX}DUTCH_APP_NAME`].toLowerCase()
proxyAddrs.forEach(proxyAddr => {
let promise = new Promise(async (resolve, reject) => {
const abi = contractStore.MintedCappedProxy.abi // we can use minted caped proxy ABI for minted capped and Dutch acution
try {
const contractInstance = await attachToContract(abi, proxyAddr)
const contractAppName = await contractInstance.methods.app_name().call()
const appName = removeTrailingNUL(web3.utils.toAscii(contractAppName))
const appNameLowerCase = appName.toLowerCase()
if (appNameLowerCase.includes(mintedCapped) || appNameLowerCase.includes(dutchAuction)) {
crowdsales.push({ appName, execID: proxyAddr })
}
resolve()
} catch (error) {
logger.error(error)
resolve()

const whenCrowdsales = proxyAddress.map(async proxyAddr => {
const abi = contractStore.MintedCappedProxy.abi // we can use minted caped proxy ABI for minted capped and Dutch auction
try {
const contractInstance = await attachToContract(abi, proxyAddr)
const contractAppName = await contractInstance.methods.app_name().call()
const appName = removeTrailingNUL(web3.utils.toAscii(contractAppName))
const appNameLowerCase = appName.toLowerCase()
if (appNameLowerCase.includes(mintedCapped) || appNameLowerCase.includes(dutchAuction)) {
return { appName, execID: proxyAddr }
}
})
promises.push(promise)
})
return Promise.all(promises).then(() => {
return Promise.all(crowdsales)
} catch (error) {
logger.error(error)
}
return null
})

const crowdsales = await Promise.all(whenCrowdsales)

return crowdsales.filter(crowdsale => crowdsale).reverse()
}

// eslint-disable-next-line no-unused-vars
Expand Down
35 changes: 35 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,38 @@ export const objectKeysToLowerCase = input => {
return newObj
}, {})
}

export const clearStorage = props => {
// Generate of stores to clear
const toArray = ({
generalStore,
contractStore,
crowdsaleStore,
gasPriceStore,
deploymentStore,
reservedTokenStore,
stepTwoValidationStore,
tierStore,
tokenStore
}) => {
return [
generalStore,
contractStore,
crowdsaleStore,
gasPriceStore,
deploymentStore,
reservedTokenStore,
stepTwoValidationStore,
tierStore,
tokenStore
]
}

const storesToClear = toArray(props)
for (let storeToClear of storesToClear) {
if (typeof storeToClear.reset === 'function') {
logger.log('Store to be cleared:', storeToClear.constructor.name)
storeToClear.reset()
}
}
}

0 comments on commit 4b9c771

Please sign in to comment.