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 */
|
/* @flow */
|
||||||
|
|
||||||
import TrezorConnect from 'trezor-connect';
|
import TrezorConnect, { UI } from 'trezor-connect';
|
||||||
import * as DISCOVERY from 'actions/constants/discovery';
|
import * as DISCOVERY from 'actions/constants/discovery';
|
||||||
import * as ACCOUNT from 'actions/constants/account';
|
import * as ACCOUNT from 'actions/constants/account';
|
||||||
import * as NOTIFICATION from 'actions/constants/notification';
|
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 DiscoveryStartAction = EthereumDiscoveryActions.DiscoveryStartAction | RippleDiscoveryActions.DiscoveryStartAction;
|
||||||
|
|
||||||
export type DiscoveryWaitingAction = {
|
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,
|
device: TrezorDevice,
|
||||||
network: string,
|
network: string,
|
||||||
}
|
}
|
||||||
@ -78,6 +78,10 @@ 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,
|
||||||
@ -188,6 +192,16 @@ 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
|
||||||
|
if (error.message === UI.FIRMWARE_NOT_SUPPORTED) {
|
||||||
|
dispatch({
|
||||||
|
type: DISCOVERY.NOT_SUPPORTED,
|
||||||
|
device,
|
||||||
|
network: discoveryProcess.network,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: DISCOVERY.STOP,
|
type: DISCOVERY.STOP,
|
||||||
device,
|
device,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
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 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,6 +26,7 @@ export type Discovery = {
|
|||||||
completed: boolean;
|
completed: boolean;
|
||||||
waitingForDevice: boolean;
|
waitingForDevice: boolean;
|
||||||
waitingForBlockchain: boolean;
|
waitingForBlockchain: boolean;
|
||||||
|
notSupported: 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
|
||||||
@ -43,6 +44,7 @@ const defaultDiscovery: Discovery = {
|
|||||||
completed: false,
|
completed: false,
|
||||||
waitingForDevice: false,
|
waitingForDevice: false,
|
||||||
waitingForBlockchain: false,
|
waitingForBlockchain: false,
|
||||||
|
notSupported: false,
|
||||||
|
|
||||||
publicKey: '',
|
publicKey: '',
|
||||||
chainCode: '',
|
chainCode: '',
|
||||||
@ -156,6 +158,26 @@ const waitingForBlockchain = (state: State, action: DiscoveryWaitingAction): Sta
|
|||||||
return newState;
|
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 {
|
export default function discovery(state: State = initialState, action: Action): State {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case DISCOVERY.START:
|
case DISCOVERY.START:
|
||||||
@ -170,6 +192,8 @@ 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:
|
||||||
|
return notSupported(state, action);
|
||||||
case DISCOVERY.FROM_STORAGE:
|
case DISCOVERY.FROM_STORAGE:
|
||||||
return action.payload.map((d) => {
|
return action.payload.map((d) => {
|
||||||
const hdKey: HDKey = new HDKey();
|
const hdKey: HDKey = new HDKey();
|
||||||
|
Loading…
Reference in New Issue
Block a user