Skip to content

Commit 8d4c33f

Browse files
feat: configuration via env
1 parent fd2a2b7 commit 8d4c33f

File tree

3 files changed

+66
-26
lines changed

3 files changed

+66
-26
lines changed

src/configuration.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
import { ChainId, ProviderType } from './types'
22

3-
const configuration = Object.freeze({
4-
storageKey: 'some-random-key',
3+
export function getConfiguration() {
4+
return {
5+
storageKey: getEnv('STORAGE_KEY'),
56

6-
[ProviderType.INJECTED]: {},
7-
[ProviderType.FORTMATIC]: {
8-
apiKeys: {
9-
[ChainId.MAINNET]: 'pk_live_D7297F51E9776DD2',
10-
[ChainId.ROPSTEN]: 'pk_test_198DDD3CA646DE2F',
11-
[ChainId.RINKEBY]: 'pk_test_198DDD3CA646DE2F',
12-
[ChainId.KOVAN]: 'pk_test_198DDD3CA646DE2F'
13-
}
14-
},
15-
[ProviderType.WALLET_CONNECT]: {
16-
bridge: 'https://bridge.walletconnect.org',
17-
urls: {
18-
[ChainId.MAINNET]: 'https://',
19-
[ChainId.ROPSTEN]: 'https://',
20-
[ChainId.RINKEBY]: 'https://',
21-
[ChainId.KOVAN]: 'https://'
7+
[ProviderType.INJECTED]: {},
8+
9+
[ProviderType.FORTMATIC]: {
10+
apiKeys: {
11+
[ChainId.MAINNET]: getEnv('FORTMATIC_LIVE_KEY'),
12+
[ChainId.ROPSTEN]: getEnv('FORTMATIC_TEST_KEY'),
13+
[ChainId.RINKEBY]: getEnv('FORTMATIC_TEST_KEY'),
14+
[ChainId.KOVAN]: getEnv('FORTMATIC_TEST_KEY')
15+
}
16+
},
17+
18+
[ProviderType.WALLET_CONNECT]: {
19+
urls: {
20+
[ChainId.MAINNET]: getEnv('WALLET_CONNECT_LIVE_RPC'),
21+
[ChainId.ROPSTEN]: getEnv('WALLET_CONNECT_TEST_RPC'),
22+
[ChainId.RINKEBY]: getEnv('WALLET_CONNECT_TEST_RPC'),
23+
[ChainId.KOVAN]: getEnv('WALLET_CONNECT_TEST_RPC')
24+
}
2225
}
2326
}
24-
})
27+
}
2528

26-
export function getConfiguration() {
27-
return configuration
29+
function getEnv(key: string): string {
30+
return process.env[key] || ''
2831
}

src/connectors/WalletConnectConnector.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import { ChainId, ProviderType } from '../types'
44

55
export class WalletConnectConnector extends BaseWalletConnectConnector {
66
constructor(chainId: ChainId) {
7-
const { bridge, urls } = getConfiguration()[ProviderType.WALLET_CONNECT]
7+
const { urls } = getConfiguration()[ProviderType.WALLET_CONNECT]
88

99
super({
1010
rpc: { [chainId]: urls[chainId] },
11-
bridge,
1211
qrcode: true,
1312
pollingInterval: 15000
1413
})

test/configuration.spec.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,45 @@
11
import { expect } from 'chai'
2+
import { getConfiguration } from '../src/configuration'
3+
import { ChainId, ProviderType } from '../src/types'
24

3-
describe('test', () => {
4-
it('passes', () => {
5-
expect(true).to.eq(true)
5+
describe('#getConfiguration', () => {
6+
let env: NodeJS.ProcessEnv = process.env
7+
8+
after(() => {
9+
process.env = env
10+
})
11+
12+
it('should return the configuration using the environment', () => {
13+
process.env = {
14+
STORAGE_KEY: 'storage-key',
15+
16+
FORTMATIC_TEST_KEY: 'pk_test_198DDD3CA646DE2F',
17+
FORTMATIC_LIVE_KEY: 'pk_live_D7297F51E9776DD2',
18+
19+
WALLET_CONNECT_TEST_RPC: 'https://ropsten.mycustomnode.com',
20+
WALLET_CONNECT_LIVE_RPC: 'https://mainnet.mycustomnode.com'
21+
}
22+
23+
expect(getConfiguration()).to.deep.eq({
24+
storageKey: 'storage-key',
25+
26+
[ProviderType.INJECTED]: {},
27+
[ProviderType.FORTMATIC]: {
28+
apiKeys: {
29+
[ChainId.MAINNET]: 'pk_live_D7297F51E9776DD2',
30+
[ChainId.ROPSTEN]: 'pk_test_198DDD3CA646DE2F',
31+
[ChainId.RINKEBY]: 'pk_test_198DDD3CA646DE2F',
32+
[ChainId.KOVAN]: 'pk_test_198DDD3CA646DE2F'
33+
}
34+
},
35+
[ProviderType.WALLET_CONNECT]: {
36+
urls: {
37+
[ChainId.MAINNET]: 'https://mainnet.mycustomnode.com',
38+
[ChainId.ROPSTEN]: 'https://ropsten.mycustomnode.com',
39+
[ChainId.RINKEBY]: 'https://ropsten.mycustomnode.com',
40+
[ChainId.KOVAN]: 'https://ropsten.mycustomnode.com'
41+
}
42+
}
43+
})
644
})
745
})

0 commit comments

Comments
 (0)