From ace9164dd1c3ce831dd0b620f9c1b4c66457f838 Mon Sep 17 00:00:00 2001 From: 1emu Date: Tue, 19 Sep 2023 14:23:22 -0300 Subject: [PATCH] fix: use process.env for DEBUG_ADDRESSES, and rename env to clientEnv --- src/constants.ts | 20 ++++++++-------- src/entities/Proposal/constants.ts | 37 +++++++++++++++--------------- src/entities/Proposal/utils.ts | 4 ++-- src/entities/Snapshot/constants.ts | 18 ++++++++------- src/entities/User/constants.ts | 4 ++-- src/entities/User/utils.ts | 6 ++--- src/helpers/index.ts | 4 ++-- src/utils/{env.ts => clientEnv.ts} | 2 +- src/utils/votes/utils.ts | 4 ++-- 9 files changed, 51 insertions(+), 48 deletions(-) rename src/utils/{env.ts => clientEnv.ts} (53%) diff --git a/src/constants.ts b/src/constants.ts index ac3560ba9..f6d3bb263 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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 || '' @@ -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()) diff --git a/src/entities/Proposal/constants.ts b/src/entities/Proposal/constants.ts index 71d4075f8..3882cd93c 100644 --- a/src/entities/Proposal/constants.ts +++ b/src/entities/Proposal/constants.ts @@ -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') diff --git a/src/entities/Proposal/utils.ts b/src/entities/Proposal/utils.ts index 3c37282e4..cc5cede32 100644 --- a/src/entities/Proposal/utils.ts +++ b/src/entities/Proposal/utils.ts @@ -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' @@ -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 diff --git a/src/entities/Snapshot/constants.ts b/src/entities/Snapshot/constants.ts index 91339f0cb..01e8b336e 100644 --- a/src/entities/Snapshot/constants.ts +++ b/src/entities/Snapshot/constants.ts @@ -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 || '' @@ -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') diff --git a/src/entities/User/constants.ts b/src/entities/User/constants.ts index ddf49bffe..a49db1ca2 100644 --- a/src/entities/User/constants.ts +++ b/src/entities/User/constants.ts @@ -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') diff --git a/src/entities/User/utils.ts b/src/entities/User/utils.ts index 0b14fb0f1..79bccf696 100644 --- a/src/entities/User/utils.ts +++ b/src/entities/User/utils.ts @@ -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) { diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 30a042002..5ef4b774d 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -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', @@ -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()) } diff --git a/src/utils/env.ts b/src/utils/clientEnv.ts similarity index 53% rename from src/utils/env.ts rename to src/utils/clientEnv.ts index 22ccf691b..add9c5b89 100644 --- a/src/utils/env.ts +++ b/src/utils/clientEnv.ts @@ -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) } diff --git a/src/utils/votes/utils.ts b/src/utils/votes/utils.ts index b139eeed4..d70f9bd26 100644 --- a/src/utils/votes/utils.ts +++ b/src/utils/votes/utils.ts @@ -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)