1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 01:08:27 +00:00

fixed duplicate instance order

This commit is contained in:
Szymon Lesisz 2018-05-15 11:24:30 +02:00
parent 69f479280b
commit c7164702a5

View File

@ -119,10 +119,10 @@ const mergeDevices = (current: TrezorDevice, upcoming: Object): TrezorDevice =>
dev.label = current.label;
dev.unacquired = false;
} else if (!upcoming.unacquired && current.unacquired) {
dev.instanceLabel = upcoming.label;
if (typeof dev.instance === 'number') {
dev.instanceLabel = `${upcoming.label} TODO:(${dev.instance})`;
}
// dev.instanceLabel = upcoming.label;
// if (typeof dev.instance === 'number') {
// dev.instanceLabel = `${upcoming.label} TODO:(${dev.instance})`;
// }
}
@ -336,10 +336,18 @@ const devicesFromLocalStorage = (devices: Array<any>): Array<TrezorDevice> => {
const duplicate = (state: State, device: TrezorDevice): State => {
const newState: State = { ...state };
const affectedDevices: Array<TrezorDevice> = state.devices.filter(d => d.features && device.features && d.features.device_id === device.features.device_id);
const affectedDevices: Array<TrezorDevice> = state.devices.filter(d => d.features && device.features && d.features.device_id === device.features.device_id)
.sort((a, b) => {
if (!a.instance) {
return -1;
} else {
return !b.instance || a.instance > b.instance ? 1 : -1;
}
});
const instance: number = affectedDevices.reduce((inst, dev) => {
return dev.instance ? dev.instance + 1 : inst;
}, 1);
return dev.instance ? dev.instance + 1 : inst + 1;
}, 0);
const newDevice: TrezorDevice = {
...device,