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/js/reducers/ModalReducer.js

108 lines
2.9 KiB

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