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:
parent
2c84d69eab
commit
56e3eb49cf
@ -7,6 +7,7 @@ import * as CONNECT from './constants/TrezorConnect';
|
||||
|
||||
import type { ThunkAction, AsyncAction, Action, GetState, Dispatch, TrezorDevice } from '~/flowtype';
|
||||
import type { State } from '../reducers/ModalReducer';
|
||||
import type { Device } from 'trezor-connect';
|
||||
|
||||
export type ModalAction = {
|
||||
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 {
|
||||
onPinSubmit,
|
||||
onPassphraseSubmit,
|
||||
|
@ -55,9 +55,9 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
|
||||
}
|
||||
});
|
||||
} 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) {
|
||||
api.dispatch(ModalActions.onRememberRequest(prevModalState));
|
||||
api.dispatch( ModalActions.onRememberRequest( prevModalState ) );
|
||||
} else if (action.type === CONNECT.FORGET) {
|
||||
//api.dispatch( TrezorConnectActions.forgetDevice(action.device) );
|
||||
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) {
|
||||
|
||||
api.dispatch( DiscoveryActions.restore() );
|
||||
|
||||
// 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
|
||||
});
|
||||
}
|
||||
}
|
||||
api.dispatch( ModalActions.onDeviceConnect( action.device ) );
|
||||
|
||||
} else if (action.type === CONNECT.AUTH_DEVICE) {
|
||||
api.dispatch( DiscoveryActions.check() );
|
||||
|
Loading…
Reference in New Issue
Block a user