Update WalletService.js

pull/500/head
Szymon Lesisz 5 years ago
parent 89d8485bbd
commit 2677f62869

@ -66,28 +66,8 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
// update common values ONLY if application is ready
if (!api.getState().wallet.ready) return action;
// observe common values in WallerReducer
if (!(await api.dispatch(WalletActions.observe(prevState, action)))) {
// if "selectedDevice" didn't change observe common values in SelectedAccountReducer
if (!(await api.dispatch(SelectedAccountActions.observe(prevState, action)))) {
// if "selectedAccount" didn't change observe send form props changes
api.dispatch(SendFormActions.observe(prevState, action));
}
} else {
// no changes in common values
if (action.type === CONNECT.RECEIVE_WALLET_TYPE) {
if (action.device.state) {
// redirect to root view (Dashboard) if device was authenticated before
api.dispatch(RouterActions.selectFirstAvailableDevice(true));
}
api.dispatch(TrezorConnectActions.authorizeDevice());
}
if (action.type === CONNECT.AUTH_DEVICE) {
// selected device did changed
// try to restore discovery after device authentication
api.dispatch(DiscoveryActions.restore());
}
}
// check for "selectedDevice" change before any action
const selectedDeviceDidChange = await api.dispatch(WalletActions.observe(prevState, action));
// double verification needed
// Corner case: LOCATION_CHANGE was called but pathname didn't changed (redirection from RouterService)
@ -122,6 +102,28 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
api.dispatch(NotificationActions.clear(prevLocation.state, currentLocation.state));
}
// if "selectedDevice" didn't change observe common values in SelectedAccountReducer
if (!selectedDeviceDidChange) {
if (!(await api.dispatch(SelectedAccountActions.observe(prevState, action)))) {
// if "selectedAccount" didn't change observe send form props changes
api.dispatch(SendFormActions.observe(prevState, action));
}
} else {
// no changes in common values
if (action.type === CONNECT.RECEIVE_WALLET_TYPE) {
if (action.device.state) {
// redirect to root view (Dashboard) if device was authenticated before
api.dispatch(RouterActions.selectFirstAvailableDevice(true));
}
api.dispatch(TrezorConnectActions.authorizeDevice());
}
if (action.type === CONNECT.AUTH_DEVICE) {
// selected device did changed
// try to restore discovery after device authentication
api.dispatch(DiscoveryActions.restore());
}
}
// even if "selectedDevice" didn't change because it was updated on DEVICE.CHANGED before DEVICE.CONNECT action
// try to restore discovery
if (action.type === DEVICE.CONNECT) {

Loading…
Cancel
Save