1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-01-01 03:40:53 +00:00
trezor-wallet/src/js/reducers/ModalReducer.js

108 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-12-13 11:01:37 +00:00
/* @flow */
'use strict';
import { UI, DEVICE } from 'trezor-connect';
2018-02-20 09:30:36 +00:00
import * as RECEIVE from '../actions/constants/receive';
2018-04-11 10:13:38 +00:00
import * as MODAL from '../actions/constants/modal';
2018-02-20 09:30:36 +00:00
import * as CONNECT from '../actions/constants/TrezorConnect';
2017-12-13 11:01:37 +00:00
import type { Action, TrezorDevice } from '~/flowtype';
2018-04-23 10:20:15 +00:00
2018-04-16 21:19:50 +00:00
export type State = {
2018-05-02 09:01:08 +00:00
opened: false;
} | {
opened: true;
device: TrezorDevice;
instances?: Array<TrezorDevice>;
windowType?: string;
2017-12-13 11:01:37 +00:00
}
2018-04-16 21:19:50 +00:00
const initialState: State = {
2018-05-02 09:01:08 +00:00
opened: false
// instances: null,
// windowType: null
2017-12-13 11:01:37 +00:00
};
2018-04-23 10:20:15 +00:00
export default function modal(state: State = initialState, action: Action): State {
2017-12-13 11:01:37 +00:00
switch (action.type) {
2018-02-20 09:30:36 +00:00
case RECEIVE.REQUEST_UNVERIFIED :
2017-12-13 11:01:37 +00:00
return {
opened: true,
2018-05-02 09:01:08 +00:00
device: action.device,
2017-12-13 11:01:37 +00:00
windowType: action.type
2018-02-20 09:30:36 +00:00
}
2017-12-13 11:01:37 +00:00
2018-02-20 09:30:36 +00:00
case CONNECT.REMEMBER_REQUEST :
2018-04-23 10:20:15 +00:00
return {
2018-05-02 09:01:08 +00:00
opened: true,
2018-04-23 10:20:15 +00:00
device: action.device,
instances: action.instances,
windowType: action.type
};
2018-02-20 09:30:36 +00:00
case CONNECT.FORGET_REQUEST :
2017-12-13 11:01:37 +00:00
return {
opened: true,
2018-05-02 09:01:08 +00:00
device: action.device,
2017-12-13 11:01:37 +00:00
windowType: action.type
};
2018-02-20 09:30:36 +00:00
case CONNECT.TRY_TO_DUPLICATE :
2017-12-13 11:01:37 +00:00
return {
opened: true,
2018-05-02 09:01:08 +00:00
device: action.device,
2017-12-13 11:01:37 +00:00
windowType: action.type
};
2018-02-20 09:30:36 +00:00
case DEVICE.CHANGED :
2018-05-02 09:01:08 +00:00
if (state.opened && action.device.path === state.device.path && action.device.isUsedElsewhere) {
return initialState
2018-02-20 09:30:36 +00:00
}
return state;
2017-12-13 11:01:37 +00:00
2018-02-20 09:30:36 +00:00
case DEVICE.DISCONNECT :
2018-05-02 09:01:08 +00:00
if (state.opened && action.device.path === state.device.path) {
return initialState
2017-12-13 11:01:37 +00:00
}
2018-02-20 09:30:36 +00:00
return state;
2017-12-13 11:01:37 +00:00
2018-02-20 09:30:36 +00:00
// case DEVICE.CONNECT :
// case DEVICE.CONNECT_UNACQUIRED :
// if (state.opened && state.windowType === CONNECT.TRY_TO_FORGET) {
// return {
// ...initialState,
// passphraseCached: state.passphraseCached
// }
// }
// return state;
2017-12-13 11:01:37 +00:00
2018-02-20 09:30:36 +00:00
case UI.REQUEST_PIN :
case UI.INVALID_PIN :
case UI.REQUEST_PASSPHRASE :
2017-12-13 11:01:37 +00:00
return {
2018-02-20 09:30:36 +00:00
opened: true,
2018-05-02 09:01:08 +00:00
device: action.payload.device,
2018-02-20 09:30:36 +00:00
windowType: action.type
};
case UI.REQUEST_BUTTON :
2017-12-13 11:01:37 +00:00
return {
2018-02-20 09:30:36 +00:00
opened: true,
2018-05-02 09:01:08 +00:00
device: action.payload.device,
windowType: action.payload.code
2017-12-13 11:01:37 +00:00
}
2018-02-20 09:30:36 +00:00
case UI.CLOSE_UI_WINDOW :
case MODAL.CLOSE :
2018-02-20 09:30:36 +00:00
case CONNECT.FORGET :
case CONNECT.FORGET_SINGLE :
case CONNECT.REMEMBER :
2018-05-02 09:01:08 +00:00
return initialState;
2018-02-20 09:30:36 +00:00
2017-12-13 11:01:37 +00:00
default:
return state;
}
}