1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-29 02:18:06 +00:00
trezor-wallet/src/reducers/WalletReducer.js

95 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-02-20 09:30:36 +00:00
/* @flow */
2018-07-30 10:52:13 +00:00
2018-02-20 09:30:36 +00:00
2018-05-05 11:52:03 +00:00
import { LOCATION_CHANGE } from 'react-router-redux';
import { DEVICE } from 'trezor-connect';
2018-08-14 13:11:52 +00:00
import * as MODAL from 'actions/constants/modal';
import * as WEB3 from 'actions/constants/web3';
import * as WALLET from 'actions/constants/wallet';
import * as CONNECT from 'actions/constants/TrezorConnect';
2018-02-20 09:30:36 +00:00
2018-05-05 11:52:03 +00:00
2018-08-14 12:56:47 +00:00
import type { Action, RouterLocationState, TrezorDevice } from 'flowtype';
2018-04-16 21:19:50 +00:00
2018-02-20 09:30:36 +00:00
type State = {
ready: boolean;
2018-05-17 14:03:11 +00:00
online: boolean;
dropdownOpened: boolean;
2018-04-16 21:19:50 +00:00
initialParams: ?RouterLocationState;
initialPathname: ?string;
2018-05-05 11:52:03 +00:00
disconnectRequest: ?TrezorDevice;
selectedDevice: ?TrezorDevice;
2018-02-20 09:30:36 +00:00
}
2018-04-16 21:19:50 +00:00
const initialState: State = {
ready: false,
2018-05-17 14:03:11 +00:00
online: navigator.onLine,
dropdownOpened: false,
initialParams: null,
initialPathname: null,
disconnectRequest: null,
selectedDevice: null,
2018-02-20 09:30:36 +00:00
};
2018-04-16 21:19:50 +00:00
export default function wallet(state: State = initialState, action: Action): State {
2018-07-30 10:52:13 +00:00
switch (action.type) {
case WALLET.SET_INITIAL_URL:
return {
...state,
2018-04-16 21:19:50 +00:00
initialParams: action.state,
2018-07-30 10:52:13 +00:00
initialPathname: action.pathname,
};
2018-07-30 10:52:13 +00:00
case WEB3.READY:
return {
...state,
2018-07-30 10:52:13 +00:00
ready: true,
};
2018-07-30 10:52:13 +00:00
case WALLET.ONLINE_STATUS:
2018-05-17 14:03:11 +00:00
return {
...state,
2018-07-30 10:52:13 +00:00
online: action.online,
};
2018-05-17 14:03:11 +00:00
2018-07-30 10:52:13 +00:00
case WALLET.TOGGLE_DEVICE_DROPDOWN:
return {
...state,
2018-07-30 10:52:13 +00:00
dropdownOpened: action.opened,
};
2018-07-30 10:52:13 +00:00
case LOCATION_CHANGE:
case MODAL.CLOSE:
2018-05-02 11:39:27 +00:00
return {
...state,
2018-07-30 10:52:13 +00:00
dropdownOpened: false,
};
2018-05-02 11:39:27 +00:00
2018-07-30 10:52:13 +00:00
case CONNECT.DISCONNECT_REQUEST:
2018-05-05 11:52:03 +00:00
return {
...state,
2018-07-30 10:52:13 +00:00
disconnectRequest: action.device,
};
2018-05-05 11:52:03 +00:00
2018-07-30 10:52:13 +00:00
case DEVICE.DISCONNECT:
2018-05-05 11:52:03 +00:00
if (state.disconnectRequest && action.device.path === state.disconnectRequest.path) {
return {
...state,
2018-07-30 10:52:13 +00:00
disconnectRequest: null,
};
2018-05-05 11:52:03 +00:00
}
return state;
2018-07-30 10:52:13 +00:00
case WALLET.SET_SELECTED_DEVICE:
case WALLET.UPDATE_SELECTED_DEVICE:
return {
...state,
2018-07-30 10:52:13 +00:00
selectedDevice: action.device,
};
2018-02-20 09:30:36 +00:00
default:
return state;
}
}