From cb7fbb2e6921982fc91aaa8a89ff45bf11d347c6 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 5 Oct 2018 15:31:03 +0200 Subject: [PATCH 1/7] added new field "useEmptyPassphrase" to TrezorDevice object --- src/flowtype/index.js | 2 ++ src/reducers/DevicesReducer.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/flowtype/index.js b/src/flowtype/index.js index 203033d1..44bd5556 100644 --- a/src/flowtype/index.js +++ b/src/flowtype/index.js @@ -56,6 +56,7 @@ export type AcquiredDevice = $Exact<{ status: DeviceStatus, +mode: DeviceMode, state: ?string, + useEmptyPassphrase: boolean, remember: boolean; // device should be remembered connected: boolean; // device is connected @@ -73,6 +74,7 @@ export type UnknownDevice = $Exact<{ +label: string, +features: null, state: ?string, + useEmptyPassphrase: boolean, remember: boolean; // device should be remembered connected: boolean; // device is connected diff --git a/src/reducers/DevicesReducer.js b/src/reducers/DevicesReducer.js index 81f2b4b1..e55b951c 100644 --- a/src/reducers/DevicesReducer.js +++ b/src/reducers/DevicesReducer.js @@ -39,6 +39,7 @@ const mergeDevices = (current: TrezorDevice, upcoming: Device | TrezorDevice): T instanceName: typeof upcoming.instanceName === 'string' ? upcoming.instanceName : current.instanceName, state: current.state, ts: typeof upcoming.ts === 'number' ? upcoming.ts : current.ts, + useEmptyPassphrase: typeof upcoming.useEmptyPassphrase === 'boolean' ? upcoming.useEmptyPassphrase : current.useEmptyPassphrase, }; if (upcoming.type === 'acquired') { @@ -89,6 +90,7 @@ const addDevice = (state: State, device: Device): State => { instanceLabel: device.label, instanceName: null, ts: new Date().getTime(), + useEmptyPassphrase: true, }; @@ -260,6 +262,22 @@ const onSelectedDevice = (state: State, device: ?TrezorDevice): State => { return otherDevices.concat([extended]); }; +const onChangeWalletType = (state: State, device: TrezorDevice, hidden: boolean): State => { + const affectedDevices: State = state.filter(d => d.path === device.path || (d.features && device.features && d.features.device_id === device.features.device_id)); + const otherDevices: State = state.filter(d => affectedDevices.indexOf(d) === -1); + if (affectedDevices.length > 0) { + const changedDevices = affectedDevices.map((d) => { // eslint-disable-line arrow-body-style + return d.type === 'acquired' ? { + ...d, + state: null, + useEmptyPassphrase: !hidden, + } : d; + }); + return otherDevices.concat(changedDevices); + } + return state; +}; + export default function devices(state: State = initialState, action: Action): State { switch (action.type) { case CONNECT.DEVICE_FROM_STORAGE: @@ -296,6 +314,9 @@ export default function devices(state: State = initialState, action: Action): St case WALLET.SET_SELECTED_DEVICE: return onSelectedDevice(state, action.device); + case CONNECT.RECEIVE_WALLET_TYPE: + return onChangeWalletType(state, action.device, action.hidden); + default: return state; } From df191fa7262c0fe188317989bef337dde1bef932 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 5 Oct 2018 15:46:47 +0200 Subject: [PATCH 2/7] TrezorConnect calls using new field "useEmptyPassphrase" --- src/actions/DiscoveryActions.js | 6 ++++-- src/actions/ReceiveActions.js | 3 ++- src/actions/SendFormActions.js | 3 ++- .../components/DeviceMenu/components/MenuItems/index.js | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/actions/DiscoveryActions.js b/src/actions/DiscoveryActions.js index e9c02369..596bc335 100644 --- a/src/actions/DiscoveryActions.js +++ b/src/actions/DiscoveryActions.js @@ -142,7 +142,8 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => async (dis }, path: coinToDiscover.bip44, keepSession: true, // acquire and hold session - useEmptyPassphrase: !device.instance, + //useEmptyPassphrase: !device.instance, + useEmptyPassphrase: device.useEmptyPassphrase, }); // handle TREZOR response error @@ -264,7 +265,8 @@ const finish = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction state: device.state, }, keepSession: false, - useEmptyPassphrase: !device.instance, + // useEmptyPassphrase: !device.instance, + useEmptyPassphrase: device.useEmptyPassphrase, }); await dispatch(BlockchainActions.subscribe(discoveryProcess.network)); diff --git a/src/actions/ReceiveActions.js b/src/actions/ReceiveActions.js index 6f193e48..95d56119 100644 --- a/src/actions/ReceiveActions.js +++ b/src/actions/ReceiveActions.js @@ -67,7 +67,8 @@ export const showAddress = (path: Array): AsyncAction => async (dispatch state: selected.state, }, path, - useEmptyPassphrase: !selected.instance, + // useEmptyPassphrase: !selected.instance, + useEmptyPassphrase: selected.useEmptyPassphrase, }); if (response && response.success) { diff --git a/src/actions/SendFormActions.js b/src/actions/SendFormActions.js index f26664f3..90ddf02e 100644 --- a/src/actions/SendFormActions.js +++ b/src/actions/SendFormActions.js @@ -458,7 +458,8 @@ export const onSend = (): AsyncAction => async (dispatch: Dispatch, getState: Ge instance: selected.instance, state: selected.state, }, - useEmptyPassphrase: !selected.instance, + // useEmptyPassphrase: !selected.instance, + useEmptyPassphrase: selected.useEmptyPassphrase, path: account.addressPath, transaction: txData, }); diff --git a/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.js b/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.js index a52bb769..969d3363 100644 --- a/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.js +++ b/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.js @@ -58,14 +58,14 @@ class MenuItems extends Component { if (!this.showDeviceMenu()) return null; return ( - this.onDeviceMenuClick('settings', this.props.device)}> + {/* this.onDeviceMenuClick('settings', this.props.device)}> - + */} this.onDeviceMenuClick('forget', this.props.device)}> - + )} {this.showRenewSession() && ( From bd6bb5927da2f46cc139c883abfb6445ae1a79e8 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 5 Oct 2018 15:47:37 +0200 Subject: [PATCH 3/7] new actions: request and receive wallet type --- src/actions/TrezorConnectActions.js | 45 ++++++++++++++++++++++---- src/actions/WalletActions.js | 1 + src/actions/constants/TrezorConnect.js | 5 ++- src/services/WalletService.js | 23 ++++++++----- 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/src/actions/TrezorConnectActions.js b/src/actions/TrezorConnectActions.js index b54a97a0..8f0bd2e8 100644 --- a/src/actions/TrezorConnectActions.js +++ b/src/actions/TrezorConnectActions.js @@ -71,6 +71,13 @@ export type TrezorConnectAction = { payload: Array } | { type: typeof CONNECT.START_ACQUIRING | typeof CONNECT.STOP_ACQUIRING, +} | { + type: typeof CONNECT.REQUEST_WALLET_TYPE, + device: TrezorDevice +} | { + type: typeof CONNECT.RECEIVE_WALLET_TYPE, + device: TrezorDevice, + hidden: boolean, }; export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { @@ -152,7 +159,19 @@ export const postInit = (): ThunkAction => (dispatch: Dispatch): void => { } }; -export const getSelectedDeviceState = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { +export const requestWalletType = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { + const selected = getState().wallet.selectedDevice; + if (!selected) return; + const isDeviceReady = selected.connected && selected.features && !selected.state && selected.mode === 'normal' && selected.firmware !== 'required'; + if (!isDeviceReady) return; + + dispatch({ + type: CONNECT.REQUEST_WALLET_TYPE, + device: selected, + }); +}; + +export const authorizeDevice = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { const selected = getState().wallet.selectedDevice; if (!selected) return; const isDeviceReady = selected.connected && selected.features && !selected.state && selected.mode === 'normal' && selected.firmware !== 'required'; @@ -164,7 +183,7 @@ export const getSelectedDeviceState = (): AsyncAction => async (dispatch: Dispat instance: selected.instance, state: selected.state, }, - useEmptyPassphrase: !selected.instance, + useEmptyPassphrase: selected.useEmptyPassphrase, }); if (response && response.success) { @@ -190,14 +209,13 @@ export const getSelectedDeviceState = (): AsyncAction => async (dispatch: Dispat type: NOTIFICATION.CLOSE, payload: { devicePath: selected.path }, }); - dispatch(getSelectedDeviceState()); + dispatch(authorizeDevice()); }, }, ], }, }); } - }; export const deviceDisconnect = (device: Device): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { @@ -231,11 +249,14 @@ export function acquire(): AsyncAction { type: CONNECT.START_ACQUIRING, }); + // this is the only place where useEmptyPassphrase should be used every time + // the goal here is to acquire device and get his features + // authentication (passphrase) is not needed here yet const response = await TrezorConnect.getFeatures({ device: { path: selected.path, }, - useEmptyPassphrase: !selected.instance, + useEmptyPassphrase: true, }); if (!response.success) { @@ -270,7 +291,7 @@ export const forget = (device: TrezorDevice): Action => ({ device, }); -export const duplicateDevice = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { +export const duplicateDevice1 = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { // dispatch({ // type: CONNECT.TRY_TO_DUPLICATE, // device, @@ -283,3 +304,15 @@ export const duplicateDevice = (device: TrezorDevice): AsyncAction => async (dis device: { ...device, ...extended }, }); }; + +export const duplicateDevice = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { + // dispatch({ + // type: CONNECT.TRY_TO_DUPLICATE, + // device, + // }); + + dispatch({ + type: CONNECT.REQUEST_WALLET_TYPE, + device, + }); +}; diff --git a/src/actions/WalletActions.js b/src/actions/WalletActions.js index a7325d25..b477ce14 100644 --- a/src/actions/WalletActions.js +++ b/src/actions/WalletActions.js @@ -87,6 +87,7 @@ export const clearUnavailableDevicesData = (prevState: State, device: Device): T const actions = [ LOCATION_CHANGE, CONNECT.AUTH_DEVICE, + CONNECT.RECEIVE_WALLET_TYPE, ...Object.values(DEVICE).filter(v => typeof v === 'string'), ]; diff --git a/src/actions/constants/TrezorConnect.js b/src/actions/constants/TrezorConnect.js index a49371c5..7a6a446d 100644 --- a/src/actions/constants/TrezorConnect.js +++ b/src/actions/constants/TrezorConnect.js @@ -25,4 +25,7 @@ export const DUPLICATE: 'connect__duplicate' = 'connect__duplicate'; export const DEVICE_STATE_EXCEPTION: 'connect__device_state_exception' = 'connect__device_state_exception'; export const START_ACQUIRING: 'connect__start_acquiring' = 'connect__start_acquiring'; -export const STOP_ACQUIRING: 'connect__stop_acquiring' = 'connect__stop_acquiring'; \ No newline at end of file +export const STOP_ACQUIRING: 'connect__stop_acquiring' = 'connect__stop_acquiring'; + +export const REQUEST_WALLET_TYPE: 'connect__request_wallet_type' = 'connect__request_wallet_type'; +export const RECEIVE_WALLET_TYPE: 'connect__receive_wallet_type' = 'connect__receive_wallet_type'; \ No newline at end of file diff --git a/src/services/WalletService.js b/src/services/WalletService.js index 3cfe4ddb..0e2b87d2 100644 --- a/src/services/WalletService.js +++ b/src/services/WalletService.js @@ -49,10 +49,9 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa api.dispatch(LocalStorageActions.loadData()); break; case WALLET.SET_SELECTED_DEVICE: - if (action.device) { - // try to authorize device - api.dispatch(TrezorConnectActions.getSelectedDeviceState()); - } + // try to authorize device + // api.dispatch(TrezorConnectActions.authorizeDevice()); + api.dispatch(TrezorConnectActions.requestWalletType()); break; case DEVICE.CONNECT: api.dispatch(WalletActions.clearUnavailableDevicesData(prevState, action.device)); @@ -102,10 +101,18 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa // if "selectedAccount" didn't change observe send form props changes api.dispatch(SendFormActionActions.observe(prevState, action)); } - } else if (action.type === CONNECT.AUTH_DEVICE) { - // selected device did changed - // try to restore discovery after device authentication - api.dispatch(DiscoveryActions.restore()); + } else { + switch (action.type) { + case CONNECT.AUTH_DEVICE: + // selected device did changed + // try to restore discovery after device authentication + api.dispatch(DiscoveryActions.restore()); + break; + case CONNECT.RECEIVE_WALLET_TYPE: + api.dispatch(TrezorConnectActions.authorizeDevice()); + break; + default: break; + } } // even if "selectedDevice" didn't change because it was updated on DEVICE.CHANGED before DEVICE.CONNECT action From c570970b423c398d0ee59ef52546efdff78f35a7 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 5 Oct 2018 15:47:51 +0200 Subject: [PATCH 4/7] new modal "wallet type" --- src/actions/ModalActions.js | 12 ++++ src/components/modals/device/Type/index.js | 70 ++++++++++++++++++++++ src/components/modals/index.js | 5 ++ src/reducers/ModalReducer.js | 7 +++ 4 files changed, 94 insertions(+) create mode 100644 src/components/modals/device/Type/index.js diff --git a/src/actions/ModalActions.js b/src/actions/ModalActions.js index 25bebdfc..ea2434d9 100644 --- a/src/actions/ModalActions.js +++ b/src/actions/ModalActions.js @@ -112,6 +112,17 @@ export const onDeviceConnect = (device: Device): ThunkAction => (dispatch: Dispa } }; +export const onWalletTypeRequest = (device: TrezorDevice, hidden: boolean): ThunkAction => (dispatch: Dispatch): void => { + dispatch({ + type: MODAL.CLOSE, + }); + dispatch({ + type: CONNECT.RECEIVE_WALLET_TYPE, + device, + hidden, + }); +}; + export default { onPinSubmit, onPassphraseSubmit, @@ -121,4 +132,5 @@ export default { onForgetSingleDevice, onCancel, onDuplicateDevice, + onWalletTypeRequest, }; \ No newline at end of file diff --git a/src/components/modals/device/Type/index.js b/src/components/modals/device/Type/index.js new file mode 100644 index 00000000..3ea87286 --- /dev/null +++ b/src/components/modals/device/Type/index.js @@ -0,0 +1,70 @@ +/* @flow */ + +import React, { Component } from 'react'; +import styled from 'styled-components'; +import { H3 } from 'components/Heading'; +import P from 'components/Paragraph'; +import Button from 'components/Button'; + +import type { Props } from 'components/modals/index'; + +const Wrapper = styled.div` + width: 360px; + padding: 24px 48px; +`; + +const StyledButton = styled(Button)` + margin: 0 0 10px 0; +`; + +const Row = styled.div` + display: flex; + flex-direction: column; + padding: 10px 0; +`; + +class ForgetDevice extends Component { + + constructor(props: Props) { + super(props); + this.keyboardHandler = this.keyboardHandler.bind(this); + } + + componentDidMount() { + window.addEventListener('keydown', this.keyboardHandler, false); + } + + componentWillUnmount() { + window.removeEventListener('keydown', this.keyboardHandler, false); + } + + keyboardHandler(event: KeyboardEvent): void { + if (event.keyCode === 13) { + event.preventDefault(); + this.foo(false); + } + } + + keyboardHandler: (event: KeyboardEvent) => void; + + foo(hidden: boolean) { + this.props.modalActions.onWalletTypeRequest(this.props.modal.device, hidden); + } + + render() { + if (!this.props.modal.opened) return null; + const { device } = this.props.modal; + const { onCancel } = this.props.modalActions; + return ( + +

RequestWalletType for { device.instanceLabel }?

+ + this.foo(false)}>Basic + this.foo(true)}>Hidden + +
+ ); + } +} + +export default ForgetDevice; \ No newline at end of file diff --git a/src/components/modals/index.js b/src/components/modals/index.js index cb13f290..c78f7b3f 100644 --- a/src/components/modals/index.js +++ b/src/components/modals/index.js @@ -29,6 +29,7 @@ import ConfirmUnverifiedAddress from 'components/modals/confirm/UnverifiedAddres import ForgetDevice from 'components/modals/device/Forget'; import RememberDevice from 'components/modals/device/Remember'; import DuplicateDevice from 'components/modals/device/Duplicate'; +import RequestWalletType from 'components/modals/device/Type'; type OwnProps = { } @@ -123,6 +124,10 @@ class Modal extends Component { component = (); break; + case CONNECT.REQUEST_WALLET_TYPE: + component = (); + break; + default: component = null; } diff --git a/src/reducers/ModalReducer.js b/src/reducers/ModalReducer.js index 49b8bc07..8cfde96d 100644 --- a/src/reducers/ModalReducer.js +++ b/src/reducers/ModalReducer.js @@ -32,6 +32,13 @@ export default function modal(state: State = initialState, action: Action): Stat windowType: action.type, }; + case CONNECT.REQUEST_WALLET_TYPE: + return { + opened: true, + device: action.device, + windowType: action.type, + }; + case CONNECT.REMEMBER_REQUEST: return { opened: true, From 5c9194e814f1e24b51edc8a299b72046559d2cba Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 5 Oct 2018 17:49:51 +0200 Subject: [PATCH 5/7] fixed flowtype in modals --- src/components/modals/device/Type/index.js | 6 ++++-- src/components/modals/passphrase/Type/index.js | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/modals/device/Type/index.js b/src/components/modals/device/Type/index.js index 3ea87286..e9676ac3 100644 --- a/src/components/modals/device/Type/index.js +++ b/src/components/modals/device/Type/index.js @@ -48,13 +48,15 @@ class ForgetDevice extends Component { keyboardHandler: (event: KeyboardEvent) => void; foo(hidden: boolean) { - this.props.modalActions.onWalletTypeRequest(this.props.modal.device, hidden); + const { modal } = this.props; + if (!modal.opened) return; + this.props.modalActions.onWalletTypeRequest(modal.device, hidden); } render() { if (!this.props.modal.opened) return null; const { device } = this.props.modal; - const { onCancel } = this.props.modalActions; + // const { onCancel } = this.props.modalActions; return (

