Skip to content

Commit

Permalink
feat: configuration via env
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo committed Dec 17, 2020
1 parent fd2a2b7 commit 8d4c33f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
45 changes: 24 additions & 21 deletions src/configuration.ts
Original file line number Diff line number Diff line change
@@ -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] || ''
}
3 changes: 1 addition & 2 deletions src/connectors/WalletConnectConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
44 changes: 41 additions & 3 deletions test/configuration.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
}
}
})
})
})

0 comments on commit 8d4c33f

Please sign in to comment.