diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-03-06 08:13:47 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-03-06 08:13:47 +0800 |
commit | 38a4ccd9f24cd1cd583c17ebc200238e1770e5f8 (patch) | |
tree | d0647ebcb590cf8ec6eb73583d505d5623faa006 /packages/sra-report/src/postman_environment_factory.ts | |
parent | cf342dd00eaae8667984e77eb565040c132f160a (diff) | |
download | dexon-sol-tools-38a4ccd9f24cd1cd583c17ebc200238e1770e5f8.tar.gz dexon-sol-tools-38a4ccd9f24cd1cd583c17ebc200238e1770e5f8.tar.zst dexon-sol-tools-38a4ccd9f24cd1cd583c17ebc200238e1770e5f8.zip |
Change all globals in environment variables
Diffstat (limited to 'packages/sra-report/src/postman_environment_factory.ts')
-rw-r--r-- | packages/sra-report/src/postman_environment_factory.ts | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/packages/sra-report/src/postman_environment_factory.ts b/packages/sra-report/src/postman_environment_factory.ts index a8753d9ff..7534baaaf 100644 --- a/packages/sra-report/src/postman_environment_factory.ts +++ b/packages/sra-report/src/postman_environment_factory.ts @@ -2,8 +2,8 @@ import { SignedOrder, ZeroEx } from '0x.js'; import { Schema, schemas as schemasByName } from '@0xproject/json-schemas'; import * as _ from 'lodash'; -import * as kovanTokensEnvironmentJSON from '../postman_configs/environments/kovan_tokens.postman_environment.json'; -import * as mainnetTokensEnvironmentJSON from '../postman_configs/environments/mainnet_tokens.postman_environment.json'; +import { addresses as kovanAddresses} from './contract_addresses/kovan_addresses'; +import { addresses as mainnetAddresses} from './contract_addresses/mainnet_addresses'; interface EnvironmentValue { key: string; @@ -13,7 +13,7 @@ interface EnvironmentValue { } export const postmanEnvironmentFactory = { - createGlobalEnvironment(url: string, order: SignedOrder) { + createPostmanEnvironment(url: string, networkId: number, order: SignedOrder) { const schemas: Schema[] = _.values(schemasByName); const schemaEnvironmentValues = _.compact( _.map(schemas, (schema: Schema) => { @@ -30,8 +30,14 @@ export const postmanEnvironmentFactory = { const schemaKeys = _.map(schemaEnvironmentValues, (environmentValue: EnvironmentValue) => { return environmentValue.key; }); + const contractAddresses = getContractAddresses(networkId); + const contractAddressEnvironmentValues = _.map(_.keys(contractAddresses), (key: string) => { + const contractAddress = _.get(contractAddresses, key); + return createEnvironmentValue(key, contractAddress); + }); const allEnvironmentValues = _.concat( schemaEnvironmentValues, + contractAddressEnvironmentValues, createEnvironmentValue('schemaKeys', JSON.stringify(schemaKeys)), createEnvironmentValue('url', url), createEnvironmentValue('order', JSON.stringify(order)), @@ -45,17 +51,17 @@ export const postmanEnvironmentFactory = { }; return environment; }, - createNetworkEnvironment(networkId: number) { - switch (networkId) { - case 1: - return mainnetTokensEnvironmentJSON; - case 42: - return kovanTokensEnvironmentJSON; - default: - return {}; - } - }, }; +function getContractAddresses(networkId: number) { + switch (networkId) { + case 1: + return mainnetAddresses; + case 42: + return kovanAddresses; + default: + throw new Error('Unsupported network id'); + } +} function convertSchemaIdToKey(schemaId: string) { let result = schemaId; if (_.startsWith(result, '/')) { |