mirror of https://github.com/trezor/trezor-wallet
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.
92 lines
2.2 KiB
92 lines
2.2 KiB
6 years ago
|
/* @flow */
|
||
6 years ago
|
|
||
6 years ago
|
|
||
6 years ago
|
import { TRANSPORT, DEVICE, UI } from 'trezor-connect';
|
||
6 years ago
|
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
|
|
||
6 years ago
|
export type State = {
|
||
6 years ago
|
// devices: Array<TrezorDevice>;
|
||
|
// selectedDevice: ?SelectedDevice;
|
||
6 years ago
|
discoveryComplete: boolean;
|
||
6 years ago
|
error: ?string;
|
||
6 years ago
|
transport: ?{
|
||
|
type: string;
|
||
|
version: string;
|
||
|
};
|
||
|
// browserState: {
|
||
|
// name: string;
|
||
|
// osname: string;
|
||
|
// supported: boolean;
|
||
|
// outdated: boolean;
|
||
|
// mobile: boolean;
|
||
|
// } | {};
|
||
6 years ago
|
browserState: any;
|
||
6 years ago
|
acquiring: boolean;
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
|
||
6 years ago
|
const initialState: State = {
|
||
6 years ago
|
// devices: [],
|
||
|
//selectedDevice: null,
|
||
6 years ago
|
discoveryComplete: false,
|
||
|
error: null,
|
||
6 years ago
|
transport: null,
|
||
6 years ago
|
browserState: {},
|
||
|
acquiring: false,
|
||
6 years ago
|
};
|
||
|
|
||
6 years ago
|
|
||
6 years ago
|
export default function connect(state: State = initialState, action: Action): State {
|
||
6 years ago
|
switch (action.type) {
|
||
6 years ago
|
case UI.IFRAME_HANDSHAKE:
|
||
6 years ago
|
return {
|
||
|
...state,
|
||
6 years ago
|
browserState: action.payload.browser,
|
||
|
};
|
||
|
|
||
|
case CONNECT.START_ACQUIRING:
|
||
6 years ago
|
return {
|
||
|
...state,
|
||
6 years ago
|
acquiring: true,
|
||
|
};
|
||
6 years ago
|
|
||
6 years ago
|
case CONNECT.STOP_ACQUIRING:
|
||
6 years ago
|
return {
|
||
|
...state,
|
||
6 years ago
|
acquiring: false,
|
||
|
};
|
||
6 years ago
|
|
||
6 years ago
|
case CONNECT.INITIALIZATION_ERROR:
|
||
6 years ago
|
return {
|
||
|
...state,
|
||
6 years ago
|
error: action.error,
|
||
6 years ago
|
};
|
||
|
|
||
6 years ago
|
case TRANSPORT.START:
|
||
6 years ago
|
return {
|
||
|
...state,
|
||
6 years ago
|
transport: action.payload,
|
||
6 years ago
|
error: null,
|
||
|
};
|
||
6 years ago
|
|
||
6 years ago
|
case TRANSPORT.ERROR:
|
||
6 years ago
|
return {
|
||
|
...state,
|
||
6 years ago
|
// error: action.payload, // message is wrapped in "device" field. It's dispatched from TrezorConnect.on(DEVICE_EVENT...) in TrezorConnectService
|
||
6 years ago
|
error: 'Transport is missing',
|
||
6 years ago
|
transport: null,
|
||
6 years ago
|
};
|
||
6 years ago
|
|
||
6 years ago
|
|
||
|
default:
|
||
|
return state;
|
||
|
}
|
||
|
}
|