Skip to content

Commit

Permalink
Merge pull request #1108 from poanetwork/issue#1045
Browse files Browse the repository at this point in the history
(Fix) crowdsale config should support exec-id and address of proxy as well
  • Loading branch information
vbaranov committed Aug 28, 2018
2 parents d7f3a21 + 1731b89 commit c0a7993
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/components/Common/config.js
Expand Up @@ -10,9 +10,10 @@
}
export const CrowdsaleConfig = {
crowdsaleContractURL: '0x338f47C1AA1DBdB56DfEA17cc376C0b21f4fbDa2',
networkID: networks.sokolPOA,
showHeaderAndFooterInIframe: true
showHeaderAndFooterInIframe: true,
execID: '',
proxyAddress: '0xf638119be6229634b3c2f7e234bfe38b368016d5'
};*/

export const CrowdsaleConfig = {}
2 changes: 1 addition & 1 deletion src/components/crowdsale/index.js
Expand Up @@ -144,7 +144,7 @@ export class Crowdsale extends React.Component {
const { crowdsale } = contractStore
const { proxyName } = crowdsaleStore
let queryStr = ''
if (!CrowdsaleConfig.crowdsaleContractURL || !CrowdsaleConfig.networkID) {
if (!CrowdsaleConfig.proxyAddress || !CrowdsaleConfig.networkID) {
const crowdsaleParamVal = crowdsale.execID || (contractStore[proxyName] ? contractStore[proxyName].addr : null)
if (crowdsaleParamVal) {
let crowdsaleParam
Expand Down
20 changes: 10 additions & 10 deletions src/components/crowdsale/utils.js
Expand Up @@ -6,7 +6,7 @@ import {
} from '../../utils/blockchainHelpers'
import { contractStore, crowdsalePageStore, tokenStore, web3Store, crowdsaleStore } from '../../stores'
import { toJS } from 'mobx'
import { _getAddr, _getExecID, removeTrailingNUL, toBigNumber } from '../../utils/utils'
import { getAddrFromQuery, getExecIDFromQuery, isAddressValid, removeTrailingNUL, toBigNumber } from '../../utils/utils'
import { BigNumber } from 'bignumber.js'
import logdown from 'logdown'
import { CrowdsaleConfig } from '../Common/config'
Expand Down Expand Up @@ -819,23 +819,23 @@ export const getInitializeDataFromContractStore = async () => {
}

export const getExecID = () => {
return CrowdsaleConfig.crowdsaleContractURL || _getExecID()
return CrowdsaleConfig.execID || getExecIDFromQuery()
}

export const getAddr = async () => {
try {
let address

// First: add the contract config if exist
if (CrowdsaleConfig && CrowdsaleConfig.crowdsaleContractURL) {
address = CrowdsaleConfig.crowdsaleContractURL
if (CrowdsaleConfig && CrowdsaleConfig.proxyAddress) {
address = isAddressValid(CrowdsaleConfig.proxyAddress)
} else {
address = _getAddr()
address = getAddrFromQuery()
}

// Second: get the addr and validate if is a valid address
if (!address) {
return sendAddressError(`There is no addr`)
return handleAddressError(`There is no addr`)
}

// Exist a race condition between clear the storage an initialize data from contract, so ...
Expand All @@ -851,22 +851,22 @@ export const getAddr = async () => {
const appExecIdVar = await app_exec_id().call()

if (!appExecIdVar) {
return sendAddressError(`There is no app exec id`)
return handleAddressError(`There is no app exec id`)
}

// Four: validate that exec id that exec-id of this Proxy smart-contract exists in Auth-os registry
let ownerAccount = await getAdmin().call()
if (!ownerAccount) {
return sendAddressError(`There is no owner account `)
return handleAddressError(`There is no owner account `)
}

return address
} catch (e) {
sendAddressError(e)
handleAddressError(e)
}
}

export const sendAddressError = message => {
export const handleAddressError = message => {
logger.log('Error getting address', message)
invalidCrowdsaleProxyAlert()
return Promise.reject(message)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/utils.js
Expand Up @@ -15,13 +15,13 @@ export const isExecIDValid = execID => /^0x[a-f0-9]{64}$/i.test(execID)

export const isAddressValid = address => Web3.utils.isAddress(address)

export const _getExecID = () => {
export const getExecIDFromQuery = () => {
const execID = getQueryVariableExecId()
logger.log('getExecID:', execID)
return isExecIDValid(execID) ? execID : null
}

export const _getAddr = () => {
export const getAddrFromQuery = () => {
const addr = getQueryVariableAddr()
logger.log('getAddr:', addr)
return isAddressValid(addr) ? addr : null
Expand Down

0 comments on commit c0a7993

Please sign in to comment.