@ -29,10 +29,15 @@ const bifyModuleGroups = require('bify-module-groups');
const metamaskrc = require ( 'rc' ) ( 'metamask' , {
const metamaskrc = require ( 'rc' ) ( 'metamask' , {
INFURA _PROJECT _ID : process . env . INFURA _PROJECT _ID ,
INFURA _PROJECT _ID : process . env . INFURA _PROJECT _ID ,
INFURA _BETA _PROJECT _ID : process . env . INFURA _BETA _PROJECT _ID ,
INFURA _FLASK _PROJECT _ID : process . env . INFURA _FLASK _PROJECT _ID ,
INFURA _PROD _PROJECT _ID : process . env . INFURA _PROD _PROJECT _ID ,
INFURA _PROD _PROJECT _ID : process . env . INFURA _PROD _PROJECT _ID ,
ONBOARDING _V2 : process . env . ONBOARDING _V2 ,
ONBOARDING _V2 : process . env . ONBOARDING _V2 ,
SEGMENT _HOST : process . env . SEGMENT _HOST ,
SEGMENT _HOST : process . env . SEGMENT _HOST ,
SEGMENT _WRITE _KEY : process . env . SEGMENT _WRITE _KEY ,
SEGMENT _WRITE _KEY : process . env . SEGMENT _WRITE _KEY ,
SEGMENT _BETA _WRITE _KEY : process . env . SEGMENT _BETA _WRITE _KEY ,
SEGMENT _FLASK _WRITE _KEY : process . env . SEGMENT _FLASK _WRITE _KEY ,
SEGMENT _PROD _WRITE _KEY : process . env . SEGMENT _PROD _WRITE _KEY ,
SENTRY _DSN _DEV :
SENTRY _DSN _DEV :
process . env . SENTRY _DSN _DEV ||
process . env . SENTRY _DSN _DEV ||
'https://f59f3dd640d2429d9d0e2445a87ea8e1@sentry.io/273496' ,
'https://f59f3dd640d2429d9d0e2445a87ea8e1@sentry.io/273496' ,
@ -50,6 +55,7 @@ const {
const {
const {
createRemoveFencedCodeTransform ,
createRemoveFencedCodeTransform ,
} = require ( './transforms/remove-fenced-code' ) ;
} = require ( './transforms/remove-fenced-code' ) ;
const { BuildTypes } = require ( './utils' ) ;
/ * *
/ * *
* The build environment . This describes the environment this build was produced in .
* The build environment . This describes the environment this build was produced in .
@ -83,18 +89,47 @@ function getConfigValue(key) {
* Get the appropriate Infura project ID .
* Get the appropriate Infura project ID .
*
*
* @ param { object } options - The Infura project ID options .
* @ param { object } options - The Infura project ID options .
* @ param { BuildTypes } options . buildType - The current build type .
* @ param { ENVIRONMENT [ keyof ENVIRONMENT ] } options . environment - The build environment .
* @ param { ENVIRONMENT [ keyof ENVIRONMENT ] } options . environment - The build environment .
* @ param { boolean } options . testing - Whether the current build is a test build or not .
* @ param { boolean } options . testing - Whether the current build is a test build or not .
* @ returns { string } The Infura project ID .
* @ returns { string } The Infura project ID .
* /
* /
function getInfuraProjectId ( { environment , testing } ) {
function getInfuraProjectId ( { buildType , environment , testing } ) {
if ( testing ) {
if ( testing ) {
return '00000000000000000000000000000000' ;
return '00000000000000000000000000000000' ;
} else if ( environment === ENVIRONMENT . PRODUCTION ) {
} else if ( environment !== ENVIRONMENT . PRODUCTION ) {
// Skip validation because this is unset on PRs from forks.
return metamaskrc . INFURA _PROJECT _ID ;
} else if ( buildType === BuildTypes . main ) {
return getConfigValue ( 'INFURA_PROD_PROJECT_ID' ) ;
return getConfigValue ( 'INFURA_PROD_PROJECT_ID' ) ;
} else if ( buildType === BuildTypes . beta ) {
return getConfigValue ( 'INFURA_BETA_PROJECT_ID' ) ;
} else if ( buildType === BuildTypes . flask ) {
return getConfigValue ( 'INFURA_FLASK_PROJECT_ID' ) ;
}
}
// Skip validation because this is unset on PRs from forks
throw new Error ( ` Invalid build type: ' ${ buildType } ' ` ) ;
return metamaskrc . INFURA _PROJECT _ID ;
}
/ * *
* Get the appropriate Segment write key .
*
* @ param { object } options - The Segment write key options .
* @ param { BuildTypes } options . buildType - The current build type .
* @ param { keyof ENVIRONMENT } options . enviroment - The current build environment .
* @ returns { string } The Segment write key .
* /
function getSegmentWriteKey ( { buildType , environment } ) {
if ( environment !== ENVIRONMENT . PRODUCTION ) {
// Skip validation because this is unset on PRs from forks, and isn't necessary for development builds.
return metamaskrc . SEGMENT _WRITE _KEY ;
} else if ( buildType === BuildTypes . main ) {
return getConfigValue ( 'SEGMENT_PROD_WRITE_KEY' ) ;
} else if ( buildType === BuildTypes . beta ) {
return getConfigValue ( 'SEGMENT_BETA_WRITE_KEY' ) ;
} else if ( buildType === BuildTypes . flask ) {
return getConfigValue ( 'SEGMENT_FLASK_WRITE_KEY' ) ;
}
throw new Error ( ` Invalid build type: ' ${ buildType } ' ` ) ;
}
}
module . exports = createScriptTasks ;
module . exports = createScriptTasks ;
@ -686,17 +721,9 @@ function getEnvironmentVariables({ buildType, devMode, testing }) {
CONF : devMode ? metamaskrc : { } ,
CONF : devMode ? metamaskrc : { } ,
SENTRY _DSN : process . env . SENTRY _DSN ,
SENTRY _DSN : process . env . SENTRY _DSN ,
SENTRY _DSN _DEV : metamaskrc . SENTRY _DSN _DEV ,
SENTRY _DSN _DEV : metamaskrc . SENTRY _DSN _DEV ,
INFURA _PROJECT _ID : getInfuraProjectId ( { environment , testing } ) ,
INFURA _PROJECT _ID : getInfuraProjectId ( { buildType , environment , testing } ) ,
SEGMENT _HOST : metamaskrc . SEGMENT _HOST ,
SEGMENT _HOST : metamaskrc . SEGMENT _HOST ,
// When we're in the 'production' environment we will use a specific key only set in CI
SEGMENT _WRITE _KEY : getSegmentWriteKey ( { buildType , environment } ) ,
// Otherwise we'll use the key from .metamaskrc or from the environment variable. If
// the value of SEGMENT_WRITE_KEY that we envify is undefined then no events will be tracked
// in the build. This is intentional so that developers can contribute to MetaMask without
// inflating event volume.
SEGMENT _WRITE _KEY :
environment === ENVIRONMENT . PRODUCTION
? process . env . SEGMENT _PROD _WRITE _KEY
: metamaskrc . SEGMENT _WRITE _KEY ,
SWAPS _USE _DEV _APIS : process . env . SWAPS _USE _DEV _APIS === '1' ,
SWAPS _USE _DEV _APIS : process . env . SWAPS _USE _DEV _APIS === '1' ,
ONBOARDING _V2 : metamaskrc . ONBOARDING _V2 === '1' ,
ONBOARDING _V2 : metamaskrc . ONBOARDING _V2 === '1' ,
} ;
} ;