Skip to content

Commit

Permalink
refactor: Use IS_PRODUCTION directly, adjust isSocialWalletOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Nov 3, 2023
1 parent 0b0ea36 commit 7cbb240
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/services/mpc/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IS_PRODUCTION } from '@/config/constants'

enum SocialWalletOptionsKeys {
web3AuthClientId = 'web3AuthClientId',
web3AuthAggregateVerifierId = 'web3AuthAggregateVerifierId',
Expand All @@ -16,28 +18,24 @@ export const isSocialWalletOptions = (options: unknown): options is SocialWallet
if (typeof options !== 'object' || options === null) {
return false
}
const keys = Object.keys(options)

const hasRequiredKeys =
keys.length === 4 &&
keys.includes(SocialWalletOptionsKeys.web3AuthClientId) &&
keys.includes(SocialWalletOptionsKeys.web3AuthAggregateVerifierId) &&
keys.includes(SocialWalletOptionsKeys.web3AuthSubverifierId) &&
keys.includes(SocialWalletOptionsKeys.googleClientId)
SocialWalletOptionsKeys.web3AuthClientId in options &&
SocialWalletOptionsKeys.web3AuthAggregateVerifierId in options &&
SocialWalletOptionsKeys.web3AuthSubverifierId in options &&
SocialWalletOptionsKeys.googleClientId in options

const hasValues = Object.values(options).every(Boolean)
return hasRequiredKeys && hasValues
}

/** env variables */
const SOCIAL_WALLET_IS_PRODUCTION = process.env.NEXT_PUBLIC_IS_PRODUCTION === 'true'

export const SOCIAL_WALLET_OPTIONS: any = (() => {
const SOCIAL_WALLET_OPTIONS_PRODUCTION = process.env.NEXT_PUBLIC_SOCIAL_WALLET_OPTIONS_PRODUCTION || ''
const SOCIAL_WALLET_OPTIONS_STAGING = process.env.NEXT_PUBLIC_SOCIAL_WALLET_OPTIONS_STAGING || ''

try {
return JSON.parse(SOCIAL_WALLET_IS_PRODUCTION ? SOCIAL_WALLET_OPTIONS_PRODUCTION : SOCIAL_WALLET_OPTIONS_STAGING)
return JSON.parse(IS_PRODUCTION ? SOCIAL_WALLET_OPTIONS_PRODUCTION : SOCIAL_WALLET_OPTIONS_STAGING)
} catch (error) {
console.error(error)
return {}
Expand Down

0 comments on commit 7cbb240

Please sign in to comment.