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; }