mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-30 20:28:09 +00:00
handle NOT_SUPPORTED methods in Discovery
This commit is contained in:
parent
ee8f884ced
commit
3774110a83
@ -1,6 +1,6 @@
|
||||
/* @flow */
|
||||
|
||||
import TrezorConnect from 'trezor-connect';
|
||||
import TrezorConnect, { UI } from 'trezor-connect';
|
||||
import * as DISCOVERY from 'actions/constants/discovery';
|
||||
import * as ACCOUNT from 'actions/constants/account';
|
||||
import * as NOTIFICATION from 'actions/constants/notification';
|
||||
@ -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,
|
||||
type: typeof DISCOVERY.WAITING_FOR_DEVICE | typeof DISCOVERY.WAITING_FOR_BLOCKCHAIN | typeof DISCOVERY.NOT_SUPPORTED,
|
||||
device: TrezorDevice,
|
||||
network: string,
|
||||
}
|
||||
@ -78,6 +78,10 @@ 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,
|
||||
@ -188,6 +192,16 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy
|
||||
throw new Error(`DiscoveryActions.discoverAccount: Unknown network type: ${network.type}`);
|
||||
}
|
||||
} catch (error) {
|
||||
// handle unsupported firmware error
|
||||
if (error.message === UI.FIRMWARE_NOT_SUPPORTED) {
|
||||
dispatch({
|
||||
type: DISCOVERY.NOT_SUPPORTED,
|
||||
device,
|
||||
network: discoveryProcess.network,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: DISCOVERY.STOP,
|
||||
device,
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
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 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';
|
||||
|
@ -26,6 +26,7 @@ export type Discovery = {
|
||||
completed: boolean;
|
||||
waitingForDevice: boolean;
|
||||
waitingForBlockchain: boolean;
|
||||
notSupported: boolean;
|
||||
|
||||
publicKey: string; // used in ethereum only
|
||||
chainCode: string; // used in ethereum only
|
||||
@ -43,6 +44,7 @@ const defaultDiscovery: Discovery = {
|
||||
completed: false,
|
||||
waitingForDevice: false,
|
||||
waitingForBlockchain: false,
|
||||
notSupported: false,
|
||||
|
||||
publicKey: '',
|
||||
chainCode: '',
|
||||
@ -156,6 +158,26 @@ const waitingForBlockchain = (state: State, action: DiscoveryWaitingAction): Sta
|
||||
return newState;
|
||||
};
|
||||
|
||||
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 index: number = findIndex(state, action.network, deviceState);
|
||||
const newState: State = [...state];
|
||||
if (index >= 0) {
|
||||
newState[index] = instance;
|
||||
} else {
|
||||
newState.push(instance);
|
||||
}
|
||||
|
||||
return newState;
|
||||
};
|
||||
|
||||
export default function discovery(state: State = initialState, action: Action): State {
|
||||
switch (action.type) {
|
||||
case DISCOVERY.START:
|
||||
@ -170,6 +192,8 @@ 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:
|
||||
return notSupported(state, action);
|
||||
case DISCOVERY.FROM_STORAGE:
|
||||
return action.payload.map((d) => {
|
||||
const hdKey: HDKey = new HDKey();
|
||||
|
Loading…
Reference in New Issue
Block a user