From b75fe10c790a60c875914a2a79ae8c4761b78bb9 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 17 Oct 2018 00:49:48 -0700 Subject: feat(contract-wrappers): export ForwarderWrapperError and ContractWrapperError.SignatureRequestDenied --- packages/contract-wrappers/src/utils/constants.ts | 1 + packages/contract-wrappers/src/utils/decorators.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'packages/contract-wrappers/src/utils') diff --git a/packages/contract-wrappers/src/utils/constants.ts b/packages/contract-wrappers/src/utils/constants.ts index 9ff61f62a..b89438592 100644 --- a/packages/contract-wrappers/src/utils/constants.ts +++ b/packages/contract-wrappers/src/utils/constants.ts @@ -14,4 +14,5 @@ export const constants = { ZERO_AMOUNT: new BigNumber(0), ONE_AMOUNT: new BigNumber(1), ETHER_TOKEN_DECIMALS: 18, + METAMASK_DENIED_SIGNATURE_PATTERN: 'MetaMask Tx Signature: User denied transaction signature', }; diff --git a/packages/contract-wrappers/src/utils/decorators.ts b/packages/contract-wrappers/src/utils/decorators.ts index e17246015..932b11785 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.METAMASK_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), -- cgit v1.2.3 From af2bf053bc9cfe80618109dc10a90515d780cd25 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 22 Oct 2018 22:23:32 -0700 Subject: feat(contract-wrappers): relax requirement for throwing `ContractWrappersError.SignatureRequestDenied` --- packages/contract-wrappers/src/utils/constants.ts | 2 +- packages/contract-wrappers/src/utils/decorators.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/contract-wrappers/src/utils') diff --git a/packages/contract-wrappers/src/utils/constants.ts b/packages/contract-wrappers/src/utils/constants.ts index b89438592..c587ba526 100644 --- a/packages/contract-wrappers/src/utils/constants.ts +++ b/packages/contract-wrappers/src/utils/constants.ts @@ -14,5 +14,5 @@ export const constants = { ZERO_AMOUNT: new BigNumber(0), ONE_AMOUNT: new BigNumber(1), ETHER_TOKEN_DECIMALS: 18, - METAMASK_DENIED_SIGNATURE_PATTERN: 'MetaMask Tx Signature: User denied transaction signature', + USER_DENIED_SIGNATURE_PATTERN: 'User denied transaction signature', }; diff --git a/packages/contract-wrappers/src/utils/decorators.ts b/packages/contract-wrappers/src/utils/decorators.ts index 932b11785..a4207ae4c 100644 --- a/packages/contract-wrappers/src/utils/decorators.ts +++ b/packages/contract-wrappers/src/utils/decorators.ts @@ -30,7 +30,7 @@ const schemaErrorTransformer = (error: Error) => { }; const signatureRequestErrorTransformer = (error: Error) => { - if (_.includes(error.message, constants.METAMASK_DENIED_SIGNATURE_PATTERN)) { + if (_.includes(error.message, constants.USER_DENIED_SIGNATURE_PATTERN)) { const errMsg = ContractWrappersError.SignatureRequestDenied; return new Error(errMsg); } -- cgit v1.2.3