RequestWalletType for { device.instanceLabel }?

diff --git a/src/components/modals/passphrase/Type/index.js b/src/components/modals/passphrase/Type/index.js index 568c1c3d..7ce9951c 100644 --- a/src/components/modals/passphrase/Type/index.js +++ b/src/components/modals/passphrase/Type/index.js @@ -1,9 +1,14 @@ +/* @flow */ + import React from 'react'; import Icon from 'components/Icon'; import colors from 'config/colors'; import icons from 'config/icons'; import styled from 'styled-components'; import { H3 } from 'components/Heading'; +import P from 'components/Paragraph'; + +import type { Props } from 'components/modals/index'; const Wrapper = styled.div` width: 360px; @@ -12,7 +17,7 @@ const Wrapper = styled.div` const Header = styled.div``; -const Confirmation = (props) => { +const Confirmation = (props: Props) => { if (!props.modal.opened) return null; const { device } = props.modal; @@ -21,6 +26,7 @@ const Confirmation = (props) => {

Complete the action on { device.label } device

+

TODO: add detailed text here. Explain passphrase/hidden wallet...

); From 25d95a971f51e7d7cafae01c71bd20fcbe99a62a Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 5 Oct 2018 17:55:26 +0200 Subject: [PATCH 6/7] FORGET_SILENT if disconnected device is not selected and modal is opened --- src/actions/TrezorConnectActions.js | 35 +++++++++++++------------- src/actions/constants/TrezorConnect.js | 1 + src/reducers/DevicesReducer.js | 2 ++ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/actions/TrezorConnectActions.js b/src/actions/TrezorConnectActions.js index 8f0bd2e8..c5928afa 100644 --- a/src/actions/TrezorConnectActions.js +++ b/src/actions/TrezorConnectActions.js @@ -6,6 +6,7 @@ import * as CONNECT from 'actions/constants/TrezorConnect'; import * as NOTIFICATION from 'actions/constants/notification'; import { getDuplicateInstanceNumber } from 'reducers/utils'; import * as RouterActions from 'actions/RouterActions'; +import * as deviceUtils from 'utils/device'; import type { DeviceMessage, @@ -58,7 +59,7 @@ export type TrezorConnectAction = { type: typeof CONNECT.FORGET, device: TrezorDevice } | { - type: typeof CONNECT.FORGET_SINGLE, + type: typeof CONNECT.FORGET_SINGLE | typeof CONNECT.FORGET_SILENT, device: TrezorDevice } | { type: typeof CONNECT.REMEMBER, @@ -222,11 +223,19 @@ export const deviceDisconnect = (device: Device): AsyncAction => async (dispatch if (device.features) { const instances = getState().devices.filter(d => d.features && device.features && d.state && !d.remember && d.features.device_id === device.features.device_id); if (instances.length > 0) { - dispatch({ - type: CONNECT.REMEMBER_REQUEST, - device: instances[0], - instances, - }); + const isSelected = deviceUtils.isSelectedDevice(getState().wallet.selectedDevice, instances[0]); + if (!isSelected && getState().modal.opened) { + dispatch({ + type: CONNECT.FORGET_SILENT, + device: instances[0], + }); + } else { + dispatch({ + type: CONNECT.REMEMBER_REQUEST, + device: instances[0], + instances, + }); + } } else { dispatch(RouterActions.selectFirstAvailableDevice()); } @@ -291,12 +300,7 @@ export const forget = (device: TrezorDevice): Action => ({ device, }); -export const duplicateDevice1 = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { - // dispatch({ - // type: CONNECT.TRY_TO_DUPLICATE, - // device, - // }); - +export const duplicateDeviceOld = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { const instance: number = getDuplicateInstanceNumber(getState().devices, device); const extended: Object = { instance }; dispatch({ @@ -305,12 +309,7 @@ export const duplicateDevice1 = (device: TrezorDevice): AsyncAction => async (di }); }; -export const duplicateDevice = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { - // dispatch({ - // type: CONNECT.TRY_TO_DUPLICATE, - // device, - // }); - +export const duplicateDevice = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch): Promise => { dispatch({ type: CONNECT.REQUEST_WALLET_TYPE, device, diff --git a/src/actions/constants/TrezorConnect.js b/src/actions/constants/TrezorConnect.js index 7a6a446d..2df229ee 100644 --- a/src/actions/constants/TrezorConnect.js +++ b/src/actions/constants/TrezorConnect.js @@ -16,6 +16,7 @@ export const REMEMBER_REQUEST: 'connect__remember_request' = 'connect__remember_ export const FORGET_REQUEST: 'connect__forget_request' = 'connect__forget_request'; export const FORGET: 'connect__forget' = 'connect__forget'; export const FORGET_SINGLE: 'connect__forget_single' = 'connect__forget_single'; +export const FORGET_SILENT: 'connect__forget_silent' = 'connect__forget_silent'; export const DISCONNECT_REQUEST: 'connect__disconnect_request' = 'connect__disconnect_request'; export const REMEMBER: 'connect__remember' = 'connect__remember'; diff --git a/src/reducers/DevicesReducer.js b/src/reducers/DevicesReducer.js index e55b951c..a6ba5fc0 100644 --- a/src/reducers/DevicesReducer.js +++ b/src/reducers/DevicesReducer.js @@ -271,6 +271,7 @@ const onChangeWalletType = (state: State, device: TrezorDevice, hidden: boolean) ...d, state: null, useEmptyPassphrase: !hidden, + ts: new Date().getTime(), } : d; }); return otherDevices.concat(changedDevices); @@ -296,6 +297,7 @@ export default function devices(state: State = initialState, action: Action): St case CONNECT.FORGET: return forgetDevice(state, action.device); case CONNECT.FORGET_SINGLE: + case CONNECT.FORGET_SILENT: return forgetSingleDevice(state, action.device); case DEVICE.CONNECT: From 286caf9d2951c2d1003838c72a9aea85d2fa8936 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Mon, 8 Oct 2018 11:59:10 +0200 Subject: [PATCH 7/7] remove data while switchin between wallet types --- src/reducers/AccountsReducer.js | 2 ++ src/reducers/DiscoveryReducer.js | 2 ++ src/reducers/TokensReducer.js | 2 ++ src/services/LocalStorageService.js | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/reducers/AccountsReducer.js b/src/reducers/AccountsReducer.js index 3e605191..48883d61 100644 --- a/src/reducers/AccountsReducer.js +++ b/src/reducers/AccountsReducer.js @@ -92,6 +92,8 @@ export default (state: State = initialState, action: Action): State => { case CONNECT.FORGET: case CONNECT.FORGET_SINGLE: + case CONNECT.FORGET_SILENT: + case CONNECT.RECEIVE_WALLET_TYPE: return removeAccounts(state, action.device); case WALLET.CLEAR_UNAVAILABLE_DEVICE_DATA: diff --git a/src/reducers/DiscoveryReducer.js b/src/reducers/DiscoveryReducer.js index c6712b50..28294b2d 100644 --- a/src/reducers/DiscoveryReducer.js +++ b/src/reducers/DiscoveryReducer.js @@ -185,6 +185,8 @@ export default function discovery(state: State = initialState, action: Action): }); case CONNECT.FORGET: case CONNECT.FORGET_SINGLE: + case CONNECT.FORGET_SILENT: + case CONNECT.RECEIVE_WALLET_TYPE: return forgetDiscovery(state, action.device); case WALLET.CLEAR_UNAVAILABLE_DEVICE_DATA: return clear(state, action.devices); diff --git a/src/reducers/TokensReducer.js b/src/reducers/TokensReducer.js index 6c6455c7..c880c588 100644 --- a/src/reducers/TokensReducer.js +++ b/src/reducers/TokensReducer.js @@ -71,6 +71,8 @@ export default (state: State = initialState, action: Action): State => { case CONNECT.FORGET: case CONNECT.FORGET_SINGLE: + case CONNECT.FORGET_SILENT: + case CONNECT.RECEIVE_WALLET_TYPE: return forget(state, action.device); case WALLET.CLEAR_UNAVAILABLE_DEVICE_DATA: diff --git a/src/services/LocalStorageService.js b/src/services/LocalStorageService.js index 9a9af858..b98fbf62 100644 --- a/src/services/LocalStorageService.js +++ b/src/services/LocalStorageService.js @@ -102,6 +102,8 @@ const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: Middlewar case CONNECT.FORGET: case CONNECT.FORGET_SINGLE: + case CONNECT.FORGET_SILENT: + case CONNECT.RECEIVE_WALLET_TYPE: case DEVICE.CHANGED: case DEVICE.DISCONNECT: case CONNECT.AUTH_DEVICE: