Skip to content

Commit

Permalink
fix: use process.env for DEBUG_ADDRESSES, and rename env to clientEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
1emu committed Sep 19, 2023
1 parent ce2cbaa commit ace9164
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 48 deletions.
20 changes: 10 additions & 10 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ import isEthereumAddress from 'validator/lib/isEthereumAddress'

import { trimOtterspaceId } from './back/utils/contractInteractions'
import { OTTERSPACE_DAO_RAFT_ID } from './entities/Snapshot/constants'
import { clientEnv } from './utils/clientEnv'
import Candidates from './utils/delegates/candidates.json'
import { env } from './utils/env'

function getBooleanStringVar(variableName: string, defaultValue: boolean) {
const enabled = env(variableName)
const enabled = clientEnv(variableName)
if (enabled && enabled.length > 0) return enabled === 'true'
return defaultValue
}

export const DOCS_URL = 'https://docs.decentraland.org/decentraland/what-is-the-dao/'
export const FORUM_URL = process.env.GATSBY_DISCOURSE_API || env('GATSBY_DISCOURSE_API') || ''
export const GOVERNANCE_API = process.env.GATSBY_GOVERNANCE_API || env('GATSBY_GOVERNANCE_API') || ''
export const FORUM_URL = process.env.GATSBY_DISCOURSE_API || clientEnv('GATSBY_DISCOURSE_API') || ''
export const GOVERNANCE_API = process.env.GATSBY_GOVERNANCE_API || clientEnv('GATSBY_GOVERNANCE_API') || ''
export const DAO_DISCORD_URL = 'https://dcl.gg/dao-discord'
export const OPEN_CALL_FOR_DELEGATES_LINK = 'https://forum.decentraland.org/t/open-call-for-delegates-apply-now/5840'
export const CANDIDATE_ADDRESSES = Candidates.map((delegate) => delegate.address)
export const DAO_ROLLBAR_TOKEN = process.env.DAO_ROLLBAR_TOKEN
export const SEGMENT_KEY = env('GATSBY_SEGMENT_KEY') || ''
export const LOCAL_ENV_VAR = env('GATSBY_LOCAL_ENV_VAR') || ''
export const TEST_ENV_VAR = env('GATSBY_TEST_ENV_VAR') || ''
export const PROD_ENV_VAR = env('GATSBY_PROD_ENV_VAR') || ''
export const SEGMENT_KEY = clientEnv('GATSBY_SEGMENT_KEY') || ''
export const LOCAL_ENV_VAR = clientEnv('GATSBY_LOCAL_ENV_VAR') || ''
export const TEST_ENV_VAR = clientEnv('GATSBY_TEST_ENV_VAR') || ''
export const PROD_ENV_VAR = clientEnv('GATSBY_PROD_ENV_VAR') || ''
export const DISCORD_SERVICE_ENABLED = getBooleanStringVar('DISCORD_SERVICE_ENABLED', true)
export const VOTES_VP_THRESHOLD = 5
export const SSO_URL = env('GATSBY_SSO_URL') ?? undefined
export const SSO_URL = clientEnv('GATSBY_SSO_URL') ?? undefined
export const RAFT_OWNER_PK = process.env.RAFT_OWNER_PK || ''
export const POLYGON_BADGES_CONTRACT_ADDRESS = process.env.POLYGON_BADGES_CONTRACT_ADDRESS || ''
export const POLYGON_RAFTS_CONTRACT_ADDRESS = process.env.POLYGON_RAFTS_CONTRACT_ADDRESS || ''
Expand All @@ -34,7 +34,7 @@ export const LAND_OWNER_BADGE_SPEC_CID = process.env.LAND_OWNER_BADGE_SPEC_CID |
export const TRIMMED_OTTERSPACE_RAFT_ID = trimOtterspaceId(OTTERSPACE_DAO_RAFT_ID)
export const TOP_VOTERS_PER_MONTH = 3
export const TOP_VOTER_BADGE_IMG_URL = process.env.TOP_VOTER_BADGE_IMG_URL || ''
export const DEBUG_ADDRESSES = (env('DEBUG_ADDRESSES', '') || '')
export const DEBUG_ADDRESSES = (process.env.DEBUG_ADDRESSES || '')
.split(',')
.filter(isEthereumAddress)
.map((address) => address.toLowerCase())
37 changes: 19 additions & 18 deletions src/entities/Proposal/constants.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
import { env } from '../../utils/env'
import { clientEnv } from '../../utils/clientEnv'

export const MIN_NAME_SIZE = 2
export const MAX_NAME_SIZE = 15
export const VOTING_POWER_TO_PASS_LINKED_WEARABLES =
process.env.GATSBY_VOTING_POWER_TO_PASS_LINKED_WEARABLES || env('GATSBY_VOTING_POWER_TO_PASS_LINKED_WEARABLES')
process.env.GATSBY_VOTING_POWER_TO_PASS_LINKED_WEARABLES || clientEnv('GATSBY_VOTING_POWER_TO_PASS_LINKED_WEARABLES')
export const VOTING_POWER_TO_PASS_CATALYST =
process.env.VOTING_POWER_TO_PASS_CATALYST || env('GATSBY_VOTING_POWER_TO_PASS_CATALYST')
process.env.VOTING_POWER_TO_PASS_CATALYST || clientEnv('GATSBY_VOTING_POWER_TO_PASS_CATALYST')
export const VOTING_POWER_TO_PASS_BAN_NAME =
process.env.VOTING_POWER_TO_PASS_BAN_NAME || env('GATSBY_VOTING_POWER_TO_PASS_BAN_NAME')
export const VOTING_POWER_TO_PASS_POI = process.env.VOTING_POWER_TO_PASS_POI || env('GATSBY_VOTING_POWER_TO_PASS_POI')
process.env.VOTING_POWER_TO_PASS_BAN_NAME || clientEnv('GATSBY_VOTING_POWER_TO_PASS_BAN_NAME')
export const VOTING_POWER_TO_PASS_POI =
process.env.VOTING_POWER_TO_PASS_POI || clientEnv('GATSBY_VOTING_POWER_TO_PASS_POI')
export const VOTING_POWER_TO_PASS_POLL =
process.env.VOTING_POWER_TO_PASS_POLL || env('GATSBY_VOTING_POWER_TO_PASS_POLL')
process.env.VOTING_POWER_TO_PASS_POLL || clientEnv('GATSBY_VOTING_POWER_TO_PASS_POLL')
export const VOTING_POWER_TO_PASS_DRAFT =
process.env.VOTING_POWER_TO_PASS_DRAFT || env('GATSBY_VOTING_POWER_TO_PASS_DRAFT')
process.env.VOTING_POWER_TO_PASS_DRAFT || clientEnv('GATSBY_VOTING_POWER_TO_PASS_DRAFT')
export const VOTING_POWER_TO_PASS_GOVERNANCE =
process.env.GATSBY_VOTING_POWER_TO_PASS_GOVERNANCE || env('GATSBY_VOTING_POWER_TO_PASS_GOVERNANCE')
process.env.GATSBY_VOTING_POWER_TO_PASS_GOVERNANCE || clientEnv('GATSBY_VOTING_POWER_TO_PASS_GOVERNANCE')
export const VOTING_POWER_TO_PASS_PITCH =
process.env.GATSBY_VOTING_POWER_TO_PASS_PITCH || env('GATSBY_VOTING_POWER_TO_PASS_PITCH')
process.env.GATSBY_VOTING_POWER_TO_PASS_PITCH || clientEnv('GATSBY_VOTING_POWER_TO_PASS_PITCH')
export const VOTING_POWER_TO_PASS_TENDER =
process.env.GATSBY_VOTING_POWER_TO_PASS_TENDER || env('GATSBY_VOTING_POWER_TO_PASS_TENDER')
process.env.GATSBY_VOTING_POWER_TO_PASS_TENDER || clientEnv('GATSBY_VOTING_POWER_TO_PASS_TENDER')
export const VOTING_POWER_TO_PASS_BID =
process.env.GATSBY_VOTING_POWER_TO_PASS_BID || env('GATSBY_VOTING_POWER_TO_PASS_BID')
process.env.GATSBY_VOTING_POWER_TO_PASS_BID || clientEnv('GATSBY_VOTING_POWER_TO_PASS_BID')
export const SUBMISSION_THRESHOLD_DRAFT =
process.env.SUBMISSION_THRESHOLD_DRAFT || env('GATSBY_SUBMISSION_THRESHOLD_DRAFT')
process.env.SUBMISSION_THRESHOLD_DRAFT || clientEnv('GATSBY_SUBMISSION_THRESHOLD_DRAFT')
export const SUBMISSION_THRESHOLD_GOVERNANCE =
process.env.SUBMISSION_THRESHOLD_GOVERNANCE || env('GATSBY_SUBMISSION_THRESHOLD_GOVERNANCE')
process.env.SUBMISSION_THRESHOLD_GOVERNANCE || clientEnv('GATSBY_SUBMISSION_THRESHOLD_GOVERNANCE')
export const SUBMISSION_THRESHOLD_POLL =
process.env.SUBMISSION_THRESHOLD_POLL || env('GATSBY_SUBMISSION_THRESHOLD_POLL')
process.env.SUBMISSION_THRESHOLD_POLL || clientEnv('GATSBY_SUBMISSION_THRESHOLD_POLL')
export const SUBMISSION_THRESHOLD_PITCH =
process.env.GATSBY_SUBMISSION_THRESHOLD_PITCH || env('GATSBY_SUBMISSION_THRESHOLD_PITCH')
process.env.GATSBY_SUBMISSION_THRESHOLD_PITCH || clientEnv('GATSBY_SUBMISSION_THRESHOLD_PITCH')
export const SUBMISSION_THRESHOLD_TENDER =
process.env.GATSBY_SUBMISSION_THRESHOLD_TENDER || env('GATSBY_SUBMISSION_THRESHOLD_TENDER')
process.env.GATSBY_SUBMISSION_THRESHOLD_TENDER || clientEnv('GATSBY_SUBMISSION_THRESHOLD_TENDER')
export const SUBMISSION_THRESHOLD_HIRING =
process.env.GATSBY_SUBMISSION_THRESHOLD_HIRING || env('GATSBY_SUBMISSION_THRESHOLD_HIRING')
process.env.GATSBY_SUBMISSION_THRESHOLD_HIRING || clientEnv('GATSBY_SUBMISSION_THRESHOLD_HIRING')
export const VOTING_POWER_TO_PASS_HIRING =
process.env.VOTING_POWER_TO_PASS_HIRING || env('GATSBY_VOTING_POWER_TO_PASS_HIRING')
process.env.VOTING_POWER_TO_PASS_HIRING || clientEnv('GATSBY_VOTING_POWER_TO_PASS_HIRING')
4 changes: 2 additions & 2 deletions src/entities/Proposal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import numeral from 'numeral'
import { Governance } from '../../clients/Governance'
import { GOVERNANCE_API } from '../../constants'
import { getTile } from '../../utils/Land'
import { clientEnv } from '../../utils/clientEnv'
import Time from '../../utils/date/Time'
import { env } from '../../utils/env'
import { SNAPSHOT_SPACE, SNAPSHOT_URL } from '../Snapshot/constants'
import { UpdateAttributes } from '../Updates/types'
import { DISCOURSE_API } from '../User/utils'
Expand All @@ -22,7 +22,7 @@ export const SITEMAP_ITEMS_PER_PAGE = 100
export const DEFAULT_CHOICES = ['yes', 'no', 'abstain']
export const REGEX_NAME = new RegExp(`^([a-zA-Z0-9]){${MIN_NAME_SIZE},${MAX_NAME_SIZE}}$`)

export const JOIN_DISCORD_URL = env('GATSBY_JOIN_DISCORD_URL') || 'https://dcl.gg/discord'
export const JOIN_DISCORD_URL = clientEnv('GATSBY_JOIN_DISCORD_URL') || 'https://dcl.gg/discord'

export const CLIFF_PERIOD_IN_DAYS = 29

Expand Down
18 changes: 10 additions & 8 deletions src/entities/Snapshot/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from '../../utils/env'
import { clientEnv } from '../../utils/clientEnv'

// Backend-only constants
export const SNAPSHOT_PRIVATE_KEY = process.env.SNAPSHOT_PRIVATE_KEY || ''
Expand All @@ -8,14 +8,16 @@ export const OTTERSPACE_QUERY_ENDPOINT = process.env.OTTERSPACE_QUERY_ENDPOINT |
export const OTTERSPACE_DAO_RAFT_ID = process.env.OTTERSPACE_DAO_RAFT_ID || ''

// Shared frontend and backend constants
export const SNAPSHOT_SPACE = process.env.GATSBY_SNAPSHOT_SPACE || env('GATSBY_SNAPSHOT_SPACE') || ''
export const SNAPSHOT_ADDRESS = process.env.GATSBY_SNAPSHOT_ADDRESS || env('GATSBY_SNAPSHOT_ADDRESS') || ''
export const SNAPSHOT_DURATION = Number(process.env.GATSBY_SNAPSHOT_DURATION || env('GATSBY_SNAPSHOT_DURATION') || '')
export const SNAPSHOT_URL = process.env.GATSBY_SNAPSHOT_URL || env('GATSBY_SNAPSHOT_URL') || ''
export const SNAPSHOT_SPACE = process.env.GATSBY_SNAPSHOT_SPACE || clientEnv('GATSBY_SNAPSHOT_SPACE') || ''
export const SNAPSHOT_ADDRESS = process.env.GATSBY_SNAPSHOT_ADDRESS || clientEnv('GATSBY_SNAPSHOT_ADDRESS') || ''
export const SNAPSHOT_DURATION = Number(
process.env.GATSBY_SNAPSHOT_DURATION || clientEnv('GATSBY_SNAPSHOT_DURATION') || ''
)
export const SNAPSHOT_URL = process.env.GATSBY_SNAPSHOT_URL || clientEnv('GATSBY_SNAPSHOT_URL') || ''
export const SNAPSHOT_QUERY_ENDPOINT =
process.env.GATSBY_SNAPSHOT_QUERY_ENDPOINT || env('GATSBY_SNAPSHOT_QUERY_ENDPOINT') || ''
export const SNAPSHOT_API = process.env.GATSBY_SNAPSHOT_API || env('GATSBY_SNAPSHOT_API') || ''
process.env.GATSBY_SNAPSHOT_QUERY_ENDPOINT || clientEnv('GATSBY_SNAPSHOT_QUERY_ENDPOINT') || ''
export const SNAPSHOT_API = process.env.GATSBY_SNAPSHOT_API || clientEnv('GATSBY_SNAPSHOT_API') || ''

