Skip to content

Commit

Permalink
Refactoring compiler version
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Aguero committed Sep 12, 2018
1 parent 142501a commit 5f51fff
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
4 changes: 0 additions & 4 deletions src/components/stepFour/constants.js
Expand Up @@ -19,7 +19,3 @@ export const TX_STEP_DESCRIPTION = {
crowdsaleInit: 'Initialize Crowdsale',
trackProxy: 'Add Proxy contract to registry'
}

export const CONTRACT_SETTINGS = {
COMPILER_VERSION: '0.4.24'
}
10 changes: 6 additions & 4 deletions src/components/stepFour/index.js
Expand Up @@ -9,7 +9,8 @@ import {
handlerForFile,
scrollToBottom,
summaryFileContents,
getOptimizationFlagByStore
getOptimizationFlagByStore,
getVersionFlagByStore
} from './utils'
import { noContractDataAlert, successfulDeployment, skippingTransaction, deployHasEnded } from '../../utils/alerts'
import {
Expand All @@ -21,7 +22,7 @@ import {
PUBLISH_DESCRIPTION,
CROWDSALE_STRATEGIES
} from '../../utils/constants'
import { CONTRACT_SETTINGS, DOWNLOAD_TYPE } from './constants'
import { DOWNLOAD_TYPE } from './constants'
import { getNetworkID, toast } from '../../utils/utils'
import { StepNavigation } from '../Common/StepNavigation'
import { DisplayField } from '../Common/DisplayField'
Expand Down Expand Up @@ -382,11 +383,12 @@ export class stepFour extends Component {
CONTRACT_NAME: PD_CONTRACT_NAME,
COMPILING_OPTIMIZATION: PD_COMPILING_OPTIMIZATION
} = PUBLISH_DESCRIPTION
const { COMPILER_VERSION: PRAGMA } = CONTRACT_SETTINGS
const optimizationFlag = getOptimizationFlagByStore(crowdsaleStore)
const versionFlag = getVersionFlagByStore(crowdsaleStore)

return (
<div className="hidden">
<DisplayField side="left" title={COMPILER_VERSION} value={PRAGMA} description={PD_COMPILER_VERSION} />
<DisplayField side="left" title={COMPILER_VERSION} value={versionFlag} description={PD_COMPILER_VERSION} />
<DisplayField
side="right"
title={CONTRACT_NAME}
Expand Down
39 changes: 36 additions & 3 deletions src/components/stepFour/utils.js
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../utils/blockchainHelpers'
import { countDecimalPlaces, toBigNumber, toFixed } from '../../utils/utils'
import { CROWDSALE_STRATEGIES } from '../../utils/constants'
import { DOWNLOAD_NAME, MINTED_PREFIX, DUTCH_PREFIX, ADDR_BOX_LEN, CONTRACT_SETTINGS } from './constants'
import { DOWNLOAD_NAME, MINTED_PREFIX, DUTCH_PREFIX, ADDR_BOX_LEN } from './constants'
import { REACT_PREFIX } from '../../utils/constants'
import { isObservableArray } from 'mobx'
import {
Expand Down Expand Up @@ -1072,7 +1072,7 @@ export const summaryFileContents = networkID => {
}

const { abiEncoded } = contractStore[crowdsaleStore.proxyName]
const { COMPILER_VERSION } = CONTRACT_SETTINGS
const versionFlag = getVersionFlagByStore(crowdsaleStore)
const optimizationFlag = getOptimizationFlagByStore(crowdsaleStore)

return {
Expand All @@ -1098,7 +1098,7 @@ export const summaryFileContents = networkID => {
'\n',
...bigHeaderElements('**********METADATA***********'),
{ field: 'proxyName', value: 'Contract name: ', parent: 'crowdsaleStore' },
{ value: 'Compiler version: ', parent: 'none', fileValue: COMPILER_VERSION },
{ value: 'Compiler version: ', parent: 'none', fileValue: versionFlag },
{ value: 'Optimized: ', parent: 'none', fileValue: optimizationFlag },
{ value: 'Encoded ABI parameters: ', parent: 'none', fileValue: abiEncoded },
...footerElemets
Expand Down Expand Up @@ -1153,6 +1153,28 @@ export const getPragmaVersion = async strategy => {
return firstLine.match(/(?:\^0|\d*)\.(?:0|\d*)\.(?:0|\d*)/gi) || '0.4.24'
}

export const getVersionFlagByStrategy = strategy => {
const strategiesAllowed = getStrategies()
if (!strategiesAllowed.includes(strategy)) {
throw new Error('Strategy not exist')
}

//Check path by enviroment variable
let constants
try {
if (['development', 'test'].includes(process.env.NODE_ENV)) {
constants = require(`json-loader!../../../public/metadata/${strategy}TruffleVersions.json`)
} else {
constants = require(`json-loader!../../../build/metadata/${strategy}TruffleVersions.json`)
}
} catch (err) {
logger.log('Error require truffle version', err)
}
const { solcVersion } = constants

return solcVersion
}

export const getOptimizationFlagByStrategy = strategy => {
const strategiesAllowed = getStrategies()
if (!strategiesAllowed.includes(strategy)) {
Expand Down Expand Up @@ -1185,3 +1207,14 @@ export const getOptimizationFlagByStore = crowdsaleStore => {
}
return getOptimizationFlagByStrategy(strategy)
}

export const getVersionFlagByStore = crowdsaleStore => {
let strategy
if (crowdsaleStore.isDutchAuction) {
strategy = 'Dutch'
}
if (crowdsaleStore.isMintedCappedCrowdsale) {
strategy = 'MintedCapped'
}
return getVersionFlagByStrategy(strategy)
}

0 comments on commit 5f51fff

Please sign in to comment.