mirror of
https://github.com/trezor/trezor-wallet
synced 2025-02-05 12:51:44 +00:00
FIX: unacquired to acuquired
This commit is contained in:
parent
4fba9ee10d
commit
da467f0304
@ -202,11 +202,10 @@ const sortDevices = (devices: Array<TrezorDevice>): Array<TrezorDevice> => {
|
|||||||
|
|
||||||
export const initConnectedDevice = (device: TrezorDevice | Device): ThunkAction => {
|
export const initConnectedDevice = (device: TrezorDevice | Device): ThunkAction => {
|
||||||
return (dispatch: Dispatch, getState: GetState): void => {
|
return (dispatch: Dispatch, getState: GetState): void => {
|
||||||
|
|
||||||
const selected = findSelectedDevice(getState().connect);
|
const selected = findSelectedDevice(getState().connect);
|
||||||
if (!selected || (selected && selected.state)) {
|
// if (!selected || (selected && selected.state)) {
|
||||||
dispatch( onSelectDevice(device) );
|
dispatch( onSelectDevice(device) );
|
||||||
}
|
// }
|
||||||
// if (device.unacquired && selected && selected.path !== device.path && !selected.connected) {
|
// if (device.unacquired && selected && selected.path !== device.path && !selected.connected) {
|
||||||
// dispatch( onSelectDevice(device) );
|
// dispatch( onSelectDevice(device) );
|
||||||
// } else if (!selected) {
|
// } else if (!selected) {
|
||||||
|
@ -43,7 +43,8 @@ const createAccount = (state: State, action: AccountCreateAction): State => {
|
|||||||
|
|
||||||
// TODO check with device_id
|
// TODO check with device_id
|
||||||
// check if account was created before
|
// check if account was created before
|
||||||
const exist: ?Account = state.find(account => account.address === action.address && account.network === action.network && action.device.features && account.deviceID === action.device.features.device_id);
|
// const exist: ?Account = state.find(account => account.address === action.address && account.network === action.network && action.device.features && account.deviceID === action.device.features.device_id);
|
||||||
|
const exist: ?Account = state.find(account => account.address === action.address && account.network === action.network && account.deviceState === action.device.state);
|
||||||
if (exist) {
|
if (exist) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -148,18 +148,18 @@ const addDevice = (state: State, device: Device): State => {
|
|||||||
|
|
||||||
let affectedDevices: Array<TrezorDevice> = [];
|
let affectedDevices: Array<TrezorDevice> = [];
|
||||||
let otherDevices: Array<TrezorDevice> = [];
|
let otherDevices: Array<TrezorDevice> = [];
|
||||||
if (device.unacquired) {
|
if (!device.features) {
|
||||||
// check if connected device is unacquired, but it was already merged with saved device(s) after DEVICE.CHANGE action
|
// check if connected device is unacquired, and it's already exists
|
||||||
affectedDevices = newState.devices.filter(d => d.path === device.path);
|
affectedDevices = newState.devices.filter(d => d.path === device.path);
|
||||||
const diff: Array<TrezorDevice> = newState.devices.filter(d => affectedDevices.indexOf(d) === -1);
|
|
||||||
|
|
||||||
// if so, ignore this action
|
// if so, ignore this action
|
||||||
if (affectedDevices.length > 0) {
|
if (affectedDevices.length > 0) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
otherDevices = newState.devices.filter(d => affectedDevices.indexOf(d) === -1);
|
||||||
} else {
|
} else {
|
||||||
affectedDevices = newState.devices.filter(d => d.features && d.features.device_id === device.features.device_id);
|
affectedDevices = newState.devices.filter(d => d.features && d.features.device_id === device.features.device_id);
|
||||||
otherDevices = newState.devices.filter(d => d.features && d.features.device_id !== device.features.device_id);
|
const unacquiredDevices = newState.devices.filter(d => d.path.length > 0 && d.path === device.path);
|
||||||
|
otherDevices = newState.devices.filter(d => affectedDevices.indexOf(d) < 0 && unacquiredDevices.indexOf(d) < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (affectedDevices.length > 0 ) {
|
if (affectedDevices.length > 0 ) {
|
||||||
@ -222,7 +222,8 @@ const addDevice = (state: State, device: Device): State => {
|
|||||||
instanceName: null,
|
instanceName: null,
|
||||||
ts: new Date().getTime(),
|
ts: new Date().getTime(),
|
||||||
}
|
}
|
||||||
newState.devices.push(newDevice);
|
// newState.devices.push(newDevice);
|
||||||
|
newState.devices = otherDevices.concat([newDevice]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newState;
|
return newState;
|
||||||
@ -248,49 +249,25 @@ const setDeviceState = (state: State, action: any): State => {
|
|||||||
|
|
||||||
const changeDevice = (state: State, device: Object): State => {
|
const changeDevice = (state: State, device: Object): State => {
|
||||||
|
|
||||||
const newState: State = { ...state };
|
// change only acquired devices
|
||||||
|
if (!device.features) return state;
|
||||||
|
|
||||||
let affectedDevices: Array<TrezorDevice> = [];
|
const affectedDevices: Array<TrezorDevice> = state.devices.filter(d =>
|
||||||
let otherDevices: Array<TrezorDevice> = [];
|
(d.features && d.features.device_id === device.features.device_id && d.features.passphrase_protection === device.features.passphrase_protection) ||
|
||||||
if (device.features) {
|
(d.features && d.path.length > 0 && d.path === device.path)
|
||||||
affectedDevices = state.devices.filter(d =>
|
);
|
||||||
(d.features && d.features.device_id === device.features.device_id && d.features.passphrase_protection === device.features.passphrase_protection) ||
|
const otherDevices: Array<TrezorDevice> = state.devices.filter(d => affectedDevices.indexOf(d) === -1);
|
||||||
(d.path.length > 0 && d.path === device.path)
|
|
||||||
);
|
|
||||||
otherDevices = state.devices.filter(d => affectedDevices.indexOf(d) === -1);
|
|
||||||
} else {
|
|
||||||
affectedDevices = state.devices.filter(d => !d.features && d.path === device.path);
|
|
||||||
otherDevices = state.devices.filter(d => affectedDevices.indexOf(d) === -1);
|
|
||||||
// otherDevices = state.devices.filter(d => d.path !== device.path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (affectedDevices.length > 0) {
|
if (affectedDevices.length > 0) {
|
||||||
|
const newState: State = { ...state };
|
||||||
const isAffectedUnacquired: number = affectedDevices.findIndex(d => d.unacquired);
|
const changedDevices = affectedDevices.map(d => mergeDevices(d, device));
|
||||||
// if (isAffectedUnacquired >= 0 && affectedDevices.length > 1){
|
newState.devices = otherDevices.concat(changedDevices);
|
||||||
if (isAffectedUnacquired >= 0){
|
return newState;
|
||||||
// TODO: should unacquired device be removed? or merged?
|
|
||||||
//affectedDevices.splice(isAffectedUnacquired, 1);
|
|
||||||
} else {
|
|
||||||
// replace existing values
|
|
||||||
const changedDevices: Array<TrezorDevice> = affectedDevices.map(d => mergeDevices(d, device));
|
|
||||||
newState.devices = otherDevices.concat(changedDevices);
|
|
||||||
}
|
|
||||||
|
|
||||||
// else if (isAffectedUnacquired >= 0 && !device.unacquired && affectedDevices.length > 1) {
|
|
||||||
// affectedDevices.splice(isAffectedUnacquired, 1);
|
|
||||||
// }
|
|
||||||
// acquiring selected device. remove unnecessary (not acquired) device from list
|
|
||||||
// after this action selectedDevice needs to be updated (in TrezorConnectService)
|
|
||||||
if (state.selectedDevice && device.path === state.selectedDevice.id && affectedDevices.length > 1) {
|
|
||||||
// affectedDevices = affectedDevices.filter(d => d.path !== state.selectedDevice.id && d.features);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newState;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const disconnectDevice = (state: State, device: Device): State => {
|
const disconnectDevice = (state: State, device: Device): State => {
|
||||||
|
|
||||||
const newState: State = { ...state };
|
const newState: State = { ...state };
|
||||||
|
@ -78,11 +78,12 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
|
|||||||
} else if (action.type === DEVICE.CHANGED) {
|
} else if (action.type === DEVICE.CHANGED) {
|
||||||
// selected device was previously unacquired, but now it's acquired
|
// selected device was previously unacquired, but now it's acquired
|
||||||
// we need to change route
|
// we need to change route
|
||||||
if (prevState.selectedDevice) {
|
// if (prevState.selectedDevice) {
|
||||||
if (!action.device.unacquired && action.device.path === prevState.selectedDevice.id) {
|
// if (action.device.features && action.device.path === prevState.selectedDevice.id) {
|
||||||
api.dispatch( TrezorConnectActions.onSelectDevice(action.device) );
|
// //console.log("REDIR HERE!", action.device)
|
||||||
}
|
// //api.dispatch( TrezorConnectActions.onSelectDevice(action.device) );
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
} else if (action.type === DEVICE.CONNECT || action.type === DEVICE.CONNECT_UNACQUIRED) {
|
} else if (action.type === DEVICE.CONNECT || action.type === DEVICE.CONNECT_UNACQUIRED) {
|
||||||
|
|
||||||
api.dispatch( DiscoveryActions.restore() );
|
api.dispatch( DiscoveryActions.restore() );
|
||||||
@ -108,7 +109,8 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
|
|||||||
api.dispatch( DiscoveryActions.check() );
|
api.dispatch( DiscoveryActions.check() );
|
||||||
} else if (action.type === CONNECT.DUPLICATE) {
|
} else if (action.type === CONNECT.DUPLICATE) {
|
||||||
api.dispatch( TrezorConnectActions.selectDuplicatedDevice() );
|
api.dispatch( TrezorConnectActions.selectDuplicatedDevice() );
|
||||||
} else if (action.type === CONNECT.ACQUIRED || action.type === CONNECT.SELECT_DEVICE) {
|
// } else if (action.type === CONNECT.ACQUIRED || action.type === CONNECT.SELECT_DEVICE) {
|
||||||
|
} else if (action.type === CONNECT.SELECT_DEVICE) {
|
||||||
api.dispatch( TrezorConnectActions.getSelectedDeviceState() );
|
api.dispatch( TrezorConnectActions.getSelectedDeviceState() );
|
||||||
} else if (action.type === CONNECT.COIN_CHANGED) {
|
} else if (action.type === CONNECT.COIN_CHANGED) {
|
||||||
api.dispatch( TrezorConnectActions.coinChanged( action.payload.network ) );
|
api.dispatch( TrezorConnectActions.coinChanged( action.payload.network ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user