diff --git a/src/actions/DiscoveryActions.js b/src/actions/DiscoveryActions.js index 773caeb1..60c99914 100644 --- a/src/actions/DiscoveryActions.js +++ b/src/actions/DiscoveryActions.js @@ -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, }); diff --git a/src/actions/SelectedAccountActions.js b/src/actions/SelectedAccountActions.js index af73d0cd..7b61eda0 100644 --- a/src/actions/SelectedAccountActions.js +++ b/src/actions/SelectedAccountActions.js @@ -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) diff --git a/src/actions/constants/discovery.js b/src/actions/constants/discovery.js index 3b6a49a0..a1b2a65e 100644 --- a/src/actions/constants/discovery.js +++ b/src/actions/constants/discovery.js @@ -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'; diff --git a/src/reducers/DiscoveryReducer.js b/src/reducers/DiscoveryReducer.js index e42bd9c5..384a1175 100644 --- a/src/reducers/DiscoveryReducer.js +++ b/src/reducers/DiscoveryReducer.js @@ -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) => { diff --git a/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js b/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js index f41efa2a..24da4cdb 100644 --- a/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js +++ b/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js @@ -229,6 +229,10 @@ const AccountMenu = (props: Props) => { ); } + if (discovery && (discovery.fwNotSupported || discovery.fwOutdated)) { + discoveryStatus = null; + } + return (