diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-11-09 16:42:50 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-11-10 08:04:29 +0800 |
commit | 38896c9358c07d722b2a24d458e6c949b802fa37 (patch) | |
tree | 43fe5262fbe6e2ee4e9b19e34ac6784f9eab1a7b /packages/instant/src/redux | |
parent | 26cbe7ae6646d97c286e58756c23a93de32ae37b (diff) | |
download | dexon-sol-tools-38896c9358c07d722b2a24d458e6c949b802fa37.tar.gz dexon-sol-tools-38896c9358c07d722b2a24d458e6c949b802fa37.tar.zst dexon-sol-tools-38896c9358c07d722b2a24d458e6c949b802fa37.zip |
feat(instant): handle privacy mode in wallets
Diffstat (limited to 'packages/instant/src/redux')
-rw-r--r-- | packages/instant/src/redux/actions.ts | 2 | ||||
-rw-r--r-- | packages/instant/src/redux/async_data.ts | 9 | ||||
-rw-r--r-- | packages/instant/src/redux/reducer.ts | 4 |
3 files changed, 8 insertions, 7 deletions
diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts index fc89e3d0e..8947c6c97 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', @@ -47,7 +46,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 a47c7a605..b920ac914 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -40,14 +40,19 @@ export const asyncData = { const { store, shouldSetToLoading } = options; const { providerState } = store.getState(); const web3Wrapper = providerState.web3Wrapper; + 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)) { diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index a5a1b6f7d..ef46fdd9d 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, @@ -65,8 +65,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, |