diff --git a/src/configuration.ts b/src/configuration.ts index 77b3377..c48d74c 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -1,28 +1,31 @@ import { ChainId, ProviderType } from './types' -const configuration = Object.freeze({ - storageKey: 'some-random-key', +export function getConfiguration() { + return { + storageKey: getEnv('STORAGE_KEY'), - [ProviderType.INJECTED]: {}, - [ProviderType.FORTMATIC]: { - apiKeys: { - [ChainId.MAINNET]: 'pk_live_D7297F51E9776DD2', - [ChainId.ROPSTEN]: 'pk_test_198DDD3CA646DE2F', - [ChainId.RINKEBY]: 'pk_test_198DDD3CA646DE2F', - [ChainId.KOVAN]: 'pk_test_198DDD3CA646DE2F' - } - }, - [ProviderType.WALLET_CONNECT]: { - bridge: 'https://bridge.walletconnect.org', - urls: { - [ChainId.MAINNET]: 'https://', - [ChainId.ROPSTEN]: 'https://', - [ChainId.RINKEBY]: 'https://', - [ChainId.KOVAN]: 'https://' + [ProviderType.INJECTED]: {}, + + [ProviderType.FORTMATIC]: { + apiKeys: { + [ChainId.MAINNET]: getEnv('FORTMATIC_LIVE_KEY'), + [ChainId.ROPSTEN]: getEnv('FORTMATIC_TEST_KEY'), + [ChainId.RINKEBY]: getEnv('FORTMATIC_TEST_KEY'), + [ChainId.KOVAN]: getEnv('FORTMATIC_TEST_KEY') + } + }, + + [ProviderType.WALLET_CONNECT]: { + urls: { + [ChainId.MAINNET]: getEnv('WALLET_CONNECT_LIVE_RPC'), + [ChainId.ROPSTEN]: getEnv('WALLET_CONNECT_TEST_RPC'), + [ChainId.RINKEBY]: getEnv('WALLET_CONNECT_TEST_RPC'), + [ChainId.KOVAN]: getEnv('WALLET_CONNECT_TEST_RPC') + } } } -}) +} -export function getConfiguration() { - return configuration +function getEnv(key: string): string { + return process.env[key] || '' } diff --git a/src/connectors/WalletConnectConnector.ts b/src/connectors/WalletConnectConnector.ts index 1a4f6ad..ac1b58d 100644 --- a/src/connectors/WalletConnectConnector.ts +++ b/src/connectors/WalletConnectConnector.ts @@ -4,11 +4,10 @@ import { ChainId, ProviderType } from '../types' export class WalletConnectConnector extends BaseWalletConnectConnector { constructor(chainId: ChainId) { - const { bridge, urls } = getConfiguration()[ProviderType.WALLET_CONNECT] + const { urls } = getConfiguration()[ProviderType.WALLET_CONNECT] super({ rpc: { [chainId]: urls[chainId] }, - bridge, qrcode: true, pollingInterval: 15000 }) diff --git a/test/configuration.spec.ts b/test/configuration.spec.ts index 17bf022..15ade78 100644 --- a/test/configuration.spec.ts +++ b/test/configuration.spec.ts @@ -1,7 +1,45 @@ import { expect } from 'chai' +import { getConfiguration } from '../src/configuration' +import { ChainId, ProviderType } from '../src/types' -describe('test', () => { - it('passes', () => { - expect(true).to.eq(true) +describe('#getConfiguration', () => { + let env: NodeJS.ProcessEnv = process.env + + after(() => { + process.env = env + }) + + it('should return the configuration using the environment', () => { + process.env = { + STORAGE_KEY: 'storage-key', + + FORTMATIC_TEST_KEY: 'pk_test_198DDD3CA646DE2F', + FORTMATIC_LIVE_KEY: 'pk_live_D7297F51E9776DD2', + + WALLET_CONNECT_TEST_RPC: 'https://ropsten.mycustomnode.com', + WALLET_CONNECT_LIVE_RPC: 'https://mainnet.mycustomnode.com' + } + + expect(getConfiguration()).to.deep.eq({ + storageKey: 'storage-key', + + [ProviderType.INJECTED]: {}, + [ProviderType.FORTMATIC]: { + apiKeys: { + [ChainId.MAINNET]: 'pk_live_D7297F51E9776DD2', + [ChainId.ROPSTEN]: 'pk_test_198DDD3CA646DE2F', + [ChainId.RINKEBY]: 'pk_test_198DDD3CA646DE2F', + [ChainId.KOVAN]: 'pk_test_198DDD3CA646DE2F' + } + }, + [ProviderType.WALLET_CONNECT]: { + urls: { + [ChainId.MAINNET]: 'https://mainnet.mycustomnode.com', + [ChainId.ROPSTEN]: 'https://ropsten.mycustomnode.com', + [ChainId.RINKEBY]: 'https://ropsten.mycustomnode.com', + [ChainId.KOVAN]: 'https://ropsten.mycustomnode.com' + } + } + }) }) })