1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-18 06:18:12 +00:00

added new field "useEmptyPassphrase" to TrezorDevice object

This commit is contained in:
Szymon Lesisz 2018-10-05 15:31:03 +02:00
parent 796db24890
commit cb7fbb2e69
2 changed files with 23 additions and 0 deletions

View File

@ -56,6 +56,7 @@ export type AcquiredDevice = $Exact<{
status: DeviceStatus, status: DeviceStatus,
+mode: DeviceMode, +mode: DeviceMode,
state: ?string, state: ?string,
useEmptyPassphrase: boolean,
remember: boolean; // device should be remembered remember: boolean; // device should be remembered
connected: boolean; // device is connected connected: boolean; // device is connected
@ -73,6 +74,7 @@ export type UnknownDevice = $Exact<{
+label: string, +label: string,
+features: null, +features: null,
state: ?string, state: ?string,
useEmptyPassphrase: boolean,
remember: boolean; // device should be remembered remember: boolean; // device should be remembered
connected: boolean; // device is connected connected: boolean; // device is connected

View File

@ -39,6 +39,7 @@ const mergeDevices = (current: TrezorDevice, upcoming: Device | TrezorDevice): T
instanceName: typeof upcoming.instanceName === 'string' ? upcoming.instanceName : current.instanceName, instanceName: typeof upcoming.instanceName === 'string' ? upcoming.instanceName : current.instanceName,
state: current.state, state: current.state,
ts: typeof upcoming.ts === 'number' ? upcoming.ts : current.ts, ts: typeof upcoming.ts === 'number' ? upcoming.ts : current.ts,
useEmptyPassphrase: typeof upcoming.useEmptyPassphrase === 'boolean' ? upcoming.useEmptyPassphrase : current.useEmptyPassphrase,
}; };
if (upcoming.type === 'acquired') { if (upcoming.type === 'acquired') {
@ -89,6 +90,7 @@ const addDevice = (state: State, device: Device): State => {
instanceLabel: device.label, instanceLabel: device.label,
instanceName: null, instanceName: null,
ts: new Date().getTime(), ts: new Date().getTime(),
useEmptyPassphrase: true,
}; };
@ -260,6 +262,22 @@ const onSelectedDevice = (state: State, device: ?TrezorDevice): State => {
return otherDevices.concat([extended]); 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 { export default function devices(state: State = initialState, action: Action): State {
switch (action.type) { switch (action.type) {
case CONNECT.DEVICE_FROM_STORAGE: case CONNECT.DEVICE_FROM_STORAGE:
@ -296,6 +314,9 @@ export default function devices(state: State = initialState, action: Action): St
case WALLET.SET_SELECTED_DEVICE: case WALLET.SET_SELECTED_DEVICE:
return onSelectedDevice(state, action.device); return onSelectedDevice(state, action.device);
case CONNECT.RECEIVE_WALLET_TYPE:
return onChangeWalletType(state, action.device, action.hidden);
default: default:
return state; return state;
} }