aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-11-09 16:42:50 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-11-10 08:04:29 +0800
commit38896c9358c07d722b2a24d458e6c949b802fa37 (patch)
tree43fe5262fbe6e2ee4e9b19e34ac6784f9eab1a7b /packages/instant
parent26cbe7ae6646d97c286e58756c23a93de32ae37b (diff)
downloaddexon-sol-tools-38896c9358c07d722b2a24d458e6c949b802fa37.tar
dexon-sol-tools-38896c9358c07d722b2a24d458e6c949b802fa37.tar.gz
dexon-sol-tools-38896c9358c07d722b2a24d458e6c949b802fa37.tar.bz2
dexon-sol-tools-38896c9358c07d722b2a24d458e6c949b802fa37.tar.lz
dexon-sol-tools-38896c9358c07d722b2a24d458e6c949b802fa37.tar.xz
dexon-sol-tools-38896c9358c07d722b2a24d458e6c949b802fa37.tar.zst
dexon-sol-tools-38896c9358c07d722b2a24d458e6c949b802fa37.zip
feat(instant): handle privacy mode in wallets
Diffstat (limited to 'packages/instant')
-rw-r--r--packages/instant/src/components/zero_ex_instant_provider.tsx2
-rw-r--r--packages/instant/src/constants.ts3
-rw-r--r--packages/instant/src/redux/actions.ts2
-rw-r--r--packages/instant/src/redux/async_data.ts9
-rw-r--r--packages/instant/src/redux/reducer.ts4
-rw-r--r--packages/instant/src/types.ts7
6 files changed, 11 insertions, 16 deletions
diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx
index 11f867abc..411f118cc 100644
--- a/packages/instant/src/components/zero_ex_instant_provider.tsx
+++ b/packages/instant/src/components/zero_ex_instant_provider.tsx
@@ -98,7 +98,6 @@ export class ZeroExInstantProvider extends React.Component<ZeroExInstantProvider
// tslint:disable-next-line:no-floating-promises
asyncData.fetchAvailableAssetDatasAndDispatchToStore(this._store);
}
-
if (state.providerState.account.state !== AccountState.None) {
this._accountUpdateHeartbeat = generateAccountHeartbeater({
store: this._store,
@@ -114,7 +113,6 @@ export class ZeroExInstantProvider extends React.Component<ZeroExInstantProvider
this._buyQuoteHeartbeat.start(BUY_QUOTE_UPDATE_INTERVAL_TIME_MS);
// tslint:disable-next-line:no-floating-promises
asyncData.fetchCurrentBuyQuoteAndDispatchToStore({ store: this._store, shouldSetPending: true });
-
// warm up the gas price estimator cache just in case we can't
// grab the gas price estimate when submitting the transaction
// tslint:disable-next-line:no-floating-promises
diff --git a/packages/instant/src/constants.ts b/packages/instant/src/constants.ts
index 6bfbc690e..110a8248a 100644
--- a/packages/instant/src/constants.ts
+++ b/packages/instant/src/constants.ts
@@ -33,6 +33,3 @@ export const LOADING_ACCOUNT: AccountNotReady = {
export const LOCKED_ACCOUNT: AccountNotReady = {
state: AccountState.Locked,
};
-export const ERROR_ACCOUNT: AccountNotReady = {
- state: AccountState.Error,
-};
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,
diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts
index 62afe652d..b43a82d46 100644
--- a/packages/instant/src/types.ts
+++ b/packages/instant/src/types.ts
@@ -102,11 +102,10 @@ export interface ProviderState {
}
export enum AccountState {
+ None = 'NONE,',
Loading = 'LOADING',
Ready = 'READY',
- Locked = 'LOCKED', // TODO(bmillman): break this up into locked / privacy mode enabled
- Error = 'ERROR',
- None = 'NONE,',
+ Locked = 'LOCKED',
}
export interface AccountReady {
@@ -115,7 +114,7 @@ export interface AccountReady {
ethBalanceInWei?: BigNumber;
}
export interface AccountNotReady {
- state: AccountState.None | AccountState.Loading | AccountState.Locked | AccountState.Error;
+ state: AccountState.None | AccountState.Loading | AccountState.Locked;
}
export type Account = AccountReady | AccountNotReady;