You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-wallet/src/reducers/TrezorConnectReducer.js

92 lines
2.2 KiB

6 years ago
/* @flow */
6 years ago
import { TRANSPORT, DEVICE, UI } from 'trezor-connect';
import * as CONNECT from 'actions/constants/TrezorConnect';
import * as WALLET from 'actions/constants/wallet';
6 years ago
6 years ago
import type { Action } from 'flowtype';
6 years ago
export type SelectedDevice = {
6 years ago
id: string; // could be device path if unacquired or features.device_id
6 years ago
instance: ?number;
}
6 years ago
export type State = {
// devices: Array<TrezorDevice>;
// selectedDevice: ?SelectedDevice;
6 years ago
discoveryComplete: boolean;
error: ?string;
6 years ago
transport: ?{
type: string;
version: string;
};
// browserState: {
// name: string;
// osname: string;
// supported: boolean;
// outdated: boolean;
// mobile: boolean;
// } | {};
browserState: any;
acquiring: boolean;
6 years ago
}
6 years ago
6 years ago
const initialState: State = {
// devices: [],
//selectedDevice: null,
6 years ago
discoveryComplete: false,
error: null,
transport: null,
browserState: {},
acquiring: false,
6 years ago
};
export default function connect(state: State = initialState, action: Action): State {
6 years ago
switch (action.type) {
case UI.IFRAME_HANDSHAKE:
return {
...state,
browserState: action.payload.browser,
};
case CONNECT.START_ACQUIRING:
return {
...state,
acquiring: true,
};
case CONNECT.STOP_ACQUIRING:
return {
...state,
acquiring: false,
};
6 years ago
case CONNECT.INITIALIZATION_ERROR:
6 years ago
return {
...state,
error: action.error,
6 years ago
};
case TRANSPORT.START:
return {
...state,
transport: action.payload,
error: null,
};
case TRANSPORT.ERROR:
6 years ago
return {
...state,
// error: action.payload, // message is wrapped in "device" field. It's dispatched from TrezorConnect.on(DEVICE_EVENT...) in TrezorConnectService
error: 'Transport is missing',
transport: null,
6 years ago
};
6 years ago
6 years ago
default:
return state;
}
}