// Frontend-only constants
export const SNAPSHOT_DELEGATION_URL = `https://snapshot.org/#/delegate/${SNAPSHOT_SPACE}`
export const SNAPSHOT_DELEGATE_CONTRACT_ADDRESS = env('GATSBY_SNAPSHOT_DELEGATE_CONTRACT_ADDRESS')
export const SNAPSHOT_DELEGATE_CONTRACT_ADDRESS = clientEnv('GATSBY_SNAPSHOT_DELEGATE_CONTRACT_ADDRESS')
4 changes: 2 additions & 2 deletions src/entities/User/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { env } from '../../utils/env'
import { clientEnv } from '../../utils/clientEnv'

export const MESSAGE_TIMEOUT_TIME = 5 * 60 * 1000 // 5mins
export const GATSBY_DISCOURSE_CONNECT_THREAD =
process.env.GATSBY_DISCOURSE_CONNECT_THREAD || env('GATSBY_DISCOURSE_CONNECT_THREAD')
process.env.GATSBY_DISCOURSE_CONNECT_THREAD || clientEnv('GATSBY_DISCOURSE_CONNECT_THREAD')
6 changes: 3 additions & 3 deletions src/entities/User/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { hashMessage, recoverAddress } from 'ethers/lib/utils'

import { DiscoursePostInTopic } from '../../clients/Discourse'
import { FORUM_URL } from '../../constants'
import { env } from '../../utils/env'
import { clientEnv } from '../../utils/clientEnv'
import { ProposalComment, ProposalCommentsInDiscourse } from '../Proposal/types'
import { isSameAddress } from '../Snapshot/utils'

import { MESSAGE_TIMEOUT_TIME } from './constants'
import { ValidatedAccount } from './types'

export const DISCOURSE_USER = process.env.GATSBY_DISCOURSE_USER || env('GATSBY_DISCOURSE_USER') || ''
export const DISCOURSE_API = process.env.GATSBY_DISCOURSE_API || env('GATSBY_DISCOURSE_API') || ''
export const DISCOURSE_USER = process.env.GATSBY_DISCOURSE_USER || clientEnv('GATSBY_DISCOURSE_USER') || ''
export const DISCOURSE_API = process.env.GATSBY_DISCOURSE_API || clientEnv('GATSBY_DISCOURSE_API') || ''
const DEFAULT_AVATAR_SIZE = '45'

function getDefaultAvatarSizeUrl(avatar_url: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import logger from 'decentraland-gatsby/dist/entities/Development/logger'
import isEthereumAddress from 'validator/lib/isEthereumAddress'
import isURL from 'validator/lib/isURL'

import { env } from '../utils/env'
import { clientEnv } from '../utils/clientEnv'

export const CURRENCY_FORMAT_OPTIONS = {
style: 'currency',
Expand Down Expand Up @@ -98,7 +98,7 @@ export function capitalizeFirstLetter(string: string) {
}

export function getVestingContractUrl(address: string) {
const VESTING_DASHBOARD_URL = env('GATSBY_VESTING_DASHBOARD_URL')
const VESTING_DASHBOARD_URL = clientEnv('GATSBY_VESTING_DASHBOARD_URL')
return VESTING_DASHBOARD_URL.replace('%23', '#').concat(address.toLowerCase())
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/env.ts → src/utils/clientEnv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { config } from '../config'

export const env = (variable: string, defaultValue?: string) => {
export const clientEnv = (variable: string, defaultValue?: string) => {
return config.get(variable, defaultValue)
}
4 changes: 2 additions & 2 deletions src/utils/votes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { DelegationsLabelProps } from '../../components/Proposal/View/ProposalVo
import { VotedChoice } from '../../components/Proposal/View/ProposalVoting/VotedChoiceButton'
import { Vote } from '../../entities/Votes/types'
import { Scores } from '../../entities/Votes/utils'
import { env } from '../env'
import { clientEnv } from '../clientEnv'

import { DelegationsLabelBuilder } from './helpers/DelegationsLabelBuilder'
import { VotedChoiceBuilder } from './helpers/VotedChoiceBuilder'

const DEFAULT_CHAIN_ID = process.env.GATSBY_DEFAULT_CHAIN_ID || env('GATSBY_DEFAULT_CHAIN_ID')
const DEFAULT_CHAIN_ID = process.env.GATSBY_DEFAULT_CHAIN_ID || clientEnv('GATSBY_DEFAULT_CHAIN_ID')

export function getEnvironmentChainId() {
const CHAIN_ID = Number(DEFAULT_CHAIN_ID)
Expand Down

0 comments on commit ace9164

Please sign in to comment.