getState().connect.devices replaced by getState().devices

pull/2/merge
Szymon Lesisz 6 years ago
parent 977d9f3983
commit 3b452661c6

@ -17,7 +17,7 @@ import BigNumber from 'bignumber.js';
import { initialState } from '../reducers/SendFormReducer';
import { findAccount } from '../reducers/AccountsReducer';
import { findToken } from '../reducers/TokensReducer';
import { findDevice } from '../reducers/TrezorConnectReducer';
import { findDevice } from '../reducers/DevicesReducer';
import type {
Dispatch,
@ -282,11 +282,11 @@ export const validation = (): ThunkAction => {
// corner-case: when same derivation path is used on different networks
const currentNetworkAccount = savedAccounts.find(a => a.network === accountState.network);
if (currentNetworkAccount) {
const device: ?TrezorDevice = findDevice(getState().connect.devices, currentNetworkAccount.deviceID, currentNetworkAccount.deviceState);
const device: ?TrezorDevice = findDevice(getState().devices, currentNetworkAccount.deviceID, currentNetworkAccount.deviceState);
if (!device) return;
infos.address = `${ device.instanceLabel } Account #${ (currentNetworkAccount.index + 1) }`;
} else {
const device: ?TrezorDevice = findDevice(getState().connect.devices, savedAccounts[0].deviceID, savedAccounts[0].deviceState);
const device: ?TrezorDevice = findDevice(getState().devices, savedAccounts[0].deviceID, savedAccounts[0].deviceState);
if (!device) return;
warnings.address = `Looks like it's ${ device.instanceLabel } Account #${ (savedAccounts[0].index + 1) } address of ${ savedAccounts[0].network.toUpperCase() } network`;
}

@ -140,8 +140,7 @@ export const postInit = (): ThunkAction => {
TrezorConnect.on(DEVICE.CONNECT, handleDeviceConnect);
TrezorConnect.on(DEVICE.CONNECT_UNACQUIRED, handleDeviceConnect);
// const devices: Array<TrezorDevice> = getState().connect.devices;
const devices: Array<TrezorDevice> = getState().connect.devices;
const { devices } = getState();
const { initialPathname, initialParams } = getState().wallet;
@ -228,7 +227,7 @@ export const onSelectDevice = (device: TrezorDevice | Device): ThunkAction => {
if (!device.hasOwnProperty('ts')) {
// its device from trezor-connect (called in initConnectedDevice triggered by device_connect event)
// need to lookup if there are unavailable instances
const available: Array<TrezorDevice> = getState().connect.devices.filter(d => d.path === device.path);
const available: Array<TrezorDevice> = getState().devices.filter(d => d.path === device.path);
const latest: Array<TrezorDevice> = sortDevices(available);
if (latest.length > 0 && latest[0].instance) {
@ -249,7 +248,7 @@ export const onSelectDevice = (device: TrezorDevice | Device): ThunkAction => {
export const switchToFirstAvailableDevice = (): AsyncAction => {
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const { devices } = getState().connect;
const { devices } = getState();
if (devices.length > 0) {
// TODO: Priority:
// 1. First Unacquired
@ -331,7 +330,7 @@ export const deviceDisconnect = (device: Device): AsyncAction => {
dispatch( DiscoveryActions.stop(selected) );
}
const instances = getState().connect.devices.filter(d => d.features && d.state && !d.remember && d.features.device_id === device.features.device_id);
const instances = getState().devices.filter(d => d.features && d.state && !d.remember && d.features.device_id === device.features.device_id);
if (instances.length > 0) {
dispatch({
type: CONNECT.REMEMBER_REQUEST,

@ -38,7 +38,8 @@ const BrowserNotSupported = (props: {}): React$Element<string> => {
export default (props: Props) => {
const web3 = props.web3;
const { devices, browserState, transport } = props.connect;
const { devices } = props;
const { browserState, transport } = props.connect;
const localStorageError = props.localStorage.error;
const connectError = props.connect.error;

@ -16,7 +16,9 @@ export type StateProps = {
web3: $ElementType<State, 'web3'>,
wallet: $ElementType<State, 'wallet'>,
connect: $ElementType<State, 'connect'>,
router: $ElementType<State, 'router'>
router: $ElementType<State, 'router'>,
wallet: $ElementType<State, 'wallet'>,
devices: $ElementType<State, 'devices'>,
}
type DispatchProps = {
@ -36,7 +38,9 @@ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: St
web3: state.web3,
wallet: state.wallet,
connect: state.connect,
router: state.router
router: state.router,
wallet: state.wallet,
devices: state.devices,
};
}

@ -2,7 +2,7 @@
'use strict';
import React, { Component } from 'react';
import { getNewInstance } from '~/js/reducers/TrezorConnectReducer'
import { getNewInstance } from '~/js/reducers/DevicesReducer'
import type { Props } from './index';
type State = {
@ -24,7 +24,7 @@ export default class DuplicateDevice extends Component<Props, State> {
const device = props.modal.opened ? props.modal.device : null;
if (!device) return;
const instance = getNewInstance(props.connect.devices, device);
const instance = getNewInstance(props.devices, device);
this.state = {
defaultName: `${device.label} (${instance.toString()})`,
@ -57,7 +57,7 @@ export default class DuplicateDevice extends Component<Props, State> {
let isUsed: boolean = false;
if (value.length > 0) {
isUsed = ( this.props.connect.devices.find(d => d.instanceName === value) !== undefined );
isUsed = ( this.props.devices.find(d => d.instanceName === value) !== undefined );
}
this.setState({

@ -31,9 +31,8 @@ export default class PinModal extends Component<Props, State> {
if (!device) return;
// check if this device is already known
// const isSavedDevice = props.devices.find(d => d.path === props.modal.device.path && d.remember);
const selected = props.wallet.selectedDevice;
let deviceLabel =device.label;
let deviceLabel = device.label;
let singleInput = false;
if (selected && selected.path === device.path) {
deviceLabel = selected.instanceLabel;

@ -34,7 +34,7 @@ type OwnProps = { }
type StateProps = {
modal: $ElementType<State, 'modal'>,
accounts: $ElementType<State, 'accounts'>,
devices: $PropertyType<$ElementType<State, 'connect'>, 'devices'>,
devices: $ElementType<State, 'devices'>,
connect: $ElementType<State, 'connect'>,
selectedAccount: $ElementType<State, 'selectedAccount'>,
sendForm: $ElementType<State, 'sendForm'>,
@ -127,7 +127,7 @@ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: St
return {
modal: state.modal,
accounts: state.accounts,
devices: state.connect.devices,
devices: state.devices,
connect: state.connect,
selectedAccount: state.selectedAccount,
sendForm: state.sendForm,

@ -3,7 +3,7 @@
import React, { Component } from 'react';
import { Notification } from '~/js/components/common/Notification';
import { findDevice } from '~/js/reducers/TrezorConnectReducer';
import { findDevice } from '~/js/reducers/DevicesReducer';
// import * as SelectedAccountActions from '~/js/actions/SelectedAccountActions';
import { default as SelectedAccountActions } from '~/js/actions/SelectedAccountActions';
@ -14,7 +14,7 @@ import type { Discovery } from '~/js/reducers/DiscoveryReducer';
export type StateProps = {
selectedAccount: $ElementType<State, 'selectedAccount'>,
devices: $PropertyType<$ElementType<State, 'connect'>, 'devices'>,
devices: $ElementType<State, 'devices'>,
discovery: $ElementType<State, 'discovery'>,
accounts: $ElementType<State, 'accounts'>,
}

@ -33,7 +33,7 @@ export type Props = StateProps & DispatchProps;
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State, own: OwnProps): StateProps => {
return {
selectedAccount: state.selectedAccount,
devices: state.connect.devices,
devices: state.devices,
accounts: state.accounts,
discovery: state.discovery,
receive: state.receive,

@ -33,7 +33,7 @@ export type Props = StateProps & DispatchProps;
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State, own: OwnProps): StateProps => {
return {
selectedAccount: state.selectedAccount,
devices: state.connect.devices,
devices: state.devices,
accounts: state.accounts,
discovery: state.discovery,
tokens: state.tokens,

@ -35,7 +35,7 @@ export type Props = StateProps & DispatchProps;
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State, own: OwnProps): StateProps => {
return {
selectedAccount: state.selectedAccount,
devices: state.connect.devices,
devices: state.devices,
accounts: state.accounts,
discovery: state.discovery,

@ -10,11 +10,11 @@ import type { TrezorDevice } from '~/flowtype';
const CoinSelection = (props: Props): React$Element<string> => {
const { location } = props.router;
const { config } = props.localStorage;
const selectedDevice = props.connect.selectedDevice;
const { selectedDevice } = props.wallet;
let baseUrl: string = '';
if (selectedDevice) {
baseUrl = `/device/${selectedDevice.id}`;
if (selectedDevice && selectedDevice.features) {
baseUrl = `/device/${selectedDevice.features.device_id}`;
if (selectedDevice.instance) {
baseUrl += `:${selectedDevice.instance}`;
}

@ -10,7 +10,8 @@ import type { TrezorDevice } from '~/flowtype';
export const DeviceSelect = (props: Props) => {
const { devices, transport } = props.connect;
const { devices } = props;
const { transport } = props.connect;
const selected: ?TrezorDevice = props.wallet.selectedDevice;
if (!selected) return null;
@ -136,7 +137,8 @@ export class DeviceDropdown extends Component<Props> {
render() {
const { devices, transport } = this.props.connect;
const { devices } = this.props;
const { transport } = this.props.connect;
const selected: ?TrezorDevice = this.props.wallet.selectedDevice;
if (!selected) return;

@ -27,6 +27,7 @@ type StateProps = {
localStorage: $ElementType<State, 'localStorage'>,
discovery: $ElementType<State, 'discovery'>,
wallet: $ElementType<State, 'wallet'>,
devices: $ElementType<State, 'devices'>,
}
type DispatchProps = {
@ -50,7 +51,8 @@ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: St
fiat: state.fiat,
localStorage: state.localStorage,
discovery: state.discovery,
wallet: state.wallet
wallet: state.wallet,
devices: state.devices
};
}

@ -63,7 +63,7 @@ const findPendingTxs = (accounts: Array<Account>, pending: Array<PendingTx>): Ar
}
const save = (dispatch: Dispatch, getState: GetState): void => {
const devices: Array<TrezorDevice> = getState().connect.devices.filter(d => d.features && d.remember === true);
const devices: Array<TrezorDevice> = getState().devices.filter(d => d.features && d.remember === true);
const accounts: Array<Account> = findAccounts(devices, getState().accounts);
const tokens: Array<Token> = findTokens(accounts, getState().tokens);
const pending: Array<PendingTx> = findPendingTxs(accounts, getState().pending);

@ -48,7 +48,7 @@ const pathToParams = (path: string): RouterLocationState => {
const validation = (api: MiddlewareAPI, params: RouterLocationState): boolean => {
if (params.hasOwnProperty('device')) {
const { devices } = api.getState().connect;
const { devices } = api.getState();
let device: ?TrezorDevice;
if (params.hasOwnProperty('deviceInstance')) {
@ -89,7 +89,8 @@ const RouterService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
const { location } = api.getState().router;
const web3 = api.getState().web3;
const { devices, error } = api.getState().connect;
const { devices } = api.getState();
const { error } = api.getState().connect;
const requestedParams: RouterLocationState = pathToParams(action.payload.pathname);
const currentParams: RouterLocationState = pathToParams(location ? location.pathname : '/');

@ -62,7 +62,7 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
//api.dispatch( TrezorConnectActions.forgetDevice(action.device) );
api.dispatch( TrezorConnectActions.switchToFirstAvailableDevice() );
} else if (action.type === CONNECT.FORGET_SINGLE) {
if (api.getState().connect.devices.length < 1 && action.device.connected) {
if (api.getState().devices.length < 1 && action.device.connected) {
// prompt disconnect device info in LandingPage
api.dispatch({
type: CONNECT.DISCONNECT_REQUEST,
@ -81,8 +81,6 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
api.dispatch( DiscoveryActions.check() );
} else if (action.type === CONNECT.DUPLICATE) {
api.dispatch( TrezorConnectActions.onSelectDevice( action.device ) );
// } else if (action.type === CONNECT.SELECT_DEVICE) {
// api.dispatch( TrezorConnectActions.getSelectedDeviceState() );
} else if (action.type === CONNECT.COIN_CHANGED) {
api.dispatch( TrezorConnectActions.coinChanged( action.payload.network ) );
}

@ -25,7 +25,7 @@ const getSelectedDevice = (state: State): ?TrezorDevice => {
if (!locationState.device) return undefined;
const instance: ?number = locationState.deviceInstance ? parseInt(locationState.deviceInstance) : undefined;
return state.connect.devices.find(d => {
return state.devices.find(d => {
if (d.unacquired && d.path === locationState.device) {
return true;
} else if (d.features && d.features.bootloader_mode && d.path === locationState.device) {
@ -61,7 +61,7 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
const state = api.getState();
// handle devices state change
if (locationChange || prevState.connect.devices !== state.connect.devices) {
if (locationChange || prevState.devices !== state.devices) {
const device = getSelectedDevice(state);
const currentDevice = state.wallet.selectedDevice;
@ -76,7 +76,7 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
type: WALLET.SET_SELECTED_DEVICE,
device
});
if (device) {
api.dispatch( TrezorConnectActions.getSelectedDeviceState() );
} else {

Loading…
Cancel
Save