From 5f51fff5944608512607ad6e2dbae5ff85f683d5 Mon Sep 17 00:00:00 2001 From: Mariano Aguero Date: Wed, 12 Sep 2018 16:17:30 -0300 Subject: [PATCH] Refactoring compiler version --- src/components/stepFour/constants.js | 4 --- src/components/stepFour/index.js | 10 ++++--- src/components/stepFour/utils.js | 39 +++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/components/stepFour/constants.js b/src/components/stepFour/constants.js index 3d78ece9b..81a0565d4 100644 --- a/src/components/stepFour/constants.js +++ b/src/components/stepFour/constants.js @@ -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' -} diff --git a/src/components/stepFour/index.js b/src/components/stepFour/index.js index 48ec4e364..c787b454c 100644 --- a/src/components/stepFour/index.js +++ b/src/components/stepFour/index.js @@ -9,7 +9,8 @@ import { handlerForFile, scrollToBottom, summaryFileContents, - getOptimizationFlagByStore + getOptimizationFlagByStore, + getVersionFlagByStore } from './utils' import { noContractDataAlert, successfulDeployment, skippingTransaction, deployHasEnded } from '../../utils/alerts' import { @@ -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' @@ -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 (
- + { } const { abiEncoded } = contractStore[crowdsaleStore.proxyName] - const { COMPILER_VERSION } = CONTRACT_SETTINGS + const versionFlag = getVersionFlagByStore(crowdsaleStore) const optimizationFlag = getOptimizationFlagByStore(crowdsaleStore) return { @@ -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 @@ -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)) { @@ -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) +}