mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
fix for ACCOUNT.DISPOSE action called + few actions moved from RouterService
This commit is contained in:
parent
ae9b12f35d
commit
13a9e47c73
@ -48,10 +48,6 @@ export const updateSelectedValues = (prevState: State, action: Action): AsyncAct
|
||||
|| prevState.discovery !== state.discovery
|
||||
|| prevState.tokens !== state.tokens
|
||||
|| prevState.pending !== state.pending) {
|
||||
if (locationChange) {
|
||||
// dispose current account view
|
||||
dispatch(dispose());
|
||||
}
|
||||
|
||||
const account = stateUtils.getSelectedAccount(state);
|
||||
const network = stateUtils.getSelectedNetwork(state);
|
||||
|
@ -4,9 +4,11 @@
|
||||
import { DEVICE } from 'trezor-connect';
|
||||
import { LOCATION_CHANGE } from 'react-router-redux';
|
||||
import * as WALLET from 'actions/constants/wallet';
|
||||
import * as CONNECT from 'actions/constants/TrezorConnect';
|
||||
|
||||
import * as WalletActions from 'actions/WalletActions';
|
||||
import * as RouterActions from 'actions/RouterActions';
|
||||
import * as NotificationActions from 'actions/NotificationActions';
|
||||
import * as LocalStorageActions from 'actions/LocalStorageActions';
|
||||
import * as TrezorConnectActions from 'actions/TrezorConnectActions';
|
||||
import * as SelectedAccountActions from 'actions/SelectedAccountActions';
|
||||
@ -30,41 +32,69 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
|
||||
const { location } = api.getState().router;
|
||||
if (!location) {
|
||||
api.dispatch(WalletActions.init());
|
||||
return next(action);
|
||||
}
|
||||
}
|
||||
|
||||
if (action.type === WALLET.SET_INITIAL_URL) {
|
||||
// load data from config.json and local storage
|
||||
api.dispatch(LocalStorageActions.loadData());
|
||||
}
|
||||
|
||||
// pass action
|
||||
next(action);
|
||||
|
||||
if (action.type === DEVICE.CONNECT) {
|
||||
api.dispatch(WalletActions.clearUnavailableDevicesData(prevState, action.device));
|
||||
switch (action.type) {
|
||||
case WALLET.SET_INITIAL_URL:
|
||||
api.dispatch(LocalStorageActions.loadData());
|
||||
break;
|
||||
case WALLET.SET_SELECTED_DEVICE: {
|
||||
if (action.device) {
|
||||
// try to authorize device
|
||||
api.dispatch(TrezorConnectActions.getSelectedDeviceState());
|
||||
} else {
|
||||
// try select different device
|
||||
api.dispatch(RouterActions.selectFirstAvailableDevice());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DEVICE.CONNECT:
|
||||
api.dispatch(WalletActions.clearUnavailableDevicesData(prevState, action.device));
|
||||
break;
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// update common values ONLY if application is ready
|
||||
if (api.getState().wallet.ready) {
|
||||
// update common values in WallerReducer
|
||||
api.dispatch(WalletActions.updateSelectedValues(prevState, action));
|
||||
if (!api.getState().wallet.ready) return action;
|
||||
|
||||
// update common values in SelectedAccountReducer
|
||||
api.dispatch(SelectedAccountActions.updateSelectedValues(prevState, action));
|
||||
}
|
||||
|
||||
// handle selected device change
|
||||
if (action.type === WALLET.SET_SELECTED_DEVICE) {
|
||||
if (action.device) {
|
||||
// try to authorize device
|
||||
api.dispatch(TrezorConnectActions.getSelectedDeviceState());
|
||||
} else {
|
||||
// try select different device
|
||||
api.dispatch(RouterActions.selectFirstAvailableDevice());
|
||||
// double verification needed
|
||||
// Corner case: LOCATION_CHANGE was called but pathname didn't changed (redirection in RouterService)
|
||||
const prevLocation = prevState.router.location;
|
||||
const currentLocation = api.getState().router.location;
|
||||
if (locationChange && prevLocation.pathname !== currentLocation.pathname) {
|
||||
// watch for coin change
|
||||
if (prevLocation.state.network !== currentLocation.state.network) {
|
||||
api.dispatch({
|
||||
type: CONNECT.COIN_CHANGED,
|
||||
payload: {
|
||||
network: currentLocation.state.network,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// watch for account change
|
||||
if (prevLocation.state.account !== currentLocation.state.account) {
|
||||
api.dispatch(SelectedAccountActions.dispose());
|
||||
}
|
||||
|
||||
// clear notifications
|
||||
api.dispatch(NotificationActions.clear(prevLocation.state, currentLocation.state));
|
||||
}
|
||||
|
||||
|
||||
// update common values in WallerReducer
|
||||
api.dispatch(WalletActions.updateSelectedValues(prevState, action));
|
||||
|
||||
// update common values in SelectedAccountReducer
|
||||
api.dispatch(SelectedAccountActions.updateSelectedValues(prevState, action));
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user