From 3b452661c67c6fc00abd2a7961b6ccb5f2858403 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Wed, 23 May 2018 10:57:36 +0200 Subject: [PATCH] getState().connect.devices replaced by getState().devices --- src/js/actions/SendFormActions.js | 6 +++--- src/js/actions/TrezorConnectActions.js | 9 ++++----- src/js/components/landing/LandingPage.js | 3 ++- src/js/components/landing/index.js | 8 ++++++-- src/js/components/modal/DuplicateDevice.js | 6 +++--- src/js/components/modal/Passphrase.js | 3 +-- src/js/components/modal/index.js | 4 ++-- src/js/components/wallet/account/SelectedAccount.js | 4 ++-- src/js/components/wallet/account/receive/index.js | 2 +- src/js/components/wallet/account/send/index.js | 2 +- src/js/components/wallet/account/summary/index.js | 2 +- src/js/components/wallet/aside/CoinSelection.js | 6 +++--- src/js/components/wallet/aside/DeviceSelection.js | 6 ++++-- src/js/components/wallet/aside/index.js | 4 +++- src/js/services/LocalStorageService.js | 2 +- src/js/services/RouterService.js | 5 +++-- src/js/services/TrezorConnectService.js | 4 +--- src/js/services/WalletService.js | 6 +++--- 18 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/js/actions/SendFormActions.js b/src/js/actions/SendFormActions.js index 9ab60f18..1ffade54 100644 --- a/src/js/actions/SendFormActions.js +++ b/src/js/actions/SendFormActions.js @@ -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`; } diff --git a/src/js/actions/TrezorConnectActions.js b/src/js/actions/TrezorConnectActions.js index dd465300..a5a81711 100644 --- a/src/js/actions/TrezorConnectActions.js +++ b/src/js/actions/TrezorConnectActions.js @@ -140,8 +140,7 @@ export const postInit = (): ThunkAction => { TrezorConnect.on(DEVICE.CONNECT, handleDeviceConnect); TrezorConnect.on(DEVICE.CONNECT_UNACQUIRED, handleDeviceConnect); - // const devices: Array = getState().connect.devices; - const devices: Array = 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 = getState().connect.devices.filter(d => d.path === device.path); + const available: Array = getState().devices.filter(d => d.path === device.path); const latest: Array = 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 => { - 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, diff --git a/src/js/components/landing/LandingPage.js b/src/js/components/landing/LandingPage.js index 97bb72a1..aa84f456 100644 --- a/src/js/components/landing/LandingPage.js +++ b/src/js/components/landing/LandingPage.js @@ -38,7 +38,8 @@ const BrowserNotSupported = (props: {}): React$Element => { 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; diff --git a/src/js/components/landing/index.js b/src/js/components/landing/index.js index d2812ad7..ba265e3c 100644 --- a/src/js/components/landing/index.js +++ b/src/js/components/landing/index.js @@ -16,7 +16,9 @@ export type StateProps = { web3: $ElementType, wallet: $ElementType, connect: $ElementType, - router: $ElementType + router: $ElementType, + wallet: $ElementType, + devices: $ElementType, } type DispatchProps = { @@ -36,7 +38,9 @@ const mapStateToProps: MapStateToProps = (state: St web3: state.web3, wallet: state.wallet, connect: state.connect, - router: state.router + router: state.router, + wallet: state.wallet, + devices: state.devices, }; } diff --git a/src/js/components/modal/DuplicateDevice.js b/src/js/components/modal/DuplicateDevice.js index 458ba723..94960689 100644 --- a/src/js/components/modal/DuplicateDevice.js +++ b/src/js/components/modal/DuplicateDevice.js @@ -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 { 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 { 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({ diff --git a/src/js/components/modal/Passphrase.js b/src/js/components/modal/Passphrase.js index d5bcfa09..a84b728f 100644 --- a/src/js/components/modal/Passphrase.js +++ b/src/js/components/modal/Passphrase.js @@ -31,9 +31,8 @@ export default class PinModal extends Component { 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; diff --git a/src/js/components/modal/index.js b/src/js/components/modal/index.js index e983005c..05d0457f 100644 --- a/src/js/components/modal/index.js +++ b/src/js/components/modal/index.js @@ -34,7 +34,7 @@ type OwnProps = { } type StateProps = { modal: $ElementType, accounts: $ElementType, - devices: $PropertyType<$ElementType, 'devices'>, + devices: $ElementType, connect: $ElementType, selectedAccount: $ElementType, sendForm: $ElementType, @@ -127,7 +127,7 @@ const mapStateToProps: MapStateToProps = (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, diff --git a/src/js/components/wallet/account/SelectedAccount.js b/src/js/components/wallet/account/SelectedAccount.js index cbe47ddc..747aa27e 100644 --- a/src/js/components/wallet/account/SelectedAccount.js +++ b/src/js/components/wallet/account/SelectedAccount.js @@ -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, - devices: $PropertyType<$ElementType, 'devices'>, + devices: $ElementType, discovery: $ElementType, accounts: $ElementType, } diff --git a/src/js/components/wallet/account/receive/index.js b/src/js/components/wallet/account/receive/index.js index 3a8f8295..509ecf2b 100644 --- a/src/js/components/wallet/account/receive/index.js +++ b/src/js/components/wallet/account/receive/index.js @@ -33,7 +33,7 @@ export type Props = StateProps & DispatchProps; const mapStateToProps: MapStateToProps = (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, diff --git a/src/js/components/wallet/account/send/index.js b/src/js/components/wallet/account/send/index.js index 5946c67e..63b30752 100644 --- a/src/js/components/wallet/account/send/index.js +++ b/src/js/components/wallet/account/send/index.js @@ -33,7 +33,7 @@ export type Props = StateProps & DispatchProps; const mapStateToProps: MapStateToProps = (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, diff --git a/src/js/components/wallet/account/summary/index.js b/src/js/components/wallet/account/summary/index.js index 1da9963f..b1cfb366 100644 --- a/src/js/components/wallet/account/summary/index.js +++ b/src/js/components/wallet/account/summary/index.js @@ -35,7 +35,7 @@ export type Props = StateProps & DispatchProps; const mapStateToProps: MapStateToProps = (state: State, own: OwnProps): StateProps => { return { selectedAccount: state.selectedAccount, - devices: state.connect.devices, + devices: state.devices, accounts: state.accounts, discovery: state.discovery, diff --git a/src/js/components/wallet/aside/CoinSelection.js b/src/js/components/wallet/aside/CoinSelection.js index d2d3114c..610562e4 100644 --- a/src/js/components/wallet/aside/CoinSelection.js +++ b/src/js/components/wallet/aside/CoinSelection.js @@ -10,11 +10,11 @@ import type { TrezorDevice } from '~/flowtype'; const CoinSelection = (props: Props): React$Element => { 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}`; } diff --git a/src/js/components/wallet/aside/DeviceSelection.js b/src/js/components/wallet/aside/DeviceSelection.js index 3975d702..8a92da37 100644 --- a/src/js/components/wallet/aside/DeviceSelection.js +++ b/src/js/components/wallet/aside/DeviceSelection.js @@ -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 { 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; diff --git a/src/js/components/wallet/aside/index.js b/src/js/components/wallet/aside/index.js index 8892225c..89494174 100644 --- a/src/js/components/wallet/aside/index.js +++ b/src/js/components/wallet/aside/index.js @@ -27,6 +27,7 @@ type StateProps = { localStorage: $ElementType, discovery: $ElementType, wallet: $ElementType, + devices: $ElementType, } type DispatchProps = { @@ -50,7 +51,8 @@ const mapStateToProps: MapStateToProps = (state: St fiat: state.fiat, localStorage: state.localStorage, discovery: state.discovery, - wallet: state.wallet + wallet: state.wallet, + devices: state.devices }; } diff --git a/src/js/services/LocalStorageService.js b/src/js/services/LocalStorageService.js index 10a6bd80..50d43908 100644 --- a/src/js/services/LocalStorageService.js +++ b/src/js/services/LocalStorageService.js @@ -63,7 +63,7 @@ const findPendingTxs = (accounts: Array, pending: Array): Ar } const save = (dispatch: Dispatch, getState: GetState): void => { - const devices: Array = getState().connect.devices.filter(d => d.features && d.remember === true); + const devices: Array = getState().devices.filter(d => d.features && d.remember === true); const accounts: Array = findAccounts(devices, getState().accounts); const tokens: Array = findTokens(accounts, getState().tokens); const pending: Array = findPendingTxs(accounts, getState().pending); diff --git a/src/js/services/RouterService.js b/src/js/services/RouterService.js index c25bfcd0..72fc5a0a 100644 --- a/src/js/services/RouterService.js +++ b/src/js/services/RouterService.js @@ -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 : '/'); diff --git a/src/js/services/TrezorConnectService.js b/src/js/services/TrezorConnectService.js index b43418ec..810c4026 100644 --- a/src/js/services/TrezorConnectService.js +++ b/src/js/services/TrezorConnectService.js @@ -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 ) ); } diff --git a/src/js/services/WalletService.js b/src/js/services/WalletService.js index 10592328..4a826161 100644 --- a/src/js/services/WalletService.js +++ b/src/js/services/WalletService.js @@ -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 {