diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-10 02:06:22 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-10 02:06:22 +0800 |
commit | df91d343154bced69be86f7af4c4c702286cfd16 (patch) | |
tree | 35a540b849c38ce72a2b5bd5aedcc23f2b72ef6d /packages/instant/src/redux | |
parent | d703c13f8eca7f7139581468e86cf6d2fa067c1e (diff) | |
parent | b4a11de097258d37fa9271e64fc28a1d012a8d26 (diff) | |
download | dexon-0x-contracts-df91d343154bced69be86f7af4c4c702286cfd16.tar.gz dexon-0x-contracts-df91d343154bced69be86f7af4c4c702286cfd16.tar.zst dexon-0x-contracts-df91d343154bced69be86f7af4c4c702286cfd16.zip |
Merge branch 'development' into feature/instant/buy-quote-heartbeat
Diffstat (limited to 'packages/instant/src/redux')
-rw-r--r-- | packages/instant/src/redux/actions.ts | 5 | ||||
-rw-r--r-- | packages/instant/src/redux/async_data.ts | 29 | ||||
-rw-r--r-- | packages/instant/src/redux/reducer.ts | 9 |
3 files changed, 33 insertions, 10 deletions
diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts index 9b0d80152..fc89e3d0e 100644 --- a/packages/instant/src/redux/actions.ts +++ b/packages/instant/src/redux/actions.ts @@ -2,7 +2,7 @@ import { BuyQuote } from '@0x/asset-buyer'; import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; -import { ActionsUnion, Asset } from '../types'; +import { ActionsUnion, AddressAndEthBalanceInWei, Asset } from '../types'; export interface PlainAction<T extends string> { type: T; @@ -49,7 +49,8 @@ export const actions = { setAccountStateLocked: () => createAction(ActionTypes.SET_ACCOUNT_STATE_LOCKED), setAccountStateError: () => createAction(ActionTypes.SET_ACCOUNT_STATE_ERROR), setAccountStateReady: (address: string) => createAction(ActionTypes.SET_ACCOUNT_STATE_READY, address), - updateAccountEthBalance: (balance: BigNumber) => createAction(ActionTypes.UPDATE_ACCOUNT_ETH_BALANCE, balance), + updateAccountEthBalance: (addressAndBalance: AddressAndEthBalanceInWei) => + createAction(ActionTypes.UPDATE_ACCOUNT_ETH_BALANCE, addressAndBalance), updateEthUsdPrice: (price?: BigNumber) => createAction(ActionTypes.UPDATE_ETH_USD_PRICE, price), updateSelectedAssetAmount: (amount?: BigNumber) => createAction(ActionTypes.UPDATE_SELECTED_ASSET_AMOUNT, amount), setBuyOrderStateNone: () => createAction(ActionTypes.SET_BUY_ORDER_STATE_NONE), diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index 055d3de20..a50f24cba 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -1,8 +1,10 @@ +import { AssetProxyId } from '@0x/types'; import * as _ from 'lodash'; import { BIG_NUMBER_ZERO } from '../constants'; -import { AccountState } from '../types'; +import { AccountState, ERC20Asset } from '../types'; import { assetUtils } from '../util/asset'; +import { buyQuoteUpdater } from '../util/buy_quote_updater'; import { coinbaseApi } from '../util/coinbase_api'; import { errorFlasher } from '../util/error_flasher'; @@ -50,7 +52,8 @@ export const asyncData = { if (!_.isEmpty(availableAddresses)) { const activeAddress = availableAddresses[0]; store.dispatch(actions.setAccountStateReady(activeAddress)); - await asyncData.fetchAccountBalanceAndDispatchToStore(store); + // tslint:disable-next-line:no-floating-promises + asyncData.fetchAccountBalanceAndDispatchToStore(store); } else { store.dispatch(actions.setAccountStateLocked()); } @@ -63,11 +66,29 @@ export const asyncData = { return; } try { - const ethBalanceInWei = await web3Wrapper.getBalanceInWeiAsync(account.address); - store.dispatch(actions.updateAccountEthBalance(ethBalanceInWei)); + const address = account.address; + const ethBalanceInWei = await web3Wrapper.getBalanceInWeiAsync(address); + store.dispatch(actions.updateAccountEthBalance({ address, ethBalanceInWei })); } catch (e) { // leave balance as is return; } }, + fetchCurrentBuyQuoteAndDispatchToStore: async (store: Store) => { + const { providerState, selectedAsset, selectedAssetAmount, affiliateInfo } = store.getState(); + const assetBuyer = providerState.assetBuyer; + if ( + !_.isUndefined(selectedAssetAmount) && + !_.isUndefined(selectedAsset) && + selectedAsset.metaData.assetProxyId === AssetProxyId.ERC20 + ) { + await buyQuoteUpdater.updateBuyQuoteAsync( + assetBuyer, + store.dispatch, + selectedAsset as ERC20Asset, + selectedAssetAmount, + affiliateInfo, + ); + } + }, }; diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index 961e29619..a5a1b6f7d 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -75,13 +75,14 @@ export const createReducer = (initialState: State) => { return reduceStateWithAccount(state, account); } case ActionTypes.UPDATE_ACCOUNT_ETH_BALANCE: { - const account = state.providerState.account; - if (account.state !== AccountState.Ready) { + const { address, ethBalanceInWei } = action.data; + const currentAccount = state.providerState.account; + if (currentAccount.state !== AccountState.Ready || currentAccount.address !== address) { return state; } else { const newAccount: AccountReady = { - ...account, - ethBalanceInWei: action.data, + ...currentAccount, + ethBalanceInWei, }; return reduceStateWithAccount(state, newAccount); } |