Skip to content

Commit

Permalink
Add clear storage on manage section
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Aguero committed Aug 22, 2018
1 parent 32b1fe3 commit 7dfd810
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 45 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
35 changes: 35 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,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 7dfd810

Please sign in to comment.