mirror of
https://github.com/trezor/trezor-wallet
synced 2025-06-01 05:38:45 +00:00
flowtype fixes corresponding changes in trezor-connect
This commit is contained in:
parent
578fb736f5
commit
c197f7f7b6
@ -1,5 +1,4 @@
|
|||||||
[include]
|
[include]
|
||||||
.*/node_modules/trezor-connect
|
|
||||||
|
|
||||||
[ignore]
|
[ignore]
|
||||||
.*/node_modules/rc-util/.*
|
.*/node_modules/rc-util/.*
|
||||||
@ -21,8 +20,6 @@
|
|||||||
./src/flowtype/npm/web3.js
|
./src/flowtype/npm/web3.js
|
||||||
./src/flowtype/css.js
|
./src/flowtype/css.js
|
||||||
|
|
||||||
./node_modules/trezor-connect/flowtype/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Store as ReduxStore,
|
Store as ReduxStore,
|
||||||
ReduxDispatch,
|
ReduxDispatch,
|
||||||
@ -35,6 +34,8 @@ import type { FiatRateAction } from '~/js/services/CoinmarketcapService'; // thi
|
|||||||
import type {
|
import type {
|
||||||
Device,
|
Device,
|
||||||
Features,
|
Features,
|
||||||
|
DeviceStatus,
|
||||||
|
DeviceFirmwareStatus,
|
||||||
DeviceMessageType,
|
DeviceMessageType,
|
||||||
TransportMessageType,
|
TransportMessageType,
|
||||||
UiMessageType,
|
UiMessageType,
|
||||||
@ -42,22 +43,42 @@ import type {
|
|||||||
|
|
||||||
import type { RouterAction, LocationState } from 'react-router-redux';
|
import type { RouterAction, LocationState } from 'react-router-redux';
|
||||||
|
|
||||||
export type TrezorDevice = {
|
export type AcquiredDevice = $Exact<{
|
||||||
|
+type: 'acquired',
|
||||||
|
path: string,
|
||||||
|
+label: string,
|
||||||
|
+features: Features,
|
||||||
|
+firmware: DeviceFirmwareStatus,
|
||||||
|
status: DeviceStatus,
|
||||||
|
state: ?string,
|
||||||
|
|
||||||
remember: boolean; // device should be remembered
|
remember: boolean; // device should be remembered
|
||||||
connected: boolean; // device is connected
|
connected: boolean; // device is connected
|
||||||
available: boolean; // device cannot be used because of features.passphrase_protection is different then expected
|
available: boolean; // device cannot be used because of features.passphrase_protection is different then expected
|
||||||
path: string;
|
|
||||||
label: string;
|
|
||||||
state: ?string;
|
|
||||||
instance?: number;
|
instance?: number;
|
||||||
instanceLabel: string;
|
instanceLabel: string;
|
||||||
instanceName: ?string;
|
instanceName: ?string;
|
||||||
features?: Features;
|
|
||||||
unacquired?: boolean;
|
|
||||||
isUsedElsewhere?: boolean;
|
|
||||||
featuresNeedsReload?: boolean;
|
|
||||||
ts: number;
|
ts: number;
|
||||||
}
|
|
||||||
|
}>;
|
||||||
|
|
||||||
|
export type UnknownDevice = $Exact<{
|
||||||
|
+type: 'unacquired' | 'unreadable',
|
||||||
|
path: string,
|
||||||
|
+label: string,
|
||||||
|
+features: null,
|
||||||
|
state: ?string,
|
||||||
|
|
||||||
|
remember: boolean; // device should be remembered
|
||||||
|
connected: boolean; // device is connected
|
||||||
|
available: boolean; // device cannot be used because of features.passphrase_protection is different then expected
|
||||||
|
instance?: number;
|
||||||
|
instanceLabel: string;
|
||||||
|
instanceName: ?string;
|
||||||
|
ts: number;
|
||||||
|
}>
|
||||||
|
|
||||||
|
export type TrezorDevice = AcquiredDevice | UnknownDevice;
|
||||||
|
|
||||||
export type RouterLocationState = LocationState;
|
export type RouterLocationState = LocationState;
|
||||||
|
|
||||||
|
@ -191,7 +191,6 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy
|
|||||||
const ethAddress: string = EthereumjsUtil.toChecksumAddress(publicAddress);
|
const ethAddress: string = EthereumjsUtil.toChecksumAddress(publicAddress);
|
||||||
const network = discoveryProcess.network;
|
const network = discoveryProcess.network;
|
||||||
|
|
||||||
|
|
||||||
// TODO: check if address was created before
|
// TODO: check if address was created before
|
||||||
|
|
||||||
// verify address with TREZOR
|
// verify address with TREZOR
|
||||||
|
@ -836,14 +836,8 @@ export const onSend = (): AsyncAction => async (dispatch: Dispatch, getState: Ge
|
|||||||
state: selected.state,
|
state: selected.state,
|
||||||
},
|
},
|
||||||
useEmptyPassphrase: !selected.instance,
|
useEmptyPassphrase: !selected.instance,
|
||||||
path: txData.address_n,
|
path: address_n,
|
||||||
nonce: strip(txData.nonce),
|
transaction: txData
|
||||||
gasPrice: strip(txData.gasPrice),
|
|
||||||
gasLimit: strip(txData.gasLimit),
|
|
||||||
to: strip(txData.to),
|
|
||||||
value: strip(txData.value),
|
|
||||||
data: strip(txData.data),
|
|
||||||
chainId: txData.chainId,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!signedTransaction || !signedTransaction.success) {
|
if (!signedTransaction || !signedTransaction.success) {
|
||||||
@ -860,10 +854,9 @@ export const onSend = (): AsyncAction => async (dispatch: Dispatch, getState: Ge
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
txData.r = `0x${signedTransaction.payload.r}`;
|
txData.r = signedTransaction.payload.r;
|
||||||
txData.s = `0x${signedTransaction.payload.s}`;
|
txData.s = signedTransaction.payload.s;
|
||||||
txData.v = w3.toHex(signedTransaction.payload.v);
|
txData.v = signedTransaction.payload.v;
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const tx = new EthereumjsTx(txData);
|
const tx = new EthereumjsTx(txData);
|
||||||
|
@ -16,7 +16,6 @@ import { resolveAfter } from '../utils/promiseUtils';
|
|||||||
|
|
||||||
import type {
|
import type {
|
||||||
Device,
|
Device,
|
||||||
ResponseMessage,
|
|
||||||
DeviceMessage,
|
DeviceMessage,
|
||||||
UiMessage,
|
UiMessage,
|
||||||
TransportMessage,
|
TransportMessage,
|
||||||
@ -115,9 +114,10 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
|
|||||||
try {
|
try {
|
||||||
await TrezorConnect.init({
|
await TrezorConnect.init({
|
||||||
transportReconnect: true,
|
transportReconnect: true,
|
||||||
// connectSrc: 'https://localhost:8088/',
|
connectSrc: typeof window.LOCAL === 'string' ? window.LOCAL : 'https://connect.trezor.io/5/',
|
||||||
connectSrc: 'https://sisyfos.trezor.io/',
|
// connectSrc: 'https://connect.trezor.io/5/',
|
||||||
debug: false,
|
// connectSrc: 'https://sisyfos.trezor.io/',
|
||||||
|
debug: true,
|
||||||
popup: false,
|
popup: false,
|
||||||
webusb: true,
|
webusb: true,
|
||||||
pendingTransportEvent: (getState().devices.length < 1),
|
pendingTransportEvent: (getState().devices.length < 1),
|
||||||
@ -156,7 +156,7 @@ export const postInit = (): ThunkAction => (dispatch: Dispatch, getState: GetSta
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (devices.length > 0) {
|
if (devices.length > 0) {
|
||||||
const unacquired: ?TrezorDevice = devices.find(d => d.unacquired);
|
const unacquired: ?TrezorDevice = devices.find(d => d.features);
|
||||||
if (unacquired) {
|
if (unacquired) {
|
||||||
dispatch(onSelectDevice(unacquired));
|
dispatch(onSelectDevice(unacquired));
|
||||||
} else {
|
} else {
|
||||||
@ -246,7 +246,7 @@ export const switchToFirstAvailableDevice = (): AsyncAction => async (dispatch:
|
|||||||
// 1. First Unacquired
|
// 1. First Unacquired
|
||||||
// 2. First connected
|
// 2. First connected
|
||||||
// 3. Saved with latest timestamp
|
// 3. Saved with latest timestamp
|
||||||
const unacquired = devices.find(d => d.unacquired);
|
const unacquired = devices.find(d => !d.features);
|
||||||
if (unacquired) {
|
if (unacquired) {
|
||||||
dispatch(initConnectedDevice(unacquired));
|
dispatch(initConnectedDevice(unacquired));
|
||||||
} else {
|
} else {
|
||||||
@ -316,7 +316,7 @@ export const deviceDisconnect = (device: Device): AsyncAction => async (dispatch
|
|||||||
dispatch(DiscoveryActions.stop(selected));
|
dispatch(DiscoveryActions.stop(selected));
|
||||||
}
|
}
|
||||||
|
|
||||||
const instances = getState().devices.filter(d => d.features && d.state && !d.remember && d.features.device_id === device.features.device_id);
|
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) {
|
if (instances.length > 0) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: CONNECT.REMEMBER_REQUEST,
|
type: CONNECT.REMEMBER_REQUEST,
|
||||||
|
@ -75,7 +75,8 @@ export const toggleDeviceDropdown = (opened: boolean): WalletAction => ({
|
|||||||
export const clearUnavailableDevicesData = (prevState: State, device: Device): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
export const clearUnavailableDevicesData = (prevState: State, device: Device): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
||||||
if (!device.features) return;
|
if (!device.features) return;
|
||||||
|
|
||||||
const affectedDevices = prevState.devices.filter(d => d.features
|
const affectedDevices = prevState.devices.filter(d =>
|
||||||
|
d.features && device.features
|
||||||
&& d.features.device_id === device.features.device_id
|
&& d.features.device_id === device.features.device_id
|
||||||
&& d.features.passphrase_protection !== device.features.passphrase_protection);
|
&& d.features.passphrase_protection !== device.features.passphrase_protection);
|
||||||
|
|
||||||
|
@ -67,7 +67,8 @@ export default class DuplicateDevice extends Component<Props, State> {
|
|||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
if (!this.props.modal.opened) return;
|
if (!this.props.modal.opened) return;
|
||||||
this.props.modalActions.onDuplicateDevice({ ...this.props.modal.device, instanceName: this.state.instanceName, instance: this.state.instance });
|
const extended: Object = { instanceName: this.state.instanceName, instance: this.state.instance };
|
||||||
|
this.props.modalActions.onDuplicateDevice({ ...this.props.modal.device, ...extended });
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -26,16 +26,17 @@ export const DeviceSelect = (props: Props) => {
|
|||||||
css += ' unavailable';
|
css += ' unavailable';
|
||||||
deviceStatus = 'Unavailable';
|
deviceStatus = 'Unavailable';
|
||||||
} else {
|
} else {
|
||||||
if (selected.unacquired) {
|
if (selected.type === 'acquired') {
|
||||||
|
if (selected.status === 'occupied') {
|
||||||
|
css += ' used-elsewhere';
|
||||||
|
deviceStatus = 'Used in other window';
|
||||||
|
} else if (selected.status === 'used') {
|
||||||
|
css += ' reload-features';
|
||||||
|
}
|
||||||
|
} else if (selected.type === 'unacquired') {
|
||||||
css += ' unacquired';
|
css += ' unacquired';
|
||||||
deviceStatus = 'Used in other window';
|
deviceStatus = 'Used in other window';
|
||||||
}
|
}
|
||||||
if (selected.isUsedElsewhere) {
|
|
||||||
css += ' used-elsewhere';
|
|
||||||
deviceStatus = 'Used in other window';
|
|
||||||
} else if (selected.featuresNeedsReload) {
|
|
||||||
css += ' reload-features';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selected.features && selected.features.major_version > 1) {
|
if (selected.features && selected.features.major_version > 1) {
|
||||||
@ -147,14 +148,12 @@ export class DeviceDropdown extends Component<Props> {
|
|||||||
if (selected.features) {
|
if (selected.features) {
|
||||||
const deviceMenuItems: Array<DeviceMenuItem> = [];
|
const deviceMenuItems: Array<DeviceMenuItem> = [];
|
||||||
|
|
||||||
if (selected.isUsedElsewhere) {
|
if (selected.status !== 'available') {
|
||||||
deviceMenuItems.push({ type: 'reload', label: 'Renew session' });
|
|
||||||
} else if (selected.featuresNeedsReload) {
|
|
||||||
deviceMenuItems.push({ type: 'reload', label: 'Renew session' });
|
deviceMenuItems.push({ type: 'reload', label: 'Renew session' });
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceMenuItems.push({ type: 'settings', label: 'Device settings' });
|
deviceMenuItems.push({ type: 'settings', label: 'Device settings' });
|
||||||
if (selected.features && selected.features.passphrase_protection && selected.connected && selected.available) {
|
if (selected.features.passphrase_protection && selected.connected && selected.available) {
|
||||||
deviceMenuItems.push({ type: 'clone', label: 'Clone device' });
|
deviceMenuItems.push({ type: 'clone', label: 'Clone device' });
|
||||||
}
|
}
|
||||||
//if (selected.remember) {
|
//if (selected.remember) {
|
||||||
@ -177,7 +176,7 @@ export class DeviceDropdown extends Component<Props> {
|
|||||||
|
|
||||||
let deviceStatus: string = 'Connected';
|
let deviceStatus: string = 'Connected';
|
||||||
let css: string = 'device item';
|
let css: string = 'device item';
|
||||||
if (dev.unacquired || dev.isUsedElsewhere) {
|
if (!dev.features || (dev.features && dev.status === 'occupied')) {
|
||||||
deviceStatus = 'Used in other window';
|
deviceStatus = 'Used in other window';
|
||||||
css += ' unacquired';
|
css += ' unacquired';
|
||||||
} else if (!dev.connected) {
|
} else if (!dev.connected) {
|
||||||
|
@ -29,10 +29,7 @@ const mergeDevices = (current: TrezorDevice, upcoming: Device | TrezorDevice): T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dev: TrezorDevice = {
|
const extended = {
|
||||||
// ...current,
|
|
||||||
...upcoming,
|
|
||||||
// make sure that instance specific variables will not be overridden
|
|
||||||
connected: typeof upcoming.connected === 'boolean' ? upcoming.connected : current.connected,
|
connected: typeof upcoming.connected === 'boolean' ? upcoming.connected : current.connected,
|
||||||
available: typeof upcoming.available === 'boolean' ? upcoming.available : current.available,
|
available: typeof upcoming.available === 'boolean' ? upcoming.available : current.available,
|
||||||
remember: typeof upcoming.remember === 'boolean' ? upcoming.remember : current.remember,
|
remember: typeof upcoming.remember === 'boolean' ? upcoming.remember : current.remember,
|
||||||
@ -41,16 +38,26 @@ 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,
|
||||||
};
|
|
||||||
// corner-case: trying to merge unacquired device with acquired
|
|
||||||
// make sure that sensitive fields will not be changed and device will remain acquired
|
|
||||||
if (upcoming.unacquired && current.state) {
|
|
||||||
dev.unacquired = false;
|
|
||||||
dev.features = current.features;
|
|
||||||
dev.label = current.label;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dev;
|
if (upcoming.type === 'acquired') {
|
||||||
|
return { ...upcoming, ...extended };
|
||||||
|
} else if (upcoming.type === 'unacquired' && current.features && current.state) {
|
||||||
|
// corner-case: trying to merge unacquired device with acquired
|
||||||
|
// make sure that sensitive fields will not be changed and device will remain acquired
|
||||||
|
return {
|
||||||
|
type: 'acquired',
|
||||||
|
path: upcoming.path,
|
||||||
|
...current,
|
||||||
|
...extended
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
...upcoming,
|
||||||
|
features: null,
|
||||||
|
...extended
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const addDevice = (state: State, device: Device): State => {
|
const addDevice = (state: State, device: Device): State => {
|
||||||
@ -65,14 +72,15 @@ const addDevice = (state: State, device: Device): State => {
|
|||||||
}
|
}
|
||||||
otherDevices = state.filter(d => affectedDevices.indexOf(d) === -1);
|
otherDevices = state.filter(d => affectedDevices.indexOf(d) === -1);
|
||||||
} else {
|
} else {
|
||||||
affectedDevices = state.filter(d => d.features && d.features.device_id === device.features.device_id);
|
affectedDevices = state.filter(d =>
|
||||||
|
d.features &&
|
||||||
|
device.features &&
|
||||||
|
d.features.device_id === device.features.device_id);
|
||||||
const unacquiredDevices = state.filter(d => d.path.length > 0 && d.path === device.path);
|
const unacquiredDevices = state.filter(d => d.path.length > 0 && d.path === device.path);
|
||||||
otherDevices = state.filter(d => affectedDevices.indexOf(d) < 0 && unacquiredDevices.indexOf(d) < 0);
|
otherDevices = state.filter(d => affectedDevices.indexOf(d) < 0 && unacquiredDevices.indexOf(d) < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newDevice: TrezorDevice = {
|
const extended = {
|
||||||
...device,
|
|
||||||
acquiring: false,
|
|
||||||
remember: false,
|
remember: false,
|
||||||
connected: true,
|
connected: true,
|
||||||
available: true,
|
available: true,
|
||||||
@ -82,6 +90,17 @@ 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(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const newDevice: TrezorDevice = device.type === 'acquired' ? {
|
||||||
|
...device,
|
||||||
|
// acquiring: false,
|
||||||
|
...extended
|
||||||
|
} : {
|
||||||
|
...device,
|
||||||
|
features: null,
|
||||||
|
...extended
|
||||||
};
|
};
|
||||||
|
|
||||||
if (affectedDevices.length > 0) {
|
if (affectedDevices.length > 0) {
|
||||||
@ -112,7 +131,12 @@ const addDevice = (state: State, device: Device): State => {
|
|||||||
// changedDevices.push(newDevice);
|
// changedDevices.push(newDevice);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const changedDevices: Array<TrezorDevice> = affectedDevices.filter(d => d.features && d.features.passphrase_protection === device.features.passphrase_protection).map(d => mergeDevices(d, { ...device, connected: true, available: true }));
|
const changedDevices: Array<TrezorDevice> = affectedDevices.filter(d =>
|
||||||
|
d.features && device.features &&
|
||||||
|
d.features.passphrase_protection === device.features.passphrase_protection).map(d => {
|
||||||
|
const extended: Object = { connected: true, available: true }
|
||||||
|
return mergeDevices(d, { ...device, ...extended })
|
||||||
|
});
|
||||||
if (changedDevices.length !== affectedDevices.length) {
|
if (changedDevices.length !== affectedDevices.length) {
|
||||||
changedDevices.push(newDevice);
|
changedDevices.push(newDevice);
|
||||||
}
|
}
|
||||||
@ -144,20 +168,21 @@ const duplicate = (state: State, device: TrezorDevice): State => {
|
|||||||
return newState;
|
return newState;
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeDevice = (state: State, device: Device): State => {
|
const changeDevice = (state: State, device: Device | TrezorDevice, extended: Object): State => {
|
||||||
// change only acquired devices
|
// change only acquired devices
|
||||||
if (!device.features) return state;
|
if (!device.features) return state;
|
||||||
|
|
||||||
// find devices with the same device_id and passphrase_protection settings
|
// find devices with the same device_id and passphrase_protection settings
|
||||||
// or devices with the same path (TODO: should be that way?)
|
// or devices with the same path (TODO: should be that way?)
|
||||||
const affectedDevices: Array<TrezorDevice> = state.filter(d => (d.features && d.features.device_id === device.features.device_id && d.features.passphrase_protection === device.features.passphrase_protection)
|
const affectedDevices: Array<TrezorDevice> = state.filter(d =>
|
||||||
|
(d.features && device.features && d.features.device_id === device.features.device_id && d.features.passphrase_protection === device.features.passphrase_protection)
|
||||||
|| (d.features && d.path.length > 0 && d.path === device.path));
|
|| (d.features && d.path.length > 0 && d.path === device.path));
|
||||||
|
|
||||||
const otherDevices: Array<TrezorDevice> = state.filter(d => affectedDevices.indexOf(d) === -1);
|
const otherDevices: Array<TrezorDevice> = state.filter(d => affectedDevices.indexOf(d) === -1);
|
||||||
|
|
||||||
if (affectedDevices.length > 0) {
|
if (affectedDevices.length > 0) {
|
||||||
// merge incoming device with State
|
// merge incoming device with State
|
||||||
const changedDevices = affectedDevices.map(d => mergeDevices(d, device));
|
const changedDevices = affectedDevices.map(d => mergeDevices(d, { ...device, ...extended }));
|
||||||
return otherDevices.concat(changedDevices);
|
return otherDevices.concat(changedDevices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,15 +202,22 @@ const authDevice = (state: State, device: TrezorDevice, deviceState: string): St
|
|||||||
|
|
||||||
|
|
||||||
// Transform JSON form local storage into State
|
// Transform JSON form local storage into State
|
||||||
const devicesFromStorage = (devices: Array<TrezorDevice>): State => devices.map((d: TrezorDevice) => ({
|
const devicesFromStorage = (devices: Array<TrezorDevice>): State => devices.map((device: TrezorDevice) => {
|
||||||
...d,
|
const extended = {
|
||||||
connected: false,
|
connected: false,
|
||||||
available: false,
|
available: false,
|
||||||
path: '',
|
path: '',
|
||||||
acquiring: false,
|
}
|
||||||
featuresNeedsReload: false,
|
|
||||||
isUsedElsewhere: false,
|
return device.type === 'acquired' ? {
|
||||||
}));
|
...device,
|
||||||
|
...extended
|
||||||
|
} : {
|
||||||
|
...device,
|
||||||
|
features: null,
|
||||||
|
...extended
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// Remove all device reference from State
|
// Remove all device reference from State
|
||||||
const forgetDevice = (state: State, device: TrezorDevice): State => state.filter(d => d.remember || (d.features && device.features && d.features.device_id !== device.features.device_id) || (!d.features && d.path !== device.path));
|
const forgetDevice = (state: State, device: TrezorDevice): State => state.filter(d => d.remember || (d.features && device.features && d.features.device_id !== device.features.device_id) || (!d.features && d.path !== device.path));
|
||||||
@ -204,15 +236,16 @@ const disconnectDevice = (state: State, device: Device): State => {
|
|||||||
const otherDevices: State = state.filter(d => affectedDevices.indexOf(d) === -1);
|
const otherDevices: State = state.filter(d => affectedDevices.indexOf(d) === -1);
|
||||||
|
|
||||||
if (affectedDevices.length > 0) {
|
if (affectedDevices.length > 0) {
|
||||||
const acquiredDevices = affectedDevices.filter(d => !d.unacquired && d.state);
|
const acquiredDevices = affectedDevices.filter(d => d.features && d.state).map(d => {
|
||||||
return otherDevices.concat(acquiredDevices.map((d) => {
|
if (d.type === 'acquired') {
|
||||||
d.connected = false;
|
d.connected = false;
|
||||||
d.available = false;
|
d.available = false;
|
||||||
d.isUsedElsewhere = false;
|
d.status = 'available';
|
||||||
d.featuresNeedsReload = false;
|
d.path = '';
|
||||||
d.path = '';
|
}
|
||||||
return d;
|
return d;
|
||||||
}));
|
});
|
||||||
|
return otherDevices.concat(acquiredDevices);
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
@ -221,7 +254,8 @@ const disconnectDevice = (state: State, device: Device): State => {
|
|||||||
const onSelectedDevice = (state: State, device: ?TrezorDevice): State => {
|
const onSelectedDevice = (state: State, device: ?TrezorDevice): State => {
|
||||||
if (device) {
|
if (device) {
|
||||||
const otherDevices: Array<TrezorDevice> = state.filter(d => d !== device);
|
const otherDevices: Array<TrezorDevice> = state.filter(d => d !== device);
|
||||||
return otherDevices.concat([{ ...device, ts: new Date().getTime() }]);
|
device.ts = new Date().getTime();
|
||||||
|
return otherDevices.concat([ device ]);
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
@ -238,7 +272,8 @@ export default function devices(state: State = initialState, action: Action): St
|
|||||||
return authDevice(state, action.device, action.state);
|
return authDevice(state, action.device, action.state);
|
||||||
|
|
||||||
case CONNECT.REMEMBER:
|
case CONNECT.REMEMBER:
|
||||||
return changeDevice(state, { ...action.device, path: '', remember: true });
|
// return changeDevice(state, { ...action.device, path: '', remember: true });
|
||||||
|
return changeDevice(state, action.device, { path: '', remember: true });
|
||||||
|
|
||||||
case CONNECT.FORGET:
|
case CONNECT.FORGET:
|
||||||
return forgetDevice(state, action.device);
|
return forgetDevice(state, action.device);
|
||||||
@ -250,11 +285,12 @@ export default function devices(state: State = initialState, action: Action): St
|
|||||||
return addDevice(state, action.device);
|
return addDevice(state, action.device);
|
||||||
|
|
||||||
case DEVICE.CHANGED:
|
case DEVICE.CHANGED:
|
||||||
return changeDevice(state, { ...action.device, connected: true, available: true });
|
// return changeDevice(state, { ...action.device, connected: true, available: true });
|
||||||
|
return changeDevice(state, action.device, { connected: true, available: true });
|
||||||
// TODO: check if available will propagate to unavailable
|
// TODO: check if available will propagate to unavailable
|
||||||
|
|
||||||
case DEVICE.DISCONNECT:
|
case DEVICE.DISCONNECT:
|
||||||
case DEVICE.DISCONNECT_UNACQUIRED:
|
// case DEVICE.DISCONNECT_UNACQUIRED:
|
||||||
return disconnectDevice(state, action.device);
|
return disconnectDevice(state, action.device);
|
||||||
|
|
||||||
case WALLET.SET_SELECTED_DEVICE:
|
case WALLET.SET_SELECTED_DEVICE:
|
||||||
|
@ -54,7 +54,7 @@ export default function modal(state: State = initialState, action: Action): Stat
|
|||||||
};
|
};
|
||||||
|
|
||||||
case DEVICE.CHANGED:
|
case DEVICE.CHANGED:
|
||||||
if (state.opened && action.device.path === state.device.path && action.device.isUsedElsewhere) {
|
if (state.opened && action.device.path === state.device.path && action.device.status === 'occupied') {
|
||||||
return initialState;
|
return initialState;
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
|
@ -30,7 +30,7 @@ export const getSelectedDevice = (state: State): ?TrezorDevice => {
|
|||||||
|
|
||||||
const instance: ?number = locationState.deviceInstance ? parseInt(locationState.deviceInstance) : undefined;
|
const instance: ?number = locationState.deviceInstance ? parseInt(locationState.deviceInstance) : undefined;
|
||||||
return state.devices.find((d) => {
|
return state.devices.find((d) => {
|
||||||
if (d.unacquired && d.path === locationState.device) {
|
if (!d.features && d.path === locationState.device) {
|
||||||
return true;
|
return true;
|
||||||
} if (d.features && d.features.bootloader_mode && d.path === locationState.device) {
|
} if (d.features && d.features.bootloader_mode && d.path === locationState.device) {
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user