-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: environment config for social wallet (#2728)
* refactor: environment config for social wallet * refactor: Use IS_PRODUCTION directly, adjust isSocialWalletOptions * fix: Failing tests * fix: Adjust error message --------- Co-authored-by: Usame Algan <[email protected]>
- Loading branch information
1 parent
c81b9fb
commit 53d95cd
Showing
7 changed files
with
61 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { IS_PRODUCTION } from '@/config/constants' | ||
|
||
enum SocialWalletOptionsKeys { | ||
web3AuthClientId = 'web3AuthClientId', | ||
web3AuthAggregateVerifierId = 'web3AuthAggregateVerifierId', | ||
web3AuthSubverifierId = 'web3AuthSubverifierId', | ||
googleClientId = 'googleClientId', | ||
} | ||
|
||
export type SocialWalletOptions = { | ||
[SocialWalletOptionsKeys.web3AuthClientId]: string | ||
[SocialWalletOptionsKeys.web3AuthAggregateVerifierId]: string | ||
[SocialWalletOptionsKeys.web3AuthSubverifierId]: string | ||
[SocialWalletOptionsKeys.googleClientId]: string | ||
} | ||
|
||
export const isSocialWalletOptions = (options: unknown): options is SocialWalletOptions => { | ||
if (typeof options !== 'object' || options === null) { | ||
return false | ||
} | ||
|
||
const requiredKeys = Object.values(SocialWalletOptionsKeys) | ||
const hasRequiredKeys = requiredKeys.every((key) => key in options) | ||
const hasValues = Object.values(options).every(Boolean) | ||
|
||
return hasRequiredKeys && hasValues | ||
} | ||
|
||
/** env variables */ | ||
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(IS_PRODUCTION ? SOCIAL_WALLET_OPTIONS_PRODUCTION : SOCIAL_WALLET_OPTIONS_STAGING) | ||
} catch (error) { | ||
console.error('Error parsing SOCIAL_WALLET_OPTIONS', error) | ||
return {} | ||
} | ||
})() |