You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-wallet/src/reducers/ModalReducer.js

105 lines
2.8 KiB

6 years ago
/* @flow */
6 years ago
import { UI, DEVICE } from 'trezor-connect';
import * as RECEIVE from 'actions/constants/receive';
import * as MODAL from 'actions/constants/modal';
import * as CONNECT from 'actions/constants/TrezorConnect';
6 years ago
import type { Action, TrezorDevice } from 'flowtype';
6 years ago
export type State = {
6 years ago
opened: false;
} | {
opened: true;
device: TrezorDevice;
instances?: Array<TrezorDevice>;
windowType?: string;
6 years ago
}
const initialState: State = {
opened: false,
6 years ago
// instances: null,
// windowType: null
6 years ago
};
6 years ago
export default function modal(state: State = initialState, action: Action): State {
6 years ago
switch (action.type) {
case RECEIVE.REQUEST_UNVERIFIED:
6 years ago
return {
opened: true,
6 years ago
device: action.device,
windowType: action.type,
};
6 years ago
case CONNECT.REMEMBER_REQUEST:
6 years ago
return {
6 years ago
opened: true,
6 years ago
device: action.device,
instances: action.instances,
windowType: action.type,
6 years ago
};
case CONNECT.FORGET_REQUEST:
6 years ago
return {
opened: true,
6 years ago
device: action.device,
windowType: action.type,
6 years ago
};
case CONNECT.TRY_TO_DUPLICATE:
6 years ago
return {
opened: true,
6 years ago
device: action.device,
windowType: action.type,
6 years ago
};
case DEVICE.CHANGED:
if (state.opened && action.device.path === state.device.path && action.device.status === 'occupied') {
return initialState;
6 years ago
}
return state;
6 years ago
case DEVICE.DISCONNECT:
6 years ago
if (state.opened && action.device.path === state.device.path) {
return initialState;
6 years ago
}
6 years ago
return state;
6 years ago
6 years ago
// case DEVICE.CONNECT :
// case DEVICE.CONNECT_UNACQUIRED :
6 years ago
// if (state.opened && state.windowType === CONNECT.TRY_TO_FORGET) {
// return {
// ...initialState,
// passphraseCached: state.passphraseCached
// }
// }
// return state;
6 years ago
case UI.REQUEST_PIN:
case UI.INVALID_PIN:
case UI.REQUEST_PASSPHRASE:
6 years ago
return {
6 years ago
opened: true,
6 years ago
device: action.payload.device,
windowType: action.type,
6 years ago
};
case UI.REQUEST_BUTTON:
6 years ago
return {
6 years ago
opened: true,
6 years ago
device: action.payload.device,
windowType: action.payload.code,
};
case UI.CLOSE_UI_WINDOW:
case MODAL.CLOSE:
case CONNECT.FORGET:
case CONNECT.FORGET_SINGLE:
case CONNECT.REMEMBER:
6 years ago
return initialState;
6 years ago
6 years ago
default:
return state;
}
}