1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-30 19:00:53 +00:00

handle unsupported and/or outdated firmware in discovery process

This commit is contained in:
Szymon Lesisz 2018-11-26 19:36:11 +01:00
parent 9d344920df
commit 7f56cdbcde
5 changed files with 52 additions and 26 deletions

View File

@ -23,7 +23,7 @@ import * as RippleDiscoveryActions from './ripple/RippleDiscoveryActions';
export type DiscoveryStartAction = EthereumDiscoveryActions.DiscoveryStartAction | RippleDiscoveryActions.DiscoveryStartAction;
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,
network: string,
}
@ -78,10 +78,6 @@ const start = (device: TrezorDevice, network: string, ignoreCompleted?: boolean)
const { discovery } = getState();
const discoveryProcess: ?Discovery = discovery.find(d => d.deviceState === device.state && d.network === network);
if (discoveryProcess && discoveryProcess.notSupported) {
return;
}
if (!selected.connected && (!discoveryProcess || !discoveryProcess.completed)) {
dispatch({
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}`);
}
} catch (error) {
// handle unsupported firmware error
// handle not supported firmware error
if (error.message === UI.FIRMWARE_NOT_SUPPORTED) {
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,
network: discoveryProcess.network,
});

View File

@ -67,6 +67,24 @@ const getAccountLoader = (state: State, selectedAccount: SelectedAccountState):
if (account) return null;
// 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 (device.connected) {
// case 1: device is connected but discovery not started yet (probably waiting for auth)

View File

@ -3,7 +3,8 @@
export const START: 'discovery__start' = 'discovery__start';
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 WAITING_FOR_DEVICE: 'discovery__waiting_for_device' = 'discovery__waiting_for_device';
export const WAITING_FOR_BLOCKCHAIN: 'discovery__waiting_for_blockchain' = 'discovery__waiting_for_blockchain';

View File

@ -26,7 +26,8 @@ export type Discovery = {
completed: boolean;
waitingForDevice: boolean;
waitingForBlockchain: boolean;
notSupported: boolean;
fwNotSupported: boolean;
fwOutdated: boolean;
publicKey: string; // used in ethereum only
chainCode: string; // used in ethereum only
@ -44,7 +45,8 @@ const defaultDiscovery: Discovery = {
completed: false,
waitingForDevice: false,
waitingForBlockchain: false,
notSupported: false,
fwNotSupported: false,
fwOutdated: false,
publicKey: '',
chainCode: '',
@ -159,23 +161,16 @@ const waitingForBlockchain = (state: State, action: DiscoveryWaitingAction): Sta
};
const notSupported = (state: State, action: DiscoveryWaitingAction): State => {
const deviceState: string = action.device.state || '0';
const instance: Discovery = {
...defaultDiscovery,
network: action.network,
deviceState,
notSupported: true,
};
const affectedProcesses = state.filter(d => d.deviceState === action.device.state && d.network === action.network);
const otherProcesses = state.filter(d => affectedProcesses.indexOf(d) === -1);
const index: number = findIndex(state, action.network, deviceState);
const newState: State = [...state];
if (index >= 0) {
newState[index] = instance;
} else {
newState.push(instance);
}
const changedProcesses = affectedProcesses.map(d => ({
...d,
fwOutdated: action.type === DISCOVERY.FIRMWARE_OUTDATED,
fwNotSupported: action.type === DISCOVERY.FIRMWARE_NOT_SUPPORTED,
}));
return newState;
return otherProcesses.concat(changedProcesses);
};
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);
case DISCOVERY.WAITING_FOR_BLOCKCHAIN:
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);
case DISCOVERY.FROM_STORAGE:
return action.payload.map((d) => {

View File

@ -229,6 +229,10 @@ const AccountMenu = (props: Props) => {
);
}
if (discovery && (discovery.fwNotSupported || discovery.fwOutdated)) {
discoveryStatus = null;
}
return (
<Wrapper>
<NavLink to={baseUrl}>