mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +00:00
handle unsupported and/or outdated firmware in discovery process
This commit is contained in:
parent
9d344920df
commit
7f56cdbcde
@ -23,7 +23,7 @@ import * as RippleDiscoveryActions from './ripple/RippleDiscoveryActions';
|
|||||||
export type DiscoveryStartAction = EthereumDiscoveryActions.DiscoveryStartAction | RippleDiscoveryActions.DiscoveryStartAction;
|
export type DiscoveryStartAction = EthereumDiscoveryActions.DiscoveryStartAction | RippleDiscoveryActions.DiscoveryStartAction;
|
||||||
|
|
||||||
export type DiscoveryWaitingAction = {
|
export type DiscoveryWaitingAction = {
|
||||||
type: typeof DISCOVERY.WAITING_FOR_DEVICE | typeof DISCOVERY.WAITING_FOR_BLOCKCHAIN | typeof DISCOVERY.NOT_SUPPORTED,
|
type: typeof DISCOVERY.WAITING_FOR_DEVICE | typeof DISCOVERY.WAITING_FOR_BLOCKCHAIN | typeof DISCOVERY.FIRMWARE_NOT_SUPPORTED | typeof DISCOVERY.FIRMWARE_OUTDATED,
|
||||||
device: TrezorDevice,
|
device: TrezorDevice,
|
||||||
network: string,
|
network: string,
|
||||||
}
|
}
|
||||||
@ -78,10 +78,6 @@ const start = (device: TrezorDevice, network: string, ignoreCompleted?: boolean)
|
|||||||
const { discovery } = getState();
|
const { discovery } = getState();
|
||||||
const discoveryProcess: ?Discovery = discovery.find(d => d.deviceState === device.state && d.network === network);
|
const discoveryProcess: ?Discovery = discovery.find(d => d.deviceState === device.state && d.network === network);
|
||||||
|
|
||||||
if (discoveryProcess && discoveryProcess.notSupported) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!selected.connected && (!discoveryProcess || !discoveryProcess.completed)) {
|
if (!selected.connected && (!discoveryProcess || !discoveryProcess.completed)) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: DISCOVERY.WAITING_FOR_DEVICE,
|
type: DISCOVERY.WAITING_FOR_DEVICE,
|
||||||
@ -192,10 +188,20 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy
|
|||||||
throw new Error(`DiscoveryActions.discoverAccount: Unknown network type: ${network.type}`);
|
throw new Error(`DiscoveryActions.discoverAccount: Unknown network type: ${network.type}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// handle unsupported firmware error
|
// handle not supported firmware error
|
||||||
if (error.message === UI.FIRMWARE_NOT_SUPPORTED) {
|
if (error.message === UI.FIRMWARE_NOT_SUPPORTED) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: DISCOVERY.NOT_SUPPORTED,
|
type: DISCOVERY.FIRMWARE_NOT_SUPPORTED,
|
||||||
|
device,
|
||||||
|
network: discoveryProcess.network,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle outdated firmware error
|
||||||
|
if (error.message === UI.FIRMWARE) {
|
||||||
|
dispatch({
|
||||||
|
type: DISCOVERY.FIRMWARE_OUTDATED,
|
||||||
device,
|
device,
|
||||||
network: discoveryProcess.network,
|
network: discoveryProcess.network,
|
||||||
});
|
});
|
||||||
|
@ -67,6 +67,24 @@ const getAccountLoader = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
if (account) return null;
|
if (account) return null;
|
||||||
// account not found (yet). checking why...
|
// account not found (yet). checking why...
|
||||||
|
|
||||||
|
if (discovery && discovery.fwOutdated) {
|
||||||
|
return {
|
||||||
|
type: 'info',
|
||||||
|
title: `Device ${device.instanceLabel} firmware is outdated`,
|
||||||
|
message: 'TODO: update firmware explanation',
|
||||||
|
shouldRender: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (discovery && discovery.fwNotSupported) {
|
||||||
|
return {
|
||||||
|
type: 'info',
|
||||||
|
title: `Device ${device.instanceLabel} is not supported`,
|
||||||
|
message: 'TODO: model T1 not supported explanation',
|
||||||
|
shouldRender: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (!discovery || (discovery.waitingForDevice || discovery.interrupted)) {
|
if (!discovery || (discovery.waitingForDevice || discovery.interrupted)) {
|
||||||
if (device.connected) {
|
if (device.connected) {
|
||||||
// case 1: device is connected but discovery not started yet (probably waiting for auth)
|
// case 1: device is connected but discovery not started yet (probably waiting for auth)
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
export const START: 'discovery__start' = 'discovery__start';
|
export const START: 'discovery__start' = 'discovery__start';
|
||||||
export const STOP: 'discovery__stop' = 'discovery__stop';
|
export const STOP: 'discovery__stop' = 'discovery__stop';
|
||||||
export const NOT_SUPPORTED: 'discovery__not_supported' = 'discovery__not_supported';
|
export const FIRMWARE_NOT_SUPPORTED: 'discovery__fw_not_supported' = 'discovery__fw_not_supported';
|
||||||
|
export const FIRMWARE_OUTDATED: 'discovery__fw_outdated' = 'discovery__fw_outdated';
|
||||||
export const COMPLETE: 'discovery__complete' = 'discovery__complete';
|
export const COMPLETE: 'discovery__complete' = 'discovery__complete';
|
||||||
export const WAITING_FOR_DEVICE: 'discovery__waiting_for_device' = 'discovery__waiting_for_device';
|
export const WAITING_FOR_DEVICE: 'discovery__waiting_for_device' = 'discovery__waiting_for_device';
|
||||||
export const WAITING_FOR_BLOCKCHAIN: 'discovery__waiting_for_blockchain' = 'discovery__waiting_for_blockchain';
|
export const WAITING_FOR_BLOCKCHAIN: 'discovery__waiting_for_blockchain' = 'discovery__waiting_for_blockchain';
|
||||||
|
@ -26,7 +26,8 @@ export type Discovery = {
|
|||||||
completed: boolean;
|
completed: boolean;
|
||||||
waitingForDevice: boolean;
|
waitingForDevice: boolean;
|
||||||
waitingForBlockchain: boolean;
|
waitingForBlockchain: boolean;
|
||||||
notSupported: boolean;
|
fwNotSupported: boolean;
|
||||||
|
fwOutdated: boolean;
|
||||||
|
|
||||||
publicKey: string; // used in ethereum only
|
publicKey: string; // used in ethereum only
|
||||||
chainCode: string; // used in ethereum only
|
chainCode: string; // used in ethereum only
|
||||||
@ -44,7 +45,8 @@ const defaultDiscovery: Discovery = {
|
|||||||
completed: false,
|
completed: false,
|
||||||
waitingForDevice: false,
|
waitingForDevice: false,
|
||||||
waitingForBlockchain: false,
|
waitingForBlockchain: false,
|
||||||
notSupported: false,
|
fwNotSupported: false,
|
||||||
|
fwOutdated: false,
|
||||||
|
|
||||||
publicKey: '',
|
publicKey: '',
|
||||||
chainCode: '',
|
chainCode: '',
|
||||||
@ -159,23 +161,16 @@ const waitingForBlockchain = (state: State, action: DiscoveryWaitingAction): Sta
|
|||||||
};
|
};
|
||||||
|
|
||||||
const notSupported = (state: State, action: DiscoveryWaitingAction): State => {
|
const notSupported = (state: State, action: DiscoveryWaitingAction): State => {
|
||||||
const deviceState: string = action.device.state || '0';
|
const affectedProcesses = state.filter(d => d.deviceState === action.device.state && d.network === action.network);
|
||||||
const instance: Discovery = {
|
const otherProcesses = state.filter(d => affectedProcesses.indexOf(d) === -1);
|
||||||
...defaultDiscovery,
|
|
||||||
network: action.network,
|
|
||||||
deviceState,
|
|
||||||
notSupported: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
const index: number = findIndex(state, action.network, deviceState);
|
const changedProcesses = affectedProcesses.map(d => ({
|
||||||
const newState: State = [...state];
|
...d,
|
||||||
if (index >= 0) {
|
fwOutdated: action.type === DISCOVERY.FIRMWARE_OUTDATED,
|
||||||
newState[index] = instance;
|
fwNotSupported: action.type === DISCOVERY.FIRMWARE_NOT_SUPPORTED,
|
||||||
} else {
|
}));
|
||||||
newState.push(instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newState;
|
return otherProcesses.concat(changedProcesses);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function discovery(state: State = initialState, action: Action): State {
|
export default function discovery(state: State = initialState, action: Action): State {
|
||||||
@ -192,7 +187,9 @@ export default function discovery(state: State = initialState, action: Action):
|
|||||||
return waitingForDevice(state, action);
|
return waitingForDevice(state, action);
|
||||||
case DISCOVERY.WAITING_FOR_BLOCKCHAIN:
|
case DISCOVERY.WAITING_FOR_BLOCKCHAIN:
|
||||||
return waitingForBlockchain(state, action);
|
return waitingForBlockchain(state, action);
|
||||||
case DISCOVERY.NOT_SUPPORTED:
|
case DISCOVERY.FIRMWARE_NOT_SUPPORTED:
|
||||||
|
return notSupported(state, action);
|
||||||
|
case DISCOVERY.FIRMWARE_OUTDATED:
|
||||||
return notSupported(state, action);
|
return notSupported(state, action);
|
||||||
case DISCOVERY.FROM_STORAGE:
|
case DISCOVERY.FROM_STORAGE:
|
||||||
return action.payload.map((d) => {
|
return action.payload.map((d) => {
|
||||||
|
@ -229,6 +229,10 @@ const AccountMenu = (props: Props) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (discovery && (discovery.fwNotSupported || discovery.fwOutdated)) {
|
||||||
|
discoveryStatus = null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<NavLink to={baseUrl}>
|
<NavLink to={baseUrl}>
|
||||||
|
Loading…
Reference in New Issue
Block a user