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.discovery !== state.discovery
|
||||||
|| prevState.tokens !== state.tokens
|
|| prevState.tokens !== state.tokens
|
||||||
|| prevState.pending !== state.pending) {
|
|| prevState.pending !== state.pending) {
|
||||||
if (locationChange) {
|
|
||||||
// dispose current account view
|
|
||||||
dispatch(dispose());
|
|
||||||
}
|
|
||||||
|
|
||||||
const account = stateUtils.getSelectedAccount(state);
|
const account = stateUtils.getSelectedAccount(state);
|
||||||
const network = stateUtils.getSelectedNetwork(state);
|
const network = stateUtils.getSelectedNetwork(state);
|
||||||
|
@ -4,9 +4,11 @@
|
|||||||
import { DEVICE } from 'trezor-connect';
|
import { DEVICE } from 'trezor-connect';
|
||||||
import { LOCATION_CHANGE } from 'react-router-redux';
|
import { LOCATION_CHANGE } from 'react-router-redux';
|
||||||
import * as WALLET from 'actions/constants/wallet';
|
import * as WALLET from 'actions/constants/wallet';
|
||||||
|
import * as CONNECT from 'actions/constants/TrezorConnect';
|
||||||
|
|
||||||
import * as WalletActions from 'actions/WalletActions';
|
import * as WalletActions from 'actions/WalletActions';
|
||||||
import * as RouterActions from 'actions/RouterActions';
|
import * as RouterActions from 'actions/RouterActions';
|
||||||
|
import * as NotificationActions from 'actions/NotificationActions';
|
||||||
import * as LocalStorageActions from 'actions/LocalStorageActions';
|
import * as LocalStorageActions from 'actions/LocalStorageActions';
|
||||||
import * as TrezorConnectActions from 'actions/TrezorConnectActions';
|
import * as TrezorConnectActions from 'actions/TrezorConnectActions';
|
||||||
import * as SelectedAccountActions from 'actions/SelectedAccountActions';
|
import * as SelectedAccountActions from 'actions/SelectedAccountActions';
|
||||||
@ -30,32 +32,18 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
|
|||||||
const { location } = api.getState().router;
|
const { location } = api.getState().router;
|
||||||
if (!location) {
|
if (!location) {
|
||||||
api.dispatch(WalletActions.init());
|
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
|
// pass action
|
||||||
next(action);
|
next(action);
|
||||||
|
|
||||||
if (action.type === DEVICE.CONNECT) {
|
switch (action.type) {
|
||||||
api.dispatch(WalletActions.clearUnavailableDevicesData(prevState, action.device));
|
case WALLET.SET_INITIAL_URL:
|
||||||
}
|
api.dispatch(LocalStorageActions.loadData());
|
||||||
|
break;
|
||||||
// update common values ONLY if application is ready
|
case WALLET.SET_SELECTED_DEVICE: {
|
||||||
if (api.getState().wallet.ready) {
|
|
||||||
// update common values in WallerReducer
|
|
||||||
api.dispatch(WalletActions.updateSelectedValues(prevState, 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) {
|
if (action.device) {
|
||||||
// try to authorize device
|
// try to authorize device
|
||||||
api.dispatch(TrezorConnectActions.getSelectedDeviceState());
|
api.dispatch(TrezorConnectActions.getSelectedDeviceState());
|
||||||
@ -64,6 +52,48 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
|
|||||||
api.dispatch(RouterActions.selectFirstAvailableDevice());
|
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) return action;
|
||||||
|
|
||||||
|
// 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;
|
return action;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user