aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/src/utils
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-10-11 07:52:35 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-10-16 04:38:59 +0800
commitc83dec22c9e70cec2b75c9e5051f37124baa2761 (patch)
tree755433a9924bc818f0b4759795a349c4cd7b0dee /packages/contract-wrappers/src/utils
parent974ec23ecd2a445523e0550c0a7f69329d6959f1 (diff)
downloaddexon-sol-tools-c83dec22c9e70cec2b75c9e5051f37124baa2761.tar
dexon-sol-tools-c83dec22c9e70cec2b75c9e5051f37124baa2761.tar.gz
dexon-sol-tools-c83dec22c9e70cec2b75c9e5051f37124baa2761.tar.bz2
dexon-sol-tools-c83dec22c9e70cec2b75c9e5051f37124baa2761.tar.lz
dexon-sol-tools-c83dec22c9e70cec2b75c9e5051f37124baa2761.tar.xz
dexon-sol-tools-c83dec22c9e70cec2b75c9e5051f37124baa2761.tar.zst
dexon-sol-tools-c83dec22c9e70cec2b75c9e5051f37124baa2761.zip
Improve error handling for unknown network ids in contract-wrappers
Diffstat (limited to 'packages/contract-wrappers/src/utils')
-rw-r--r--packages/contract-wrappers/src/utils/contract_addresses.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/packages/contract-wrappers/src/utils/contract_addresses.ts b/packages/contract-wrappers/src/utils/contract_addresses.ts
new file mode 100644
index 000000000..c32907c24
--- /dev/null
+++ b/packages/contract-wrappers/src/utils/contract_addresses.ts
@@ -0,0 +1,13 @@
+import { ContractAddresses, getContractAddressesForNetwork, NetworkId } from '@0xproject/contract-addresses';
+import * as _ from 'lodash';
+
+// Returns the default contract addresses for the given networkId or throws with
+// a context-specific error message if the networkId is not recognized.
+export function _getDefaultContractAddresses(networkId: number): ContractAddresses {
+ if (!(networkId in NetworkId)) {
+ throw new Error(
+ `No default contract addresses found for the given network id (${networkId}). If you want to use ContractWrappers on this network, you must manually pass in the contract address(es) to the constructor.`,
+ );
+ }
+ return getContractAddressesForNetwork(networkId);
+}