aboutsummaryrefslogtreecommitdiffstats
path: root/packages/asset-buyer/src
diff options
context:
space:
mode:
authorBrandon Millman <brandon@0xproject.com>2018-10-24 01:33:33 +0800
committerGitHub <noreply@github.com>2018-10-24 01:33:33 +0800
commit37f87ab267c5eb10c70d7eb4d3eef01bf8ed7ac1 (patch)
treec75d060dce57b3f89a7122609fc0ca46e751eae6 /packages/asset-buyer/src
parent104b2ed7592eeccf73d649390b11196462780e20 (diff)
parentaf2bf053bc9cfe80618109dc10a90515d780cd25 (diff)
downloaddexon-sol-tools-37f87ab267c5eb10c70d7eb4d3eef01bf8ed7ac1.tar
dexon-sol-tools-37f87ab267c5eb10c70d7eb4d3eef01bf8ed7ac1.tar.gz
dexon-sol-tools-37f87ab267c5eb10c70d7eb4d3eef01bf8ed7ac1.tar.bz2
dexon-sol-tools-37f87ab267c5eb10c70d7eb4d3eef01bf8ed7ac1.tar.lz
dexon-sol-tools-37f87ab267c5eb10c70d7eb4d3eef01bf8ed7ac1.tar.xz
dexon-sol-tools-37f87ab267c5eb10c70d7eb4d3eef01bf8ed7ac1.tar.zst
dexon-sol-tools-37f87ab267c5eb10c70d7eb4d3eef01bf8ed7ac1.zip
Merge pull request #1147 from 0xProject/feature/asset-buyer/signing-request-error
[asset-buyer][contract-wrappers] Throw SignatureRequestDenied and TransactionValueTooLow errors from AssetBuyer
Diffstat (limited to 'packages/asset-buyer/src')
-rw-r--r--packages/asset-buyer/src/asset_buyer.ts43
-rw-r--r--packages/asset-buyer/src/types.ts2
2 files changed, 29 insertions, 16 deletions
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts
index 2fe8f6deb..2f9a3108e 100644
--- a/packages/asset-buyer/src/asset_buyer.ts
+++ b/packages/asset-buyer/src/asset_buyer.ts
@@ -1,4 +1,4 @@
-import { ContractWrappers } from '@0x/contract-wrappers';
+import { ContractWrappers, ContractWrappersError, ForwarderWrapperError } from '@0x/contract-wrappers';
import { schemas } from '@0x/json-schemas';
import { SignedOrder } from '@0x/order-utils';
import { ObjectMap } from '@0x/types';
@@ -210,21 +210,32 @@ export class AssetBuyer {
throw new Error(AssetBuyerError.NoAddressAvailable);
}
}
- // if no ethAmount is provided, default to the worst ethAmount from buyQuote
- const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEthAsync(
- orders,
- assetBuyAmount,
- finalTakerAddress,
- ethAmount || worstCaseQuoteInfo.totalEthAmount,
- feeOrders,
- feePercentage,
- feeRecipient,
- {
- gasLimit,
- gasPrice,
- },
- );
- return txHash;
+ try {
+ // if no ethAmount is provided, default to the worst ethAmount from buyQuote
+ const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEthAsync(
+ orders,
+ assetBuyAmount,
+ finalTakerAddress,
+ ethAmount || worstCaseQuoteInfo.totalEthAmount,
+ feeOrders,
+ feePercentage,
+ feeRecipient,
+ {
+ gasLimit,
+ gasPrice,
+ shouldValidate: true,
+ },
+ );
+ return txHash;
+ } catch (err) {
+ if (_.includes(err.message, ContractWrappersError.SignatureRequestDenied)) {
+ throw new Error(AssetBuyerError.SignatureRequestDenied);
+ } else if (_.includes(err.message, ForwarderWrapperError.CompleteFillFailed)) {
+ throw new Error(AssetBuyerError.TransactionValueTooLow);
+ } else {
+ throw err;
+ }
+ }
}
/**
* Grab orders from the map, if there is a miss or it is time to refresh, fetch and process the orders
diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts
index 0d8e732d7..f15e7e934 100644
--- a/packages/asset-buyer/src/types.ts
+++ b/packages/asset-buyer/src/types.ts
@@ -112,6 +112,8 @@ export enum AssetBuyerError {
NoAddressAvailable = 'NO_ADDRESS_AVAILABLE',
InvalidOrderProviderResponse = 'INVALID_ORDER_PROVIDER_RESPONSE',
AssetUnavailable = 'ASSET_UNAVAILABLE',
+ SignatureRequestDenied = 'SIGNATURE_REQUEST_DENIED',
+ TransactionValueTooLow = 'TRANSACTION_VALUE_TOO_LOW',
}
export interface OrdersAndFillableAmounts {