diff options
Diffstat (limited to 'packages/contract-wrappers/src/utils')
8 files changed, 51 insertions, 19 deletions
diff --git a/packages/contract-wrappers/src/utils/assert.ts b/packages/contract-wrappers/src/utils/assert.ts index 30726c546..3f02ed052 100644 --- a/packages/contract-wrappers/src/utils/assert.ts +++ b/packages/contract-wrappers/src/utils/assert.ts @@ -1,10 +1,10 @@ -import { assert as sharedAssert } from '@0xproject/assert'; +import { assert as sharedAssert } from '@0x/assert'; // HACK: We need those two unused imports because they're actually used by sharedAssert which gets injected here -import { Schema } from '@0xproject/json-schemas'; // tslint:disable-line:no-unused-variable -import { assetDataUtils, signatureUtils } from '@0xproject/order-utils'; -import { Order } from '@0xproject/types'; // tslint:disable-line:no-unused-variable -import { BigNumber } from '@0xproject/utils'; // tslint:disable-line:no-unused-variable -import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Schema } from '@0x/json-schemas'; // tslint:disable-line:no-unused-variable +import { assetDataUtils, signatureUtils } from '@0x/order-utils'; +import { Order } from '@0x/types'; // tslint:disable-line:no-unused-variable +import { BigNumber } from '@0x/utils'; // tslint:disable-line:no-unused-variable +import { Web3Wrapper } from '@0x/web3-wrapper'; import { Provider } from 'ethereum-types'; import * as _ from 'lodash'; diff --git a/packages/contract-wrappers/src/utils/calldata_optimization_utils.ts b/packages/contract-wrappers/src/utils/calldata_optimization_utils.ts index 3172cf531..bee7acaa7 100644 --- a/packages/contract-wrappers/src/utils/calldata_optimization_utils.ts +++ b/packages/contract-wrappers/src/utils/calldata_optimization_utils.ts @@ -1,4 +1,4 @@ -import { SignedOrder } from '@0xproject/types'; +import { SignedOrder } from '@0x/types'; import * as _ from 'lodash'; import { constants } from './constants'; diff --git a/packages/contract-wrappers/src/utils/constants.ts b/packages/contract-wrappers/src/utils/constants.ts index 78441decf..c587ba526 100644 --- a/packages/contract-wrappers/src/utils/constants.ts +++ b/packages/contract-wrappers/src/utils/constants.ts @@ -1,4 +1,4 @@ -import { BigNumber } from '@0xproject/utils'; +import { BigNumber } from '@0x/utils'; export const constants = { NULL_ADDRESS: '0x0000000000000000000000000000000000000000', @@ -14,4 +14,5 @@ export const constants = { ZERO_AMOUNT: new BigNumber(0), ONE_AMOUNT: new BigNumber(1), ETHER_TOKEN_DECIMALS: 18, + USER_DENIED_SIGNATURE_PATTERN: 'User denied transaction signature', }; 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..dc156e017 --- /dev/null +++ b/packages/contract-wrappers/src/utils/contract_addresses.ts @@ -0,0 +1,15 @@ +import { ContractAddresses, getContractAddressesForNetworkOrThrow, NetworkId } from '@0x/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 getContractAddressesForNetworkOrThrow(networkId); +} diff --git a/packages/contract-wrappers/src/utils/decorators.ts b/packages/contract-wrappers/src/utils/decorators.ts index e17246015..a4207ae4c 100644 --- a/packages/contract-wrappers/src/utils/decorators.ts +++ b/packages/contract-wrappers/src/utils/decorators.ts @@ -29,6 +29,14 @@ const schemaErrorTransformer = (error: Error) => { return error; }; +const signatureRequestErrorTransformer = (error: Error) => { + if (_.includes(error.message, constants.USER_DENIED_SIGNATURE_PATTERN)) { + const errMsg = ContractWrappersError.SignatureRequestDenied; + return new Error(errMsg); + } + return error; +}; + /** * Source: https://stackoverflow.com/a/29837695/3546986 */ @@ -87,7 +95,11 @@ const syncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => { }; // _.flow(f, g) = f ∘ g -const zeroExErrorTransformer = _.flow(schemaErrorTransformer, contractCallErrorTransformer); +const zeroExErrorTransformer = _.flow( + schemaErrorTransformer, + contractCallErrorTransformer, + signatureRequestErrorTransformer, +); export const decorators = { asyncZeroExErrorHandler: asyncErrorHandlerFactory(zeroExErrorTransformer), diff --git a/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts b/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts index a7c4a238f..f374d509b 100644 --- a/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts +++ b/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts @@ -1,5 +1,5 @@ -import { ExchangeContractErrs } from '@0xproject/types'; -import { BigNumber } from '@0xproject/utils'; +import { ExchangeContractErrs } from '@0x/types'; +import { BigNumber } from '@0x/utils'; import { AbstractBalanceAndProxyAllowanceLazyStore } from '../abstract/abstract_balance_and_proxy_allowance_lazy_store'; import { TradeSide, TransferType } from '../types'; diff --git a/packages/contract-wrappers/src/utils/transaction_encoder.ts b/packages/contract-wrappers/src/utils/transaction_encoder.ts index 33086944b..0cf08a8fe 100644 --- a/packages/contract-wrappers/src/utils/transaction_encoder.ts +++ b/packages/contract-wrappers/src/utils/transaction_encoder.ts @@ -1,10 +1,10 @@ -import { schemas } from '@0xproject/json-schemas'; -import { eip712Utils } from '@0xproject/order-utils'; -import { Order, SignedOrder } from '@0xproject/types'; -import { BigNumber, signTypedDataUtils } from '@0xproject/utils'; -import _ = require('lodash'); +import { ExchangeContract } from '@0x/abi-gen-wrappers'; -import { ExchangeContract } from '../contract_wrappers/generated/exchange'; +import { schemas } from '@0x/json-schemas'; +import { eip712Utils } from '@0x/order-utils'; +import { Order, SignedOrder } from '@0x/types'; +import { BigNumber, signTypedDataUtils } from '@0x/utils'; +import _ = require('lodash'); import { assert } from './assert'; diff --git a/packages/contract-wrappers/src/utils/utils.ts b/packages/contract-wrappers/src/utils/utils.ts index f7949ec34..0b3270e78 100644 --- a/packages/contract-wrappers/src/utils/utils.ts +++ b/packages/contract-wrappers/src/utils/utils.ts @@ -1,5 +1,6 @@ -import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { BigNumber } from '@0x/utils'; +import { Web3Wrapper } from '@0x/web3-wrapper'; +import * as _ from 'lodash'; import { constants } from './constants'; @@ -14,4 +15,7 @@ export const utils = { numberPercentageToEtherTokenAmountPercentage(percentage: number): BigNumber { return Web3Wrapper.toBaseUnitAmount(constants.ONE_AMOUNT, constants.ETHER_TOKEN_DECIMALS).mul(percentage); }, + removeUndefinedProperties<T extends object>(obj: T): Partial<T> { + return _.pickBy(obj); + }, }; |