aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-11-28 03:39:32 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-28 07:37:22 +0800
commitee93f091ea5fc78d039f4f91cb234a94f428ec6a (patch)
tree7f86bdfb5c947d3e24771085eede424fc37b4a2a /packages
parent33a8c7a9fb707f6a5f1bc345988ba1e420af67c5 (diff)
downloaddexon-sol-tools-ee93f091ea5fc78d039f4f91cb234a94f428ec6a.tar
dexon-sol-tools-ee93f091ea5fc78d039f4f91cb234a94f428ec6a.tar.gz
dexon-sol-tools-ee93f091ea5fc78d039f4f91cb234a94f428ec6a.tar.bz2
dexon-sol-tools-ee93f091ea5fc78d039f4f91cb234a94f428ec6a.tar.lz
dexon-sol-tools-ee93f091ea5fc78d039f4f91cb234a94f428ec6a.tar.xz
dexon-sol-tools-ee93f091ea5fc78d039f4f91cb234a94f428ec6a.tar.zst
dexon-sol-tools-ee93f091ea5fc78d039f4f91cb234a94f428ec6a.zip
Add gas margin and remove undefined values
Diffstat (limited to 'packages')
-rw-r--r--packages/0x.js/src/contract.ts24
1 files changed, 14 insertions, 10 deletions
diff --git a/packages/0x.js/src/contract.ts b/packages/0x.js/src/contract.ts
index 347f47aa0..6dc0dab66 100644
--- a/packages/0x.js/src/contract.ts
+++ b/packages/0x.js/src/contract.ts
@@ -5,6 +5,8 @@ import * as Web3 from 'web3';
import {AbiType} from './types';
+const GAS_MARGIN = 30000;
+
export class Contract implements Web3.ContractInstance {
public address: string;
public abi: Web3.ContractAbi;
@@ -63,21 +65,23 @@ export class Contract implements Web3.ContractInstance {
// 1 - method level
// 2 - Library defaults
// 3 - estimate
+ const removeUndefinedProperties = _.pickBy;
txData = {
- ...this.defaults,
- ...txData,
+ ...removeUndefinedProperties(this.defaults),
+ ...removeUndefinedProperties(txData),
};
if (_.isUndefined(txData.gas)) {
- const estimatedGas = await estimateGasAsync.apply(this.contract, [...args, txData]);
- txData.gas = estimatedGas;
- }
- const callback = (err: Error, data: any) => {
- if (_.isNull(err)) {
- resolve(data);
- } else {
+ try {
+ const estimatedGas = await estimateGasAsync.apply(this.contract, [...args, txData]);
+ const gas = estimatedGas + GAS_MARGIN;
+ txData.gas = gas;
+ console.log('withGas', txData);
+ } catch (err) {
reject(err);
+ return;
}
- };
+ }
+ const callback = (err: Error, data: any) => _.isNull(err) ? resolve(data) : reject(err);
args.push(txData);
args.push(callback);
web3CbStyleFunction.apply(this.contract, args);