fortmatic patches
This commit is contained in:
@@ -9,11 +9,11 @@ import { assetUtils } from '../util/asset';
|
||||
import { coinbaseApi } from '../util/coinbase_api';
|
||||
import { errorFlasher } from '../util/error_flasher';
|
||||
import { errorReporter } from '../util/error_reporter';
|
||||
import { providerStateFactory } from '../util/provider_state_factory';
|
||||
import { swapQuoteUpdater } from '../util/swap_quote_updater';
|
||||
|
||||
import { actions } from './actions';
|
||||
import { State } from './reducer';
|
||||
import { providerStateFactory } from '../util/provider_state_factory';
|
||||
|
||||
export const asyncData = {
|
||||
fetchEthPriceAndDispatchToStore: async (dispatch: Dispatch) => {
|
||||
@@ -60,21 +60,28 @@ export const asyncData = {
|
||||
providerState: ProviderState,
|
||||
dispatch: Dispatch,
|
||||
shouldAttemptUnlock: boolean = false,
|
||||
shouldSetToLoading: boolean = false,
|
||||
) => {
|
||||
const web3Wrapper = providerState.web3Wrapper;
|
||||
const provider = providerState.provider;
|
||||
if (shouldSetToLoading && providerState.account.state !== AccountState.Loading) {
|
||||
let availableAddresses: string[] = [];
|
||||
if (shouldAttemptUnlock && providerState.account.state !== AccountState.Loading) {
|
||||
dispatch(actions.setAccountStateLoading());
|
||||
}
|
||||
let availableAddresses: string[] = [];
|
||||
try {
|
||||
// TODO(bmillman): Add support at the web3Wrapper level for calling `eth_requestAccounts` instead of calling enable here
|
||||
const isPrivacyModeEnabled = (provider as any).enable !== undefined;
|
||||
availableAddresses =
|
||||
isPrivacyModeEnabled && shouldAttemptUnlock
|
||||
? await (provider as any).enable()
|
||||
: await web3Wrapper.getAvailableAddressesAsync();
|
||||
// HACK: Fortmatic's getAvailableAddressesAsync behaves in ways that default wallet behavior can't handle
|
||||
if ((provider as any).isFortmatic) {
|
||||
availableAddresses =
|
||||
(provider as any).isLoggedIn || shouldAttemptUnlock
|
||||
? await web3Wrapper.getAvailableAddressesAsync()
|
||||
: [];
|
||||
} else {
|
||||
// TODO(bmillman): Add support at the web3Wrapper level for calling `eth_requestAccounts` instead of calling enable here
|
||||
const isPrivacyModeEnabled = (provider as any).enable !== undefined;
|
||||
availableAddresses =
|
||||
isPrivacyModeEnabled && shouldAttemptUnlock
|
||||
? await (provider as any).enable()
|
||||
: await web3Wrapper.getAvailableAddressesAsync();
|
||||
}
|
||||
} catch (e) {
|
||||
analytics.trackAccountUnlockDenied();
|
||||
if (e.message.includes('Fortmatic: User denied account access.')) {
|
||||
@@ -93,7 +100,7 @@ export const asyncData = {
|
||||
dispatch(actions.setAccountStateReady(activeAddress));
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
asyncData.fetchAccountBalanceAndDispatchToStore(activeAddress, providerState.web3Wrapper, dispatch);
|
||||
} else {
|
||||
} else if (providerState.account.state !== AccountState.Loading) {
|
||||
dispatch(actions.setAccountStateLocked());
|
||||
}
|
||||
},
|
||||
|
@@ -3,7 +3,7 @@ import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import { SupportedProvider, ZeroExProvider } from 'ethereum-types';
|
||||
import * as Fortmatic from 'fortmatic';
|
||||
|
||||
import { FORTMATIC_API_KEY, LOADING_ACCOUNT, NO_ACCOUNT } from '../constants';
|
||||
import { FORTMATIC_API_KEY, LOCKED_ACCOUNT, NO_ACCOUNT } from '../constants';
|
||||
import { Maybe, Network, OrderSource, ProviderState, ProviderType } from '../types';
|
||||
import { envUtil } from '../util/env';
|
||||
|
||||
@@ -50,7 +50,7 @@ export const providerStateFactory = {
|
||||
web3Wrapper: new Web3Wrapper(provider),
|
||||
swapQuoter: assetSwapperFactory.getSwapQuoter(provider, orderSource, network),
|
||||
swapQuoteConsumer: assetSwapperFactory.getSwapQuoteConsumer(provider, network),
|
||||
account: LOADING_ACCOUNT,
|
||||
account: LOCKED_ACCOUNT,
|
||||
orderSource,
|
||||
isProviderInjected: false,
|
||||
};
|
||||
@@ -70,7 +70,7 @@ export const providerStateFactory = {
|
||||
web3Wrapper: new Web3Wrapper(injectedProviderIfExists),
|
||||
swapQuoter: assetSwapperFactory.getSwapQuoter(injectedProviderIfExists, orderSource, network),
|
||||
swapQuoteConsumer: assetSwapperFactory.getSwapQuoteConsumer(injectedProviderIfExists, network),
|
||||
account: LOADING_ACCOUNT,
|
||||
account: LOCKED_ACCOUNT,
|
||||
orderSource,
|
||||
isProviderInjected: true,
|
||||
};
|
||||
@@ -99,9 +99,7 @@ export const providerStateFactory = {
|
||||
return providerState;
|
||||
},
|
||||
// function to call getInitialProviderState with parameters retreived from a provided ProviderState
|
||||
getInitialProviderStateWithCurrentProviderState: (
|
||||
currentProviderState: ProviderState,
|
||||
): ProviderState => {
|
||||
getInitialProviderStateWithCurrentProviderState: (currentProviderState: ProviderState): ProviderState => {
|
||||
const orderSource = currentProviderState.orderSource;
|
||||
const chainId = currentProviderState.swapQuoter.chainId;
|
||||
// If provider is provided to instant, use that and the displayName
|
||||
@@ -113,11 +111,8 @@ export const providerStateFactory = {
|
||||
currentProviderState.displayName,
|
||||
);
|
||||
}
|
||||
const newProviderState = providerStateFactory.getInitialProviderState(
|
||||
orderSource,
|
||||
chainId,
|
||||
);
|
||||
newProviderState.account = NO_ACCOUNT;
|
||||
const newProviderState = providerStateFactory.getInitialProviderState(orderSource, chainId);
|
||||
newProviderState.account = LOCKED_ACCOUNT;
|
||||
return newProviderState;
|
||||
},
|
||||
getProviderStateBasedOnProviderType: (
|
||||
@@ -137,7 +132,7 @@ export const providerStateFactory = {
|
||||
web3Wrapper: new Web3Wrapper(provider),
|
||||
swapQuoter: assetSwapperFactory.getSwapQuoter(provider, orderSource, chainId),
|
||||
swapQuoteConsumer: assetSwapperFactory.getSwapQuoteConsumer(provider, chainId),
|
||||
account: LOADING_ACCOUNT,
|
||||
account: LOCKED_ACCOUNT,
|
||||
orderSource,
|
||||
isProviderInjected: true,
|
||||
};
|
||||
@@ -153,14 +148,11 @@ export const providerStateFactory = {
|
||||
web3Wrapper: new Web3Wrapper(fmProvider),
|
||||
swapQuoter: assetSwapperFactory.getSwapQuoter(fmProvider, orderSource, chainId),
|
||||
swapQuoteConsumer: assetSwapperFactory.getSwapQuoteConsumer(fmProvider, chainId),
|
||||
account: LOADING_ACCOUNT,
|
||||
account: LOCKED_ACCOUNT,
|
||||
orderSource,
|
||||
isProviderInjected: true,
|
||||
};
|
||||
}
|
||||
return providerStateFactory.getInitialProviderState(
|
||||
orderSource,
|
||||
chainId,
|
||||
);
|
||||
return providerStateFactory.getInitialProviderState(orderSource, chainId);
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user