Skip to content

Commit

Permalink
Consolidate usages of process.env.DEBUG (#240)
Browse files Browse the repository at this point in the history
* Consolidate usages of process.env.DEBUG

* Set a global rather than use process.env

* Fix reference error
  • Loading branch information
corbanbrook authored Jan 16, 2025
1 parent 629db5d commit b3fa90e
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 30 deletions.
5 changes: 4 additions & 1 deletion examples/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import ReactDOM from 'react-dom/client'
import './index.css'
import { App } from './App'

console.log('VERSION:', process.env.PACKAGE_VERSION)
// @ts-ignore
console.log('VERSION:', __SEQUENCE_KIT_PACKAGE_VERSION__)
// @ts-ignore
console.log('DEBUG: ', __SEQUENCE_KIT_DEBUG__)

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)
root.render(<App />)
4 changes: 2 additions & 2 deletions examples/react/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default defineConfig(() => {
svgrPlugin()
],
define: {
'process.env.PACKAGE_VERSION': JSON.stringify(process.env.npm_package_version),
'process.env.DEBUG': JSON.stringify(process.env.DEBUG || false)
__SEQUENCE_KIT_PACKAGE_VERSION__: JSON.stringify(process.env.npm_package_version),
__SEQUENCE_KIT_DEBUG__: JSON.stringify(process.env.DEBUG || false)
},
resolve: {
dedupe: ['wagmi', 'viem']
Expand Down
9 changes: 5 additions & 4 deletions packages/checkout/src/api/data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEBUG } from '@0xsequence/kit'
import { TokenMetadata } from '@0xsequence/metadata'
import { ChainId, networks } from '@0xsequence/network'

Expand All @@ -24,8 +25,8 @@ export const fetchSardineClientToken = async ({
tokenMetadata
}: FetchSardineClientTokenArgs): Promise<FetchSardineClientTokenReturn> => {
// Test credentials: https://docs.sardine.ai/docs/integrate-payments/nft-checkout-testing-credentials
const accessKey = process.env.DEBUG ? '17xhjK4yjRf1fr0am8kgKfICAAAAAAAAA' : projectAccessKey
const url = process.env.DEBUG
const accessKey = DEBUG ? '17xhjK4yjRf1fr0am8kgKfICAAAAAAAAA' : projectAccessKey
const url = DEBUG
? 'https://dev-api.sequence.app/rpc/API/SardineGetNFTCheckoutToken'
: 'https://api.sequence.app/rpc/API/SardineGetNFTCheckoutToken'

Expand Down Expand Up @@ -68,8 +69,8 @@ export const fetchSardineClientToken = async ({

export const fetchSardineOrderStatus = async (orderId: string, projectAccessKey: string) => {
// Test credentials: https://docs.sardine.ai/docs/integrate-payments/nft-checkout-testing-credentials
const accessKey = process.env.DEBUG ? '17xhjK4yjRf1fr0am8kgKfICAAAAAAAAA' : projectAccessKey
const url = process.env.DEBUG
const accessKey = DEBUG ? '17xhjK4yjRf1fr0am8kgKfICAAAAAAAAA' : projectAccessKey
const url = DEBUG
? 'https://dev-api.sequence.app/rpc/API/SardineGetNFTCheckoutOrderStatus'
: 'https://api.sequence.app/rpc/API/SardineGetNFTCheckoutOrderStatus'
const response = await fetch(url, {
Expand Down
4 changes: 2 additions & 2 deletions packages/checkout/src/hooks/useMarketplaceClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useProjectAccessKey } from '@0xsequence/kit'
import { DEBUG, useProjectAccessKey } from '@0xsequence/kit'
import { MarketplaceIndexer } from '@0xsequence/marketplace'
import { networks, stringTemplate } from '@0xsequence/network'
import { useMemo } from 'react'
Expand All @@ -11,7 +11,7 @@ export const useMarketplaceClient = ({ chain }: UseMarketplaceClientArgs) => {
const projectAccessKey = useProjectAccessKey()

const marketplaceClient = useMemo(() => {
const env = process.env.DEBUG ? 'development' : 'production'
const env = DEBUG ? 'development' : 'production'
const clientUrl = marketplaceApiURL(chain, env)
return new MarketplaceIndexer(clientUrl, projectAccessKey)
}, [projectAccessKey])
Expand Down
5 changes: 3 additions & 2 deletions packages/checkout/src/utils/sardine.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEBUG } from '@0xsequence/kit'
import { ChainId, networks } from '@0xsequence/network'
import { ethers } from 'ethers'

Expand All @@ -12,9 +13,9 @@ export const checkSardineWhitelistStatus = async (
) => {
const referenceId = `sequence-kit-sardine-whitelist-check`

const accessKey = process.env.DEBUG ? '17xhjK4yjRf1fr0am8kgKfICAAAAAAAAA' : projectAccessKey
const accessKey = DEBUG ? '17xhjK4yjRf1fr0am8kgKfICAAAAAAAAA' : projectAccessKey

const url = process.env.DEBUG
const url = DEBUG
? 'https://dev-api.sequence.app/rpc/API/SardineGetNFTCheckoutToken'
: 'https://api.sequence.app/rpc/API/SardineGetNFTCheckoutToken'

Expand Down
10 changes: 6 additions & 4 deletions packages/checkout/src/utils/transak.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { DEBUG } from '@0xsequence/kit'

import { AddFundsSettings } from '../contexts'

export const TRANSAK_API_KEY = '5911d9ec-46b5-48fa-a755-d59a715ff0cf'
export const TRANSAK_API_KEY_STAGING = 'c20f2a0e-fe6a-4133-8fa7-77e9f84edf98'
export const TRANSAK_PROXY_ADDRESS = '0x4a598b7ec77b1562ad0df7dc64a162695ce4c78a'

const TransakUrlProd = 'https://global.transak.com';
const TransakUrlSandbox = 'https://global-stg.transak.com';
const TransakUrlProd = 'https://global.transak.com'
const TransakUrlSandbox = 'https://global-stg.transak.com'

export const getTransakLink = (addFundsSettings: AddFundsSettings) => {
const defaultNetworks =
Expand All @@ -15,8 +17,8 @@ export const getTransakLink = (addFundsSettings: AddFundsSettings) => {
[index: string]: string | undefined
}

const url = new URL(process.env.DEBUG ? TransakUrlSandbox : TransakUrlProd);
const apiKey = process.env.DEBUG ? TRANSAK_API_KEY_STAGING : TRANSAK_API_KEY;
const url = new URL(DEBUG ? TransakUrlSandbox : TransakUrlProd)
const apiKey = DEBUG ? TRANSAK_API_KEY_STAGING : TRANSAK_API_KEY

const options: Options = {
apiKey: apiKey,
Expand Down
6 changes: 3 additions & 3 deletions packages/checkout/src/views/PendingCreditCardTransaction.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Spinner, Text } from '@0xsequence/design-system'
import { useProjectAccessKey, useContractInfo, useTokenMetadata } from '@0xsequence/kit'
import { useProjectAccessKey, useContractInfo, useTokenMetadata, DEBUG } from '@0xsequence/kit'
import { findSupportedNetwork } from '@0xsequence/network'
import pako from 'pako'
import { useEffect } from 'react'
Expand Down Expand Up @@ -68,7 +68,7 @@ export const PendingCreditCardTransactionTransak = ({ skipOnCloseCallback }: Pen

const transakConfig = settings?.creditCardCheckout?.transakConfig

const baseUrl = process.env.DEBUG ? 'https://global-stg.transak.com' : 'https://global.transak.com'
const baseUrl = DEBUG ? 'https://global-stg.transak.com' : 'https://global.transak.com'

// Transak requires the recipient address to be the proxy address
// so we need to replace the recipient address with the proxy address in the calldata
Expand Down Expand Up @@ -256,7 +256,7 @@ export const PendingCreditCardTransactionSardine = ({ skipOnCloseCallback }: Pen

const authToken = data?.token

const url = process.env.DEBUG
const url = DEBUG
? `https://sardine-checkout-sandbox.sequence.info?api_url=https://sardine-api-sandbox.sequence.info&client_token=${authToken}&show_features=true`
: `https://sardine-checkout.sequence.info?api_url=https://sardine-api.sequence.info&client_token=${authToken}&show_features=true`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { createConnector } from 'wagmi'

import { LocalStorageKey } from '../../constants/localStorage'
import { DEBUG } from '../../env'

export interface SequenceWaasConnectConfig {
googleClientId?: string
Expand Down Expand Up @@ -51,7 +52,7 @@ export function sequenceWaasWallet(params: BaseSequenceWaasConnectorOptions) {
[LocalStorageKey.WaasSignInEmail]: string
}

const nodesUrl = process.env.DEBUG ? 'https://dev-nodes.sequence.app' : 'https://nodes.sequence.app'
const nodesUrl = DEBUG ? 'https://dev-nodes.sequence.app' : 'https://nodes.sequence.app'

const showConfirmationModal = params.enableConfirmationModal ?? false

Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-ignore
export const DEBUG = !!globalThis.__SEQUENCE_KIT_DEBUG__
4 changes: 2 additions & 2 deletions packages/kit/src/hooks/useAPIClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { SequenceAPIClient } from '@0xsequence/api'
import { useMemo } from 'react'

import { useKitConfig } from '../contexts/KitConfig'
import { DEBUG } from '../env'

import { useProjectAccessKey } from './useProjectAccessKey'

export const useAPIClient = () => {
const projectAccessKey = useProjectAccessKey()

const clientUrl = process.env.DEBUG ? 'https://dev-api.sequence.app' : 'https://api.sequence.app'
const clientUrl = DEBUG ? 'https://dev-api.sequence.app' : 'https://api.sequence.app'

const apiClient = useMemo(() => {
return new SequenceAPIClient(clientUrl, projectAccessKey)
Expand Down
10 changes: 3 additions & 7 deletions packages/kit/src/hooks/useIndexerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SequenceIndexer } from '@0xsequence/indexer'
import { ChainId, networks } from '@0xsequence/network'
import { useMemo } from 'react'

import { useKitConfig } from '../contexts/KitConfig'
import { DEBUG } from '../env'

import { useProjectAccessKey } from './useProjectAccessKey'

Expand All @@ -14,9 +14,7 @@ export const useIndexerClient = (chainId: ChainId) => {
}, [projectAccessKey])

const network = networks[chainId]
const clientUrl = process.env.DEBUG
? `https://dev-${network.name}-indexer.sequence.app`
: `https://${network.name}-indexer.sequence.app`
const clientUrl = DEBUG ? `https://dev-${network.name}-indexer.sequence.app` : `https://${network.name}-indexer.sequence.app`

if (!indexerClients.has(chainId)) {
indexerClients.set(chainId, new SequenceIndexer(clientUrl, projectAccessKey))
Expand All @@ -42,9 +40,7 @@ export const useIndexerClients = (chainIds: ChainId[]) => {

for (const chainId of chainIds) {
const network = networks[chainId]
const clientUrl = process.env.DEBUG
? `https://dev-${network.name}-indexer.sequence.app`
: `https://${network.name}-indexer.sequence.app`
const clientUrl = DEBUG ? `https://dev-${network.name}-indexer.sequence.app` : `https://${network.name}-indexer.sequence.app`

if (!indexerClients.has(chainId)) {
indexerClients.set(chainId, new SequenceIndexer(clientUrl, projectAccessKey))
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/hooks/useMetadataClient.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { SequenceMetadata } from '@0xsequence/metadata'
import { useMemo } from 'react'

import { useKitConfig } from '../contexts/KitConfig'
import { DEBUG } from '../env'

import { useProjectAccessKey } from './useProjectAccessKey'

export const useMetadataClient = () => {
const projectAccessKey = useProjectAccessKey()

const metadataClient = useMemo(() => {
const clientUrl = process.env.DEBUG ? 'https://dev-metadata.sequence.app' : 'https://metadata.sequence.app'
const clientUrl = DEBUG ? 'https://dev-metadata.sequence.app' : 'https://metadata.sequence.app'

return new SequenceMetadata(clientUrl, projectAccessKey)
}, [projectAccessKey])
Expand Down
3 changes: 3 additions & 0 deletions packages/kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ export { CollectibleTileImage } from './components/CollectibleTileImage'

// Indexer
export { ContractVerificationStatus } from '@0xsequence/indexer'

// XXX
export { DEBUG } from './env'

0 comments on commit b3fa90e

Please sign in to comment.