Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Fix optimizely for local dev (#1874)
Browse files Browse the repository at this point in the history
* Prefer remote dev eth provider in dev env

* Fix optimizely local dev (#1261)

* Fix env

* Fix types

Co-authored-by: Dylan Jeffers <dylan@audius.co>
  • Loading branch information
piazzatron and dylanjeffers committed Sep 8, 2022
1 parent a3e62e8 commit 40bda4c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
12 changes: 10 additions & 2 deletions packages/common/src/services/audius-backend/AudiusBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import dayjs from 'dayjs'
import timezone from 'dayjs/plugin/timezone'
import utc from 'dayjs/plugin/utc'

import { Env } from 'services/env'

import placeholderCoverArt from '../../assets/img/imageBlank2x.png'
import imageCoverPhotoBlank from '../../assets/img/imageCoverPhotoBlank.jpg'
import placeholderProfilePicture from '../../assets/img/imageProfilePicEmpty2X.png'
Expand Down Expand Up @@ -204,6 +206,7 @@ type WaitForLibsInit = () => Promise<unknown>
type AudiusBackendParams = {
claimDistributionContractAddress: Maybe<string>
disableImagePreload?: boolean
env: Env
ethOwnerWallet: Maybe<string>
ethProviderUrls: Maybe<string[]>
ethRegistryAddress: Maybe<string>
Expand Down Expand Up @@ -257,6 +260,7 @@ type AudiusBackendParams = {
export const audiusBackend = ({
claimDistributionContractAddress,
disableImagePreload,
env,
ethOwnerWallet,
ethProviderUrls,
ethRegistryAddress,
Expand Down Expand Up @@ -717,8 +721,12 @@ export const audiusBackend = ({
}

function getEthWeb3Config() {
const providerUrls =
getRemoteVar(StringKeys.ETH_PROVIDER_URLS) || ethProviderUrls
// In a dev env, always ignore the remote var which is inherited from staging
const isDevelopment = env.ENVIRONMENT === 'development'
const providerUrls = isDevelopment
? ethProviderUrls
: getRemoteVar(StringKeys.ETH_PROVIDER_URLS) || ethProviderUrls

return {
ethWeb3Config: AudiusLibs.configEthWeb3(
ethTokenAddress,
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/services/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export type Environment = 'development' | 'staging' | 'production'

export type Env = {
EAGER_DISCOVERY_NODES?: string
EXPLORE_CONTENT_URL?: string
ENVIRONMENT?: Environment
}
2 changes: 2 additions & 0 deletions packages/mobile/src/services/audius-backend-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import scrypt from 'react-native-scrypt'
import { track } from 'app/services/analytics'
import { reportToSentry } from 'app/utils/reportToSentry'

import { env } from './env'
import { monitoringCallbacks } from './monitoringCallbacks'
import { getFeatureEnabled } from './remote-config'
import { remoteConfigInstance } from './remote-config/remote-config-instance'
Expand Down Expand Up @@ -86,6 +87,7 @@ const createKey = async (encryptStr: string, ivHex: string) => {
*/
export const audiusBackendInstance = audiusBackend({
claimDistributionContractAddress: Config.CLAIM_DISTRIBUTION_CONTRACT_ADDRESS,
env,
ethOwnerWallet: Config.ETH_OWNER_WALLET,
ethProviderUrls: (Config.ETH_PROVIDER_URL || '').split(','),
ethRegistryAddress: Config.ETH_REGISTRY_ADDRESS,
Expand Down
5 changes: 4 additions & 1 deletion packages/mobile/src/services/env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { Environment } from '@audius/common'

export const env = {
EAGER_DISCOVERY_NODES: process.env.REACT_APP_EAGER_DISCOVERY_NODES
EAGER_DISCOVERY_NODES: process.env.REACT_APP_EAGER_DISCOVERY_NODES,
ENVIRONMENT: process.env.REACT_APP_ENVIRONMENT as Environment
}
2 changes: 2 additions & 0 deletions packages/web/scripts/configureLocalEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ try {

const REACT_APP_ORACLE_ETH_ADDRESSES = aaoConfigFile.join(',')
const REACT_APP_AAO_ENDPOINT = `http://${HOST}:8000`
const REACT_APP_OPTIMIZELY_KEY = 'MX4fYBgANQetvmBXGpuxzF' // Stage optimizely key

const REACT_APP_METADATA_PROGRAM_ID =
'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'
Expand Down Expand Up @@ -117,6 +118,7 @@ try {
REACT_APP_ORACLE_ETH_ADDRESSES=${REACT_APP_ORACLE_ETH_ADDRESSES}
REACT_APP_AAO_ENDPOINT=${REACT_APP_AAO_ENDPOINT}
REACT_APP_OPTIMIZELY_KEY=${REACT_APP_OPTIMIZELY_KEY}
REACT_APP_USE_HASH_ROUTING=false
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { monitoringCallbacks } from 'services/serviceMonitoring'
import { reportToSentry } from 'store/errors/reportToSentry'
import { isElectron, isMobile } from 'utils/clientUtil'

import { env } from '../env'

declare global {
interface Window {
audiusLibs: any
Expand All @@ -25,6 +27,7 @@ declare global {
export const audiusBackendInstance = audiusBackend({
claimDistributionContractAddress:
process.env.REACT_APP_CLAIM_DISTRIBUTION_CONTRACT_ADDRESS,
env,
ethOwnerWallet: process.env.REACT_APP_ETH_OWNER_WALLET,
ethProviderUrls: (process.env.REACT_APP_ETH_PROVIDER_URL || '').split(','),
ethRegistryAddress: process.env.REACT_APP_ETH_REGISTRY_ADDRESS,
Expand Down
5 changes: 4 additions & 1 deletion packages/web/src/services/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Environment } from '@audius/common'

export const env = {
EAGER_DISCOVERY_NODES: process.env.REACT_APP_EAGER_DISCOVERY_NODES,
EXPLORE_CONTENT_URL: process.env.REACT_APP_EXPLORE_CONTENT_URL
EXPLORE_CONTENT_URL: process.env.REACT_APP_EXPLORE_CONTENT_URL,
ENVIRONMENT: process.env.REACT_APP_ENVIRONMENT as Environment
}

0 comments on commit 40bda4c

Please sign in to comment.