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

(Bug) Keep data between the steps (Manage Page) #1103

Merged
merged 42 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d8c7c17
Added callback to button continue
Aug 14, 2018
76fc272
Add function to convert keys to lowercase
Aug 14, 2018
4cd18b5
Refactoring, add setProperty
Aug 14, 2018
40d1ee1
Validate tiers on key 0
Aug 14, 2018
a468e4e
keep type of gas selected
Aug 14, 2018
efd197a
Refactoring to keep data
Aug 14, 2018
02661da
Refactoring to keep data
Aug 14, 2018
445c8a8
Add button continue, callback to update
Aug 14, 2018
92f4277
Add button continue and callback
Aug 14, 2018
6de6eef
Update snapshots
Aug 14, 2018
a2531e0
Add burn excess support
Aug 14, 2018
dc10df6
Validate tiers with dutch auction
Aug 15, 2018
0f95b1c
Add mutator and validator
Aug 15, 2018
3097b61
Refactor
Aug 15, 2018
3d3ad43
Fix lint
Aug 15, 2018
1467b11
Add mutator, validator for supply input
Aug 15, 2018
704f2e2
Add rate as touched
Aug 16, 2018
e07e669
Add rate as touched
Aug 16, 2018
957bfce
Send gas type selected on change
Aug 16, 2018
8be411b
Support gas type selected on refresh page
Aug 16, 2018
5925f17
Disable supply when whitelist is enable for dutch strategy
Aug 16, 2018
a5f682d
Update snapshots
Aug 16, 2018
add416c
Change to lowercase
Aug 16, 2018
71b72be
Update snapshot
Aug 16, 2018
b1db8d9
Change language constant 'Greater or Equal Than'
Aug 17, 2018
b006fbb
Update gas type selected on father component
Aug 17, 2018
812ce85
Change custom gas price constant, change event onChange
Aug 17, 2018
7490791
Added custom gas price constant, remove set state
Aug 21, 2018
73d9f36
Validate network change
Aug 17, 2018
8ca582f
Change how gas type is set
Aug 21, 2018
7ebd9ac
Update snapshot
Aug 21, 2018
e0fffff
Add alert info if contracts already deployed
Aug 21, 2018
816b22e
Add clear storage on manage section
Aug 22, 2018
bfc37fc
Validate network change
Aug 17, 2018
2f41965
Change how gas type is set
Aug 21, 2018
2d39405
Update snapshot
Aug 21, 2018
45d7b23
Add alert info if contracts already deployed
Aug 21, 2018
41091ea
Add clear storage on manage section
Aug 22, 2018
7ba48d5
Merge branch 'issue#1033#manage' of github.com:poanetwork/token-wizar…
Aug 29, 2018
173d03a
Sort crowdsales list
Aug 29, 2018
84fb022
Merge branch '2.0-steps-integration' into issue#1033#manage
mariano-aguero Aug 29, 2018
83b7d70
Add function import
Aug 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
}
}
}