aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-10-30 01:26:27 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-10-30 01:37:56 +0800
commitaab9bedd7fe1ab328e416024b6397f242d39d84f (patch)
tree5ffa6dc9d737d5dddd1b16c4ecb6fb65e6e85ee4 /packages/instant/src/util
parent8d1689073b702d973075d30b2bb36369487fad1c (diff)
parent4e4291eccdd6c837bbec70603aa6eb64d3aa8d85 (diff)
downloaddexon-sol-tools-aab9bedd7fe1ab328e416024b6397f242d39d84f.tar
dexon-sol-tools-aab9bedd7fe1ab328e416024b6397f242d39d84f.tar.gz
dexon-sol-tools-aab9bedd7fe1ab328e416024b6397f242d39d84f.tar.bz2
dexon-sol-tools-aab9bedd7fe1ab328e416024b6397f242d39d84f.tar.lz
dexon-sol-tools-aab9bedd7fe1ab328e416024b6397f242d39d84f.tar.xz
dexon-sol-tools-aab9bedd7fe1ab328e416024b6397f242d39d84f.tar.zst
dexon-sol-tools-aab9bedd7fe1ab328e416024b6397f242d39d84f.zip
Merge branch 'development' into feature/instant/fixed-orders-in-render-method
* development: Has Sufficient Funds/Balance -> Has Sufficient ETH When transaction too low, treat as validation error. also modify callback: errorMessage could be AssetBuyError as well onPendingValidation -> onValidationPending linting Simpler way of validaitng has enough eth questionmark syntax instead of '| undefined' Validate enough ETH when user clicks buy acccount for no address move funct into util move imports yarn.lock changes feat(instant): Show message if user doesn't have enough ETH ethDecimals -> ETH_DECIMALS
Diffstat (limited to 'packages/instant/src/util')
-rw-r--r--packages/instant/src/util/address.ts6
-rw-r--r--packages/instant/src/util/balance.ts13
-rw-r--r--packages/instant/src/util/format.ts6
3 files changed, 22 insertions, 3 deletions
diff --git a/packages/instant/src/util/address.ts b/packages/instant/src/util/address.ts
new file mode 100644
index 000000000..14d42d8c0
--- /dev/null
+++ b/packages/instant/src/util/address.ts
@@ -0,0 +1,6 @@
+import { web3Wrapper } from '../util/web3_wrapper';
+
+export const getBestAddress = async (): Promise<string | undefined> => {
+ const addresses = await web3Wrapper.getAvailableAddressesAsync();
+ return addresses[0];
+};
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;
+ },
+};
diff --git a/packages/instant/src/util/format.ts b/packages/instant/src/util/format.ts
index ca7c01359..4a48dec9d 100644
--- a/packages/instant/src/util/format.ts
+++ b/packages/instant/src/util/format.ts
@@ -2,7 +2,7 @@ import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as _ from 'lodash';
-import { ethDecimals } from '../constants';
+import { ETH_DECIMALS } from '../constants';
export const format = {
ethBaseAmount: (
@@ -13,7 +13,7 @@ export const format = {
if (_.isUndefined(ethBaseAmount)) {
return defaultText;
}
- const ethUnitAmount = Web3Wrapper.toUnitAmount(ethBaseAmount, ethDecimals);
+ const ethUnitAmount = Web3Wrapper.toUnitAmount(ethBaseAmount, ETH_DECIMALS);
return format.ethUnitAmount(ethUnitAmount, decimalPlaces);
},
ethUnitAmount: (
@@ -36,7 +36,7 @@ export const format = {
if (_.isUndefined(ethBaseAmount) || _.isUndefined(ethUsdPrice)) {
return defaultText;
}
- const ethUnitAmount = Web3Wrapper.toUnitAmount(ethBaseAmount, ethDecimals);
+ const ethUnitAmount = Web3Wrapper.toUnitAmount(ethBaseAmount, ETH_DECIMALS);
return format.ethUnitAmountInUsd(ethUnitAmount, ethUsdPrice, decimalPlaces);
},
ethUnitAmountInUsd: (