aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/balance.ts
diff options
context:
space:
mode:
authorSteve Klebanoff <steve@0xproject.com>2018-10-30 01:12:44 +0800
committerGitHub <noreply@github.com>2018-10-30 01:12:44 +0800
commit4e4291eccdd6c837bbec70603aa6eb64d3aa8d85 (patch)
treeedf8006576143d5cd1c32b052164ac898c57c8b2 /packages/instant/src/util/balance.ts
parentae6202ed3d777605a3fd02cd29141a3ba40f4b34 (diff)
parent7ed44f7b2f0224b4169f0a8f34bae09e8c6b986f (diff)
downloaddexon-sol-tools-4e4291eccdd6c837bbec70603aa6eb64d3aa8d85.tar
dexon-sol-tools-4e4291eccdd6c837bbec70603aa6eb64d3aa8d85.tar.gz
dexon-sol-tools-4e4291eccdd6c837bbec70603aa6eb64d3aa8d85.tar.bz2
dexon-sol-tools-4e4291eccdd6c837bbec70603aa6eb64d3aa8d85.tar.lz
dexon-sol-tools-4e4291eccdd6c837bbec70603aa6eb64d3aa8d85.tar.xz
dexon-sol-tools-4e4291eccdd6c837bbec70603aa6eb64d3aa8d85.tar.zst
dexon-sol-tools-4e4291eccdd6c837bbec70603aa6eb64d3aa8d85.zip
Merge pull request #1193 from 0xProject/feature/not-enough-eth
[instant] Not enough ETH error message
Diffstat (limited to 'packages/instant/src/util/balance.ts')
-rw-r--r--packages/instant/src/util/balance.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/packages/instant/src/util/balance.ts b/packages/instant/src/util/balance.ts
new file mode 100644
index 000000000..533656858
--- /dev/null
+++ b/packages/instant/src/util/balance.ts
@@ -0,0 +1,13 @@
+import { BuyQuote } from '@0x/asset-buyer';
+import { Web3Wrapper } from '@0x/web3-wrapper';
+import * as _ from 'lodash';
+
+export const balanceUtil = {
+ hasSufficentEth: async (takerAddress: string | undefined, buyQuote: BuyQuote, web3Wrapper: Web3Wrapper) => {
+ if (_.isUndefined(takerAddress)) {
+ return false;
+ }
+ const balanceWei = await web3Wrapper.getBalanceInWeiAsync(takerAddress);
+ return balanceWei >= buyQuote.worstCaseQuoteInfo.totalEthAmount;
+ },
+};