1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

modal logic moved from TCService to ModalActions

This commit is contained in:
Szymon Lesisz 2018-05-19 18:26:28 +02:00
parent 2c84d69eab
commit 56e3eb49cf
2 changed files with 25 additions and 19 deletions

View File

@ -7,6 +7,7 @@ import * as CONNECT from './constants/TrezorConnect';
import type { ThunkAction, AsyncAction, Action, GetState, Dispatch, TrezorDevice } from '~/flowtype'; import type { ThunkAction, AsyncAction, Action, GetState, Dispatch, TrezorDevice } from '~/flowtype';
import type { State } from '../reducers/ModalReducer'; import type { State } from '../reducers/ModalReducer';
import type { Device } from 'trezor-connect';
export type ModalAction = { export type ModalAction = {
type: typeof MODAL.CLOSE type: typeof MODAL.CLOSE
@ -107,6 +108,27 @@ export const onRememberRequest = (prevState: State): ThunkAction => {
} }
} }
export const onDeviceConnect = (device: Device): ThunkAction => {
return (dispatch: Dispatch, getState: GetState): void => {
// interrupt process of remembering device (force forget)
// TODO: the same for disconnect more than 1 device at once
const { modal } = getState();
if (modal.opened && modal.windowType === CONNECT.REMEMBER_REQUEST) {
if (device.features && modal.device && modal.device.features && modal.device.features.device_id === device.features.device_id) {
dispatch({
type: MODAL.CLOSE,
});
} else {
dispatch({
type: CONNECT.FORGET,
device: modal.device
});
}
}
}
}
export default { export default {
onPinSubmit, onPinSubmit,
onPassphraseSubmit, onPassphraseSubmit,

View File

@ -55,9 +55,9 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
} }
}); });
} else if (action.type === DEVICE.DISCONNECT) { } else if (action.type === DEVICE.DISCONNECT) {
api.dispatch( TrezorConnectActions.deviceDisconnect(action.device) ); api.dispatch( TrezorConnectActions.deviceDisconnect( action.device ) );
} else if (action.type === CONNECT.REMEMBER_REQUEST) { } else if (action.type === CONNECT.REMEMBER_REQUEST) {
api.dispatch(ModalActions.onRememberRequest(prevModalState)); api.dispatch( ModalActions.onRememberRequest( prevModalState ) );
} else if (action.type === CONNECT.FORGET) { } else if (action.type === CONNECT.FORGET) {
//api.dispatch( TrezorConnectActions.forgetDevice(action.device) ); //api.dispatch( TrezorConnectActions.forgetDevice(action.device) );
api.dispatch( TrezorConnectActions.switchToFirstAvailableDevice() ); api.dispatch( TrezorConnectActions.switchToFirstAvailableDevice() );
@ -75,23 +75,7 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
} else if (action.type === DEVICE.CONNECT || action.type === DEVICE.CONNECT_UNACQUIRED) { } else if (action.type === DEVICE.CONNECT || action.type === DEVICE.CONNECT_UNACQUIRED) {
api.dispatch( DiscoveryActions.restore() ); api.dispatch( DiscoveryActions.restore() );
api.dispatch( ModalActions.onDeviceConnect( action.device ) );
// interrupt process of remembering device (force forget)
// TODO: the same for disconnect more than 1 device at once
// TODO: move it to modal actions
const { modal } = api.getState();
if (modal.opened && modal.windowType === CONNECT.REMEMBER_REQUEST) {
if (action.device.features && modal.device && modal.device.features && modal.device.features.device_id === action.device.features.device_id) {
api.dispatch({
type: MODAL.CLOSE,
});
} else {
api.dispatch({
type: CONNECT.FORGET,
device: modal.device
});
}
}
} else if (action.type === CONNECT.AUTH_DEVICE) { } else if (action.type === CONNECT.AUTH_DEVICE) {
api.dispatch( DiscoveryActions.check() ); api.dispatch( DiscoveryActions.check() );