mirror of
https://github.com/trezor/trezor-wallet
synced 2025-02-04 20:30:58 +00:00
Update WalletService.js
This commit is contained in:
parent
89d8485bbd
commit
2677f62869
@ -66,28 +66,8 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
|
|||||||
// update common values ONLY if application is ready
|
// update common values ONLY if application is ready
|
||||||
if (!api.getState().wallet.ready) return action;
|
if (!api.getState().wallet.ready) return action;
|
||||||
|
|
||||||
// observe common values in WallerReducer
|
// check for "selectedDevice" change before any action
|
||||||
if (!(await api.dispatch(WalletActions.observe(prevState, action)))) {
|
const selectedDeviceDidChange = 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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// double verification needed
|
// double verification needed
|
||||||
// Corner case: LOCATION_CHANGE was called but pathname didn't changed (redirection from RouterService)
|
// 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));
|
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
|
// even if "selectedDevice" didn't change because it was updated on DEVICE.CHANGED before DEVICE.CONNECT action
|
||||||
// try to restore discovery
|
// try to restore discovery
|
||||||
if (action.type === DEVICE.CONNECT) {
|
if (action.type === DEVICE.CONNECT) {
|
||||||
|
Loading…
Reference in New Issue
Block a user