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 = {
|
2018-04-11 10:06:46 +00:00
|
|
|
ready: boolean;
|
2018-05-17 14:03:11 +00:00
|
|
|
online: boolean;
|
2018-04-11 10:06:46 +00:00
|
|
|
dropdownOpened: boolean;
|
2018-04-16 21:19:50 +00:00
|
|
|
initialParams: ?RouterLocationState;
|
|
|
|
initialPathname: ?string;
|
2018-05-05 11:52:03 +00:00
|
|
|
disconnectRequest: ?TrezorDevice;
|
2018-05-22 17:41:10 +00:00
|
|
|
|
|
|
|
selectedDevice: ?TrezorDevice;
|
2018-02-20 09:30:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 21:19:50 +00:00
|
|
|
const initialState: State = {
|
2018-04-11 10:06:46 +00:00
|
|
|
ready: false,
|
2018-05-17 14:03:11 +00:00
|
|
|
online: navigator.onLine,
|
2018-04-11 10:06:46 +00:00
|
|
|
dropdownOpened: false,
|
|
|
|
initialParams: null,
|
|
|
|
initialPathname: null,
|
2018-05-22 17:41:10 +00:00
|
|
|
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:
|
2018-04-11 10:06:46 +00:00
|
|
|
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-04-11 10:06:46 +00:00
|
|
|
|
2018-07-30 10:52:13 +00:00
|
|
|
case WEB3.READY:
|
2018-04-11 10:06:46 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2018-07-30 10:52:13 +00:00
|
|
|
ready: true,
|
|
|
|
};
|
2018-04-11 10:06:46 +00:00
|
|
|
|
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:
|
2018-04-11 10:06:46 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2018-07-30 10:52:13 +00:00
|
|
|
dropdownOpened: action.opened,
|
|
|
|
};
|
2018-04-11 10:06:46 +00:00
|
|
|
|
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:
|
2018-05-22 17:41:10 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2018-07-30 10:52:13 +00:00
|
|
|
selectedDevice: action.device,
|
|
|
|
};
|
2018-05-22 17:41:10 +00:00
|
|
|
|
2018-02-20 09:30:36 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|