2018-02-20 09:30:36 +00:00
|
|
|
/* @flow */
|
2018-07-30 10:52:13 +00:00
|
|
|
|
2018-12-18 13:33:01 +00:00
|
|
|
import { LOCATION_CHANGE } from 'connected-react-router';
|
2018-09-03 15:45:50 +00:00
|
|
|
import { DEVICE, TRANSPORT } from 'trezor-connect';
|
2018-08-14 13:11:52 +00:00
|
|
|
import * as MODAL from 'actions/constants/modal';
|
|
|
|
import * as WALLET from 'actions/constants/wallet';
|
|
|
|
import * as CONNECT from 'actions/constants/TrezorConnect';
|
2019-01-24 17:49:33 +00:00
|
|
|
import * as ACCOUNT from 'actions/constants/account';
|
2018-02-20 09:30:36 +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 = {
|
2019-03-04 12:33:02 +00:00
|
|
|
ready: boolean,
|
|
|
|
online: boolean,
|
|
|
|
language: string,
|
|
|
|
messages: { [string]: string },
|
2019-03-14 22:31:19 +00:00
|
|
|
localCurrency: string,
|
|
|
|
hideBalance: boolean,
|
2019-03-04 12:33:02 +00:00
|
|
|
dropdownOpened: boolean,
|
|
|
|
showBetaDisclaimer: boolean,
|
|
|
|
showSidebar: ?boolean,
|
|
|
|
initialParams: ?RouterLocationState,
|
|
|
|
initialPathname: ?string,
|
|
|
|
firstLocationChange: boolean,
|
|
|
|
disconnectRequest: ?TrezorDevice,
|
|
|
|
selectedDevice: ?TrezorDevice,
|
2019-04-17 17:14:06 +00:00
|
|
|
hiddenCoins: Array<string>,
|
2019-04-24 12:05:07 +00:00
|
|
|
hiddenCoinsExternal: Array<string>,
|
2019-03-04 12:33:02 +00:00
|
|
|
};
|
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,
|
2019-02-06 17:01:09 +00:00
|
|
|
language: 'en',
|
2019-02-15 19:52:56 +00:00
|
|
|
messages: {},
|
2019-03-14 22:31:19 +00:00
|
|
|
localCurrency: 'usd',
|
|
|
|
hideBalance: false,
|
2018-04-11 10:06:46 +00:00
|
|
|
dropdownOpened: false,
|
2018-12-18 16:05:06 +00:00
|
|
|
firstLocationChange: true,
|
2018-10-17 10:09:25 +00:00
|
|
|
showBetaDisclaimer: false,
|
2019-02-25 00:43:34 +00:00
|
|
|
showSidebar: null,
|
2018-04-11 10:06:46 +00:00
|
|
|
initialParams: null,
|
|
|
|
initialPathname: null,
|
2018-05-22 17:41:10 +00:00
|
|
|
disconnectRequest: null,
|
|
|
|
selectedDevice: null,
|
2019-04-16 16:59:12 +00:00
|
|
|
hiddenCoins: [],
|
2019-04-24 12:05:07 +00:00
|
|
|
hiddenCoinsExternal: [],
|
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-12-20 14:58:46 +00:00
|
|
|
};
|
|
|
|
case WALLET.SET_FIRST_LOCATION_CHANGE:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-12-18 16:05:06 +00:00
|
|
|
firstLocationChange: false,
|
2018-07-30 10:52:13 +00:00
|
|
|
};
|
2018-04-11 10:06:46 +00:00
|
|
|
|
2018-09-03 15:45:50 +00:00
|
|
|
case TRANSPORT.START:
|
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,
|
|
|
|
};
|
2019-01-24 17:49:33 +00:00
|
|
|
case ACCOUNT.UPDATE_SELECTED_ACCOUNT:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showSidebar: 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
|
|
|
|
2019-01-24 17:49:33 +00:00
|
|
|
case WALLET.TOGGLE_SIDEBAR:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showSidebar: !state.showSidebar,
|
|
|
|
};
|
|
|
|
|
2018-10-17 10:09:25 +00:00
|
|
|
case WALLET.SHOW_BETA_DISCLAIMER:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showBetaDisclaimer: true,
|
|
|
|
};
|
|
|
|
case WALLET.HIDE_BETA_DISCLAIMER:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showBetaDisclaimer: false,
|
|
|
|
};
|
|
|
|
|
2019-02-06 17:01:09 +00:00
|
|
|
case WALLET.SET_LANGUAGE:
|
|
|
|
return {
|
|
|
|
...state,
|
2019-02-15 19:52:56 +00:00
|
|
|
language: action.locale,
|
|
|
|
messages: action.messages ? action.messages : state.messages,
|
2019-02-06 17:01:09 +00:00
|
|
|
};
|
|
|
|
|
2019-03-11 16:45:35 +00:00
|
|
|
case WALLET.SET_LOCAL_CURRENCY:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
localCurrency: action.localCurrency,
|
|
|
|
};
|
|
|
|
|
2019-03-14 22:31:19 +00:00
|
|
|
case WALLET.SET_HIDE_BALANCE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
hideBalance: action.toggled,
|
|
|
|
};
|
|
|
|
|
2019-04-16 16:59:12 +00:00
|
|
|
case WALLET.SET_HIDDEN_COINS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
hiddenCoins: action.hiddenCoins,
|
|
|
|
};
|
|
|
|
|
2019-04-24 12:05:07 +00:00
|
|
|
case WALLET.SET_HIDDEN_COINS_EXTERNAL:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
hiddenCoinsExternal: action.hiddenCoinsExternal,
|
|
|
|
};
|
|
|
|
|
2018-02-20 09:30:36 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|