1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-15 12:59:09 +00:00
trezor-wallet/src/reducers/WalletReducer.js

168 lines
4.4 KiB
JavaScript
Raw Normal View History

2018-02-20 09:30:36 +00:00
/* @flow */
2018-07-30 10:52:13 +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 },
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 = {
ready: false,
2018-05-17 14:03:11 +00:00
online: navigator.onLine,
language: 'en',
2019-02-15 19:52:56 +00:00
messages: {},
localCurrency: 'usd',
hideBalance: false,
dropdownOpened: false,
2018-12-18 16:05:06 +00:00
firstLocationChange: true,
showBetaDisclaimer: false,
2019-02-25 00:43:34 +00:00
showSidebar: null,
initialParams: null,
initialPathname: null,
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:
return {
...state,
2018-04-16 21:19:50 +00:00
initialParams: action.state,
2018-07-30 10:52:13 +00:00
initialPathname: action.pathname,
};
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-09-03 15:45:50 +00:00
case TRANSPORT.START:
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,
};
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:
return {
...state,
2018-07-30 10:52:13 +00:00
selectedDevice: action.device,
};
2019-01-24 17:49:33 +00:00
case WALLET.TOGGLE_SIDEBAR:
return {
...state,
showSidebar: !state.showSidebar,
};
case WALLET.SHOW_BETA_DISCLAIMER:
return {
...state,
showBetaDisclaimer: true,
};
case WALLET.HIDE_BETA_DISCLAIMER:
return {
...state,
showBetaDisclaimer: false,
};
case WALLET.SET_LANGUAGE:
return {
...state,
2019-02-15 19:52:56 +00:00
language: action.locale,
messages: action.messages ? action.messages : state.messages,
};
case WALLET.SET_LOCAL_CURRENCY:
return {
...state,
localCurrency: action.localCurrency,
};
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;
}
}