diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-27 06:20:04 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-27 06:20:04 +0800 |
commit | e1ae551560ad12501256fd5702dcd929baa84100 (patch) | |
tree | d02f498fe7a14222b18cef3476cb7aa8a54cbc5e /packages/instant/src/util | |
parent | 476cbbb6cb32db5ca72cc9d200b3ead152ae0e33 (diff) | |
download | dexon-sol-tools-e1ae551560ad12501256fd5702dcd929baa84100.tar dexon-sol-tools-e1ae551560ad12501256fd5702dcd929baa84100.tar.gz dexon-sol-tools-e1ae551560ad12501256fd5702dcd929baa84100.tar.bz2 dexon-sol-tools-e1ae551560ad12501256fd5702dcd929baa84100.tar.lz dexon-sol-tools-e1ae551560ad12501256fd5702dcd929baa84100.tar.xz dexon-sol-tools-e1ae551560ad12501256fd5702dcd929baa84100.tar.zst dexon-sol-tools-e1ae551560ad12501256fd5702dcd929baa84100.zip |
move funct into util
Diffstat (limited to 'packages/instant/src/util')
-rw-r--r-- | packages/instant/src/util/balance.ts | 30 |
1 files changed, 30 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..d442da9e0 --- /dev/null +++ b/packages/instant/src/util/balance.ts @@ -0,0 +1,30 @@ +import { BuyQuote } from '@0x/asset-buyer'; +import { Web3Wrapper } from '@0x/web3-wrapper'; +import { Dispatch } from 'redux'; + +import { ZeroExInstantError } from '../types'; + +import { errorUtil } from './error'; + +export const balanceUtil = { + /** + * Checks to see if user has enough balance to buy assets + * If they do not, flash an error and return false + * If they do, return true + */ + checkSufficientBalanceAndFlashError: async ( + takerAddress: string, + buyQuote: BuyQuote, + web3Wrapper: Web3Wrapper, + dispatch: Dispatch, + ) => { + const balanceWei = await web3Wrapper.getBalanceInWeiAsync(takerAddress); + + if (balanceWei < buyQuote.worstCaseQuoteInfo.totalEthAmount) { + const balanceError = new Error(ZeroExInstantError.InsufficientBalance); + errorUtil.errorFlasher.flashNewError(dispatch, balanceError); + return false; + } + return true; + }, +}; |