aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/redux
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-11-10 08:22:36 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-11-10 08:22:36 +0800
commitff027ee36a5c2384004c9b55baa42919b5d9fa65 (patch)
tree72300769affc9d33f5c8ef32aadd1b8cc31f98d6 /packages/instant/src/redux
parentba292ead45f451e4d7d2fac74582b8406cd4a586 (diff)
parent397b4e289015f9bb0831c1a0ce6fee601670b487 (diff)
downloaddexon-sol-tools-ff027ee36a5c2384004c9b55baa42919b5d9fa65.tar
dexon-sol-tools-ff027ee36a5c2384004c9b55baa42919b5d9fa65.tar.gz
dexon-sol-tools-ff027ee36a5c2384004c9b55baa42919b5d9fa65.tar.bz2
dexon-sol-tools-ff027ee36a5c2384004c9b55baa42919b5d9fa65.tar.lz
dexon-sol-tools-ff027ee36a5c2384004c9b55baa42919b5d9fa65.tar.xz
dexon-sol-tools-ff027ee36a5c2384004c9b55baa42919b5d9fa65.tar.zst
dexon-sol-tools-ff027ee36a5c2384004c9b55baa42919b5d9fa65.zip
Merge branch 'development' of https://github.com/0xProject/0x-monorepo into feature/instant/metamask-connect-flow
Diffstat (limited to 'packages/instant/src/redux')
-rw-r--r--packages/instant/src/redux/actions.ts2
-rw-r--r--packages/instant/src/redux/async_data.ts23
-rw-r--r--packages/instant/src/redux/reducer.ts4
3 files changed, 17 insertions, 12 deletions
diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts
index a899da23c..0891170b4 100644
--- a/packages/instant/src/redux/actions.ts
+++ b/packages/instant/src/redux/actions.ts
@@ -23,7 +23,6 @@ function createAction<T extends string, P>(type: T, data?: P): PlainAction<T> |
export enum ActionTypes {
SET_ACCOUNT_STATE_LOADING = 'SET_ACCOUNT_STATE_LOADING',
SET_ACCOUNT_STATE_LOCKED = 'SET_ACCOUNT_STATE_LOCKED',
- SET_ACCOUNT_STATE_ERROR = 'SET_ACCOUNT_STATE_ERROR',
SET_ACCOUNT_STATE_READY = 'SET_ACCOUNT_STATE_READY',
UPDATE_ACCOUNT_ETH_BALANCE = 'UPDATE_ACCOUNT_ETH_BALANCE',
UPDATE_ETH_USD_PRICE = 'UPDATE_ETH_USD_PRICE',
@@ -49,7 +48,6 @@ export enum ActionTypes {
export const actions = {
setAccountStateLoading: () => createAction(ActionTypes.SET_ACCOUNT_STATE_LOADING),
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: (addressAndBalance: AddressAndEthBalanceInWei) =>
createAction(ActionTypes.UPDATE_ACCOUNT_ETH_BALANCE, addressAndBalance),
diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts
index a8f632009..b920ac914 100644
--- a/packages/instant/src/redux/async_data.ts
+++ b/packages/instant/src/redux/async_data.ts
@@ -2,7 +2,7 @@ import { AssetProxyId } from '@0x/types';
import * as _ from 'lodash';
import { BIG_NUMBER_ZERO } from '../constants';
-import { AccountState, ERC20Asset } from '../types';
+import { AccountState, ERC20Asset, OrderProcessState } from '../types';
import { assetUtils } from '../util/asset';
import { buyQuoteUpdater } from '../util/buy_quote_updater';
import { coinbaseApi } from '../util/coinbase_api';
@@ -36,17 +36,23 @@ export const asyncData = {
store.dispatch(actions.setAvailableAssets([]));
}
},
- fetchAccountInfoAndDispatchToStore: async (store: Store) => {
+ fetchAccountInfoAndDispatchToStore: async (options: { store: Store; shouldSetToLoading: boolean }) => {
+ const { store, shouldSetToLoading } = options;
const { providerState } = store.getState();
const web3Wrapper = providerState.web3Wrapper;
- if (providerState.account.state !== AccountState.Loading) {
+ const provider = providerState.provider;
+ if (shouldSetToLoading && providerState.account.state !== AccountState.Loading) {
store.dispatch(actions.setAccountStateLoading());
}
let availableAddresses: string[];
try {
- availableAddresses = await web3Wrapper.getAvailableAddressesAsync();
+ // TODO(bmillman): Add support at the web3Wrapper level for calling `eth_requestAccounts` instead of calling enable here
+ const isPrivacyModeEnabled = !_.isUndefined((provider as any).enable);
+ availableAddresses = isPrivacyModeEnabled
+ ? await (provider as any).enable()
+ : await web3Wrapper.getAvailableAddressesAsync();
} catch (e) {
- store.dispatch(actions.setAccountStateError());
+ store.dispatch(actions.setAccountStateLocked());
return;
}
if (!_.isEmpty(availableAddresses)) {
@@ -74,12 +80,14 @@ export const asyncData = {
return;
}
},
- fetchCurrentBuyQuoteAndDispatchToStore: async (store: Store) => {
- const { providerState, selectedAsset, selectedAssetAmount, affiliateInfo } = store.getState();
+ fetchCurrentBuyQuoteAndDispatchToStore: async (options: { store: Store; shouldSetPending: boolean }) => {
+ const { store, shouldSetPending } = options;
+ const { buyOrderState, providerState, selectedAsset, selectedAssetAmount, affiliateInfo } = store.getState();
const assetBuyer = providerState.assetBuyer;
if (
!_.isUndefined(selectedAssetAmount) &&
!_.isUndefined(selectedAsset) &&
+ buyOrderState.processState === OrderProcessState.None &&
selectedAsset.metaData.assetProxyId === AssetProxyId.ERC20
) {
await buyQuoteUpdater.updateBuyQuoteAsync(
@@ -87,6 +95,7 @@ export const asyncData = {
store.dispatch,
selectedAsset as ERC20Asset,
selectedAssetAmount,
+ shouldSetPending,
affiliateInfo,
);
}
diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts
index a542979cb..4688250bc 100644
--- a/packages/instant/src/redux/reducer.ts
+++ b/packages/instant/src/redux/reducer.ts
@@ -4,7 +4,7 @@ import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as _ from 'lodash';
-import { ERROR_ACCOUNT, LOADING_ACCOUNT, LOCKED_ACCOUNT } from '../constants';
+import { LOADING_ACCOUNT, LOCKED_ACCOUNT } from '../constants';
import { assetMetaDataMap } from '../data/asset_meta_data_map';
import {
Account,
@@ -72,8 +72,6 @@ export const createReducer = (initialState: State) => {
return reduceStateWithAccount(state, LOADING_ACCOUNT);
case ActionTypes.SET_ACCOUNT_STATE_LOCKED:
return reduceStateWithAccount(state, LOCKED_ACCOUNT);
- case ActionTypes.SET_ACCOUNT_STATE_ERROR:
- return reduceStateWithAccount(state, ERROR_ACCOUNT);
case ActionTypes.SET_ACCOUNT_STATE_READY: {
const account: AccountReady = {
state: AccountState.Ready,