Browse Source

Fix flow for react-redux

master
Gaëtan Renaudeau 7 years ago
parent
commit
a822f11c92
  1. 1
      .eslintrc
  2. 3
      package.json
  3. 2
      scripts/postinstall.sh
  4. 32
      src/components/CounterValue/index.js
  5. 22
      src/components/DeviceMonit/index.js
  6. 47
      src/components/DeviceMonitNew/index.js
  7. 20
      src/components/base/FormattedVal/index.js
  8. 2
      src/components/modals/StepConnectDevice.js
  9. 2723
      yarn.lock

1
.eslintrc

@ -42,6 +42,7 @@
"no-return-assign": 0,
"no-shadow": 0,
"no-underscore-dangle": 0,
"no-unused-vars": ["error", { "argsIgnorePattern": "^_", "vars": "all", "args": "after-used", "ignoreRestSiblings": true }],
"no-use-before-define": 0,
"no-restricted-syntax": 0,
"no-prototype-builtins": 0,

3
package.json

@ -39,7 +39,7 @@
"@ledgerhq/hw-app-eth": "^4.7.3",
"@ledgerhq/hw-transport": "^4.7.3",
"@ledgerhq/hw-transport-node-hid": "^4.7.6",
"@ledgerhq/live-common": "^2.0.0-rc4",
"@ledgerhq/live-common": "^2.0.0",
"axios": "^0.18.0",
"babel-runtime": "^6.26.0",
"bcryptjs": "^2.4.3",
@ -56,6 +56,7 @@
"history": "^4.7.2",
"i18next": "^11.2.2",
"i18next-node-fs-backend": "^1.0.0",
"invariant": "^2.2.4",
"ledger-test-library": "KhalilBellakrid/ledger-test-library-nodejs#7d37482",
"lodash": "^4.17.5",
"moment": "^2.22.1",

2
scripts/postinstall.sh

@ -1,5 +1,5 @@
#/bin/bash
flow-typed install -s --overwrite
rm flow-typed/npm/{react-i18next_v7.x.x.js,react-redux_v5.x.x.js,styled-components_v3.x.x.js}
rm flow-typed/npm/{react-i18next_v7.x.x.js,styled-components_v3.x.x.js}
electron-builder install-app-deps

32
src/components/CounterValue/index.js

@ -2,35 +2,44 @@
import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import type { Currency } from '@ledgerhq/live-common/lib/types'
import { counterValueCurrencySelector } from 'reducers/settings'
import { calculateCounterValueSelector } from 'reducers/counterValues'
import FormattedVal from 'components/base/FormattedVal'
type Props = {
import type { State } from 'reducers'
type OwnProps = {
// wich market to query
// FIXME drop ticker in favor of currency
ticker: string,
currency?: Currency,
// when? if not given: take latest
date?: Date,
value: number,
}
type Props = OwnProps & {
// from reducers
counterValueCurrency: CryptoCurrency,
counterValueCurrency: Currency,
value: number,
}
const mapStateToProps = (state, props) => {
const mapStateToProps = (state: State, props: OwnProps) => {
const { ticker, value, date } = props
// TODO: in wallet-common, stop using currency.
// always use ticker and remove that hack
if (ticker) {
// FIXME actually ticker should be deprecated, not currency!!
console.warn('CounterValue: `currency` should be passed instead of `ticker`') // eslint-disable-line no-console
}
let { currency } = props
if (!currency && ticker) {
currency = generateFakeCurrency(ticker)
} else if (currency) {
console.warn('`currency` is deprecated in CounterValue. use `ticker` instead.') // eslint-disable-line no-console
}
const counterValueCurrency = counterValueCurrencySelector(state)
@ -46,11 +55,6 @@ const mapStateToProps = (state, props) => {
}
class CounterValue extends PureComponent<Props> {
static defaultProps = {
value: 0,
date: undefined,
}
render() {
const { value, counterValueCurrency, date, ...props } = this.props
return (
@ -79,7 +83,7 @@ function generateFakeCurrency(ticker) {
],
// unused
coinType: 0,
id: '',
color: '#000',
name: 'fake-coin',
scheme: 'bitcoin',

22
src/components/DeviceMonit/index.js

@ -9,23 +9,29 @@ import { sendEvent } from 'renderer/events'
import { getCurrentDevice } from 'reducers/devices'
import type { Device } from 'types/common'
const mapStateToProps = state => ({
currentDevice: getCurrentDevice(state),
})
import type { State as StoreState } from 'reducers'
type DeviceStatus = 'unconnected' | 'connected' | 'appOpened'
type Props = {
currentDevice: Device | null,
type OwnProps = {
account?: Account,
onStatusChange?: DeviceStatus => void,
render?: Function,
// FIXME prefer use of children function
render?: DeviceStatus => React$Element<*>,
}
type Props = OwnProps & {
currentDevice: ?Device,
}
type State = {
status: DeviceStatus,
}
const mapStateToProps = (state: StoreState, _props: OwnProps) => ({
currentDevice: getCurrentDevice(state),
})
class DeviceMonit extends PureComponent<Props, State> {
state = {
status: this.props.currentDevice ? 'connected' : 'unconnected',
@ -70,7 +76,7 @@ class DeviceMonit extends PureComponent<Props, State> {
checkAppOpened = () => {
const { currentDevice, account } = this.props
if (currentDevice === null || !account || account.currency === null) {
if (!currentDevice || !account) {
return
}
@ -83,7 +89,7 @@ class DeviceMonit extends PureComponent<Props, State> {
_timeout: any = null
handleStatusChange = status => {
handleStatusChange = (status: DeviceStatus) => {
const { onStatusChange } = this.props
this.setState({ status })
onStatusChange && onStatusChange(status)

47
src/components/DeviceMonitNew/index.js

@ -1,5 +1,5 @@
// @flow
import invariant from 'invariant'
import { PureComponent } from 'react'
import { connect } from 'react-redux'
import { ipcRenderer } from 'electron'
@ -9,29 +9,40 @@ import type { Device, Devices } from 'types/common'
import { sendEvent } from 'renderer/events'
import { getDevices } from 'reducers/devices'
import type { State as StoreState } from 'reducers/index'
const mapStateToProps = state => ({
devices: getDevices(state),
})
type OwnProps = {
currency: ?CryptoCurrency,
deviceSelected: ?Device,
account: ?Account,
onStatusChange?: (DeviceStatus, AppStatus) => void,
// TODO prefer children function
render?: ({
appStatus: AppStatus,
currency: CryptoCurrency,
devices: Devices,
deviceSelected: ?Device,
deviceStatus: DeviceStatus,
}) => React$Element<*>,
}
type Props = OwnProps & {
devices: Devices,
}
type DeviceStatus = 'unconnected' | 'connected'
type AppStatus = 'success' | 'fail' | 'progress'
type Props = {
currency: ?CryptoCurrency,
devices: Devices,
deviceSelected: Device | null,
account?: Account,
onStatusChange?: (DeviceStatus, AppStatus) => void,
render?: Function,
}
type State = {
deviceStatus: DeviceStatus,
appStatus: AppStatus,
}
const mapStateToProps = (state: StoreState) => ({
devices: getDevices(state),
})
class DeviceMonit extends PureComponent<Props, State> {
state = {
appStatus: 'progress',
@ -80,7 +91,7 @@ class DeviceMonit extends PureComponent<Props, State> {
checkAppOpened = () => {
const { deviceSelected, account, currency } = this.props
if (deviceSelected === null) {
if (!deviceSelected) {
return
}
@ -105,7 +116,7 @@ class DeviceMonit extends PureComponent<Props, State> {
})
}
_timeout: any = null
_timeout: *
handleStatusChange = (deviceStatus, appStatus) => {
const { onStatusChange } = this.props
@ -118,7 +129,7 @@ class DeviceMonit extends PureComponent<Props, State> {
const { deviceStatus } = this.state
const { deviceSelected } = this.props
if (deviceSelected === null) {
if (!deviceSelected) {
return
}
@ -138,9 +149,11 @@ class DeviceMonit extends PureComponent<Props, State> {
const { appStatus, deviceStatus } = this.state
if (render) {
const cur = account ? account.currency : currency
invariant(cur, 'currency is either provided or taken from account')
return render({
appStatus,
currency: account ? account.currency : currency,
currency: cur,
devices,
deviceSelected: deviceStatus === 'connected' ? deviceSelected : null,
deviceStatus,

20
src/components/base/FormattedVal/index.js

@ -8,6 +8,7 @@ import isUndefined from 'lodash/isUndefined'
import type { Settings } from 'types/common'
import type { Unit } from '@ledgerhq/live-common/lib/types'
import type { State } from 'reducers'
import {
formatCurrencyUnit,
@ -39,7 +40,7 @@ I.defaultProps = {
color: undefined,
}
const mapStateToProps = state => ({
const mapStateToProps = (state: State) => ({
settings: state.settings,
})
@ -48,11 +49,11 @@ type Props = {
animateTicker?: boolean,
color?: string,
disableRounding?: boolean,
fiat?: string | null,
fiat?: string,
isPercent?: boolean,
settings?: Settings,
showCode?: boolean,
unit?: Unit | null,
unit?: Unit,
val: number,
withIcon?: boolean,
}
@ -136,17 +137,4 @@ export function FormattedVal(props: Props) {
)
}
FormattedVal.defaultProps = {
alwaysShowSign: false,
animateTicker: false,
color: undefined,
disableRounding: false,
fiat: null,
isPercent: false,
settings: undefined,
showCode: false,
unit: null,
withIcon: false,
}
export default connect(mapStateToProps)(FormattedVal)

2
src/components/modals/StepConnectDevice.js

@ -12,7 +12,7 @@ type Props = {
accountName?: string,
account?: ?Account,
currency?: ?CryptoCurrency,
deviceSelected: ?Device,
deviceSelected?: ?Device,
onChangeDevice: Function,
onStatusChange: Function,
}

2723
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save