Browse Source

Merge pull request #393 from gre/bump-live-common

display tBTC for testnet + remove fiat prop of FormattedVal
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
03c8d05581
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      package.json
  2. 49
      src/components/AccountPage/index.js
  3. 17
      src/components/BalanceSummary/BalanceInfos.js
  4. 19
      src/components/BalanceSummary/index.js
  5. 2
      src/components/CounterValue/index.js
  6. 12
      src/components/DashboardPage/AccountCard.js
  7. 40
      src/components/DashboardPage/index.js
  8. 6
      src/components/base/Chart/Tooltip.js
  9. 9
      src/components/base/Chart/handleMouseEvents.js
  10. 6
      src/components/base/FormattedVal/__tests__/FormattedVal.test.js
  11. 9
      src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap
  12. 35
      src/components/base/FormattedVal/index.js
  13. 2
      src/components/modals/AddAccount/03-step-import.js
  14. 6
      yarn.lock

2
package.json

@ -42,7 +42,7 @@
"@ledgerhq/hw-transport": "^4.12.0",
"@ledgerhq/hw-transport-node-hid": "^4.12.0",
"@ledgerhq/ledger-core": "^1.3.0",
"@ledgerhq/live-common": "2.11.0",
"@ledgerhq/live-common": "2.12.0",
"axios": "^0.18.0",
"babel-runtime": "^6.26.0",
"bcryptjs": "^2.4.3",

49
src/components/AccountPage/index.js

@ -1,18 +1,12 @@
// @flow
import React, { PureComponent } from 'react'
import { ipcRenderer } from 'electron'
import { compose } from 'redux'
import { connect } from 'react-redux'
import { translate } from 'react-i18next'
import { Redirect } from 'react-router'
import styled from 'styled-components'
import {
formatCurrencyUnit,
getFiatCurrencyByTicker,
} from '@ledgerhq/live-common/lib/helpers/currencies'
import type { Account } from '@ledgerhq/live-common/lib/types'
import type { Currency, Account } from '@ledgerhq/live-common/lib/types'
import { MODAL_SEND, MODAL_RECEIVE, MODAL_SETTINGS_ACCOUNT } from 'config/constants'
@ -21,7 +15,7 @@ import type { T } from 'types/common'
import { darken } from 'styles/helpers'
import { getAccountById } from 'reducers/accounts'
import { getCounterValueCode, localeSelector } from 'reducers/settings'
import { counterValueCurrencySelector, localeSelector } from 'reducers/settings'
import { openModal } from 'reducers/modals'
import IconControls from 'icons/Controls'
@ -56,7 +50,7 @@ const ButtonSettings = styled(Button).attrs({
const mapStateToProps = (state, props) => ({
account: getAccountById(state, props.match.params.id),
counterValue: getCounterValueCode(state),
counterValue: counterValueCurrencySelector(state),
settings: localeSelector(state),
})
@ -65,11 +59,10 @@ const mapDispatchToProps = {
}
type Props = {
counterValue: string,
counterValue: Currency,
t: T,
account?: Account,
openModal: Function,
locale: string,
}
type State = {
@ -83,37 +76,6 @@ class AccountPage extends PureComponent<Props, State> {
daysCount: 7,
}
handleCalculateBalance = data => {
const { counterValue, account, locale } = this.props
if (!account) {
return
}
if (process.platform === 'darwin' && this._cacheBalance !== data.totalBalance) {
this._cacheBalance = data.totalBalance
ipcRenderer.send('touch-bar-update', {
text: account.name,
color: account.currency.color,
balance: {
currency: formatCurrencyUnit(account.unit, account.balance, {
showCode: true,
locale,
}),
counterValue: formatCurrencyUnit(
getFiatCurrencyByTicker(counterValue).units[0],
data.totalBalance,
{
showCode: true,
locale,
},
),
},
})
}
}
handleChangeSelectedTime = item =>
this.setState({
selectedTime: item.key,
@ -163,7 +125,6 @@ class AccountPage extends PureComponent<Props, State> {
chartId={`account-chart-${account.id}`}
counterValue={counterValue}
daysCount={daysCount}
onCalculate={this.handleCalculateBalance}
selectedTime={selectedTime}
renderHeader={({ totalBalance, sinceBalance, refBalance }) => (
<Box flow={4} mb={2}>
@ -173,7 +134,7 @@ class AccountPage extends PureComponent<Props, State> {
animateTicker
alwaysShowSign={false}
color="warmGrey"
fiat={counterValue}
unit={counterValue.units[0]}
fontSize={6}
showCode
val={totalBalance}

17
src/components/BalanceSummary/BalanceInfos.js

@ -3,7 +3,7 @@
import React from 'react'
import styled from 'styled-components'
import type { Unit } from '@ledgerhq/live-common/lib/types'
import type { Unit, Currency } from '@ledgerhq/live-common/lib/types'
import type { T } from 'types/common'
import Box from 'components/base/Box'
@ -27,13 +27,12 @@ type BalanceSinceProps = {
type BalanceTotalProps = {
children?: any,
counterValue?: string,
unit: Unit,
totalBalance: number,
unit?: Unit,
}
type Props = {
counterValue: string,
counterValue: Currency,
} & BalanceSinceProps
export function BalanceSincePercent(props: BalanceSinceProps) {
@ -60,7 +59,7 @@ export function BalanceSinceDiff(props: Props) {
<FormattedVal
color="dark"
animateTicker
fiat={counterValue}
unit={counterValue.units[0]}
fontSize={7}
showCode
val={totalBalance - sinceBalance}
@ -72,16 +71,15 @@ export function BalanceSinceDiff(props: Props) {
}
export function BalanceTotal(props: BalanceTotalProps) {
const { counterValue, totalBalance, children, unit } = props
const { unit, totalBalance, children } = props
return (
<Box grow {...props}>
<FormattedVal
animateTicker
color="dark"
fiat={counterValue}
unit={unit}
fontSize={8}
showCode
unit={unit}
val={totalBalance}
/>
{children}
@ -90,7 +88,6 @@ export function BalanceTotal(props: BalanceTotalProps) {
}
BalanceTotal.defaultProps = {
counterValue: undefined,
children: null,
unit: undefined,
}
@ -99,7 +96,7 @@ function BalanceInfos(props: Props) {
const { t, totalBalance, since, sinceBalance, refBalance, counterValue } = props
return (
<Box horizontal alignItems="center" flow={7}>
<BalanceTotal counterValue={counterValue} totalBalance={totalBalance}>
<BalanceTotal unit={counterValue.units[0]} totalBalance={totalBalance}>
<Sub>{t('dashboard:totalBalance')}</Sub>
</BalanceTotal>
<BalanceSincePercent

19
src/components/BalanceSummary/index.js

@ -1,8 +1,7 @@
// @flow
import React, { Fragment } from 'react'
import type { Account } from '@ledgerhq/live-common/lib/types'
import { getFiatCurrencyByTicker } from '@ledgerhq/live-common/lib/helpers/currencies'
import type { Currency, Account } from '@ledgerhq/live-common/lib/types'
import Chart from 'components/base/Chart'
import Box, { Card } from 'components/base/Box'
@ -10,8 +9,7 @@ import CalculateBalance from 'components/CalculateBalance'
import FormattedVal from 'components/base/FormattedVal'
type Props = {
onCalculate: Function,
counterValue: string,
counterValue: Currency,
chartColor: string,
chartId: string,
accounts: Account[],
@ -31,20 +29,13 @@ const BalanceSummary = ({
chartId,
counterValue,
daysCount,
onCalculate,
renderHeader,
selectedTime,
}: Props) => {
const currency = getFiatCurrencyByTicker(counterValue)
const account = accounts.length === 1 ? accounts[0] : undefined
return (
<Card p={0} py={6}>
<CalculateBalance
accounts={accounts}
counterValue={counterValue}
daysCount={daysCount}
onCalculate={onCalculate}
>
<CalculateBalance accounts={accounts} daysCount={daysCount}>
{({ isAvailable, balanceHistory, balanceStart, balanceEnd }) =>
!isAvailable ? null : (
<Fragment>
@ -66,7 +57,7 @@ const BalanceSummary = ({
color={chartColor}
data={balanceHistory}
height={250}
currency={currency}
currency={counterValue}
tickXScale={selectedTime}
renderTooltip={
isAvailable && !account
@ -77,7 +68,7 @@ const BalanceSummary = ({
fontSize={5}
color="dark"
showCode
fiat={counterValue}
unit={counterValue.units[0]}
val={d.value}
/>
<Box ff="Open Sans|Regular" color="grey" fontSize={3} mt={2}>

2
src/components/CounterValue/index.js

@ -55,7 +55,7 @@ class CounterValue extends PureComponent<Props> {
return (
<FormattedVal
val={value}
fiat={counterValueCurrency.units[0].code}
unit={counterValueCurrency.units[0]}
showCode
alwaysShowSign
{...props}

12
src/components/DashboardPage/AccountCard.js

@ -3,7 +3,7 @@
import React from 'react'
import styled from 'styled-components'
import type { Account } from '@ledgerhq/live-common/lib/types'
import type { Account, Currency } from '@ledgerhq/live-common/lib/types'
import Chart from 'components/base/Chart'
import Bar from 'components/base/Bar'
@ -27,9 +27,9 @@ const AccountCard = ({
daysCount,
...props
}: {
counterValue: string,
counterValue: Currency,
account: Account,
onClick?: Function,
onClick?: () => void,
daysCount: number,
}) => (
<Wrapper onClick={onClick} {...props}>
@ -66,7 +66,7 @@ const AccountCard = ({
{isAvailable ? (
<FormattedVal
animateTicker
fiat={counterValue}
unit={counterValue.units[0]}
val={balanceEnd}
alwaysShowSign={false}
showCode
@ -96,8 +96,4 @@ const AccountCard = ({
</Wrapper>
)
AccountCard.defaultProps = {
onClick: undefined,
}
export default AccountCard

40
src/components/DashboardPage/index.js

@ -1,25 +1,19 @@
// @flow
import React, { PureComponent, Fragment } from 'react'
import { ipcRenderer } from 'electron'
import { compose } from 'redux'
import { translate } from 'react-i18next'
import { connect } from 'react-redux'
import { push } from 'react-router-redux'
import chunk from 'lodash/chunk'
import {
formatCurrencyUnit,
getFiatCurrencyByTicker,
} from '@ledgerhq/live-common/lib/helpers/currencies'
import type { Account } from '@ledgerhq/live-common/lib/types'
import type { Account, Currency } from '@ledgerhq/live-common/lib/types'
import type { T } from 'types/common'
import { colors } from 'styles/theme'
import { getVisibleAccounts } from 'reducers/accounts'
import { getCounterValueCode, localeSelector } from 'reducers/settings'
import { counterValueCurrencySelector, localeSelector } from 'reducers/settings'
import { updateOrderAccounts } from 'actions/accounts'
import { saveSettings } from 'actions/settings'
@ -37,7 +31,7 @@ import AccountsOrder from './AccountsOrder'
const mapStateToProps = state => ({
accounts: getVisibleAccounts(state),
counterValue: getCounterValueCode(state),
counterValue: counterValueCurrencySelector(state),
locale: localeSelector(state),
})
@ -51,8 +45,7 @@ type Props = {
t: T,
accounts: Account[],
push: Function,
counterValue: string,
locale: string,
counterValue: Currency,
}
type State = {
@ -87,30 +80,6 @@ class DashboardPage extends PureComponent<Props, State> {
}
}
handleCalculateBalance = data => {
const { counterValue, locale } = this.props
if (process.platform === 'darwin' && this._cacheBalance !== data.totalBalance) {
this._cacheBalance = data.totalBalance
// TODO abstract this out in a component
ipcRenderer.send('touch-bar-update', {
text: 'Total balance',
color: colors.wallet,
balance: {
counterValue: formatCurrencyUnit(
getFiatCurrencyByTicker(counterValue).units[0],
data.totalBalance,
{
showCode: true,
locale,
},
),
},
})
}
}
handleGreeting = () => {
const localTimeHour = new Date().getHours()
const afternoon_breakpoint = 12
@ -159,7 +128,6 @@ class DashboardPage extends PureComponent<Props, State> {
{totalAccounts > 0 && (
<Fragment>
<BalanceSummary
onCalculate={this.handleCalculateBalance}
counterValue={counterValue}
chartId="dashboard-chart"
chartColor={colors.wallet}

6
src/components/base/Chart/Tooltip.js

@ -3,7 +3,7 @@
import React, { Fragment } from 'react'
import styled from 'styled-components'
import type { Account } from '@ledgerhq/live-common/lib/types'
import type { Account, Currency } from '@ledgerhq/live-common/lib/types'
import FormattedVal from 'components/base/FormattedVal'
import Box from 'components/base/Box'
@ -26,10 +26,12 @@ const Tooltip = ({
item,
renderTooltip,
account,
counterValue,
}: {
item: Item,
renderTooltip?: Function,
account?: Account,
counterValue: Currency,
}) => (
<div style={{ position: 'relative' }}>
<div
@ -52,7 +54,7 @@ const Tooltip = ({
fontSize={5}
alwaysShowSign={false}
showCode
fiat="USD"
unit={counterValue.units[0]}
val={item.value}
/>
{account && (

9
src/components/base/Chart/handleMouseEvents.js

@ -5,6 +5,7 @@ import * as d3 from 'd3'
import { renderToString } from 'react-dom/server'
import { ThemeProvider } from 'styled-components'
import { Provider } from 'react-redux'
import { getFiatCurrencyByTicker } from '@ledgerhq/live-common/lib/helpers/currencies'
import createStore from 'renderer/createStore'
@ -89,9 +90,15 @@ export default function handleMouseEvents({
NODES.tooltip
.html(
renderToString(
// FIXME :o why is this not in React tree. maybe use a portal (native in React now)
<Provider store={createStore({})}>
<ThemeProvider theme={theme}>
<Tooltip account={account} renderTooltip={renderTooltip} item={d.ref} />
<Tooltip
account={account}
renderTooltip={renderTooltip}
item={d.ref}
counterValue={getFiatCurrencyByTicker('USD')}
/>
</ThemeProvider>
</Provider>,
),

6
src/components/base/FormattedVal/__tests__/FormattedVal.test.js

@ -35,11 +35,5 @@ describe('components', () => {
const tree = render(component)
expect(tree).toMatchSnapshot()
})
it('renders a fiat', () => {
const component = <FormattedVal fiat="USD" val={2000} />
const tree = render(component)
expect(tree).toMatchSnapshot()
})
})
})

9
src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap

@ -1,14 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components FormattedVal renders a fiat 1`] = `
<div
className="k45ou1-0 iqaJGf e345n3-0 eoitYS"
color="#66be54"
>
20.00
</div>
`;
exports[`components FormattedVal renders a formatted val 1`] = `
<div
className="k45ou1-0 iqaJGf e345n3-0 eoitYS"

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

@ -9,10 +9,7 @@ import isUndefined from 'lodash/isUndefined'
import type { Unit } from '@ledgerhq/live-common/lib/types'
import type { State } from 'reducers'
import {
formatCurrencyUnit,
findCurrencyByTicker,
} from '@ledgerhq/live-common/lib/helpers/currencies'
import { formatCurrencyUnit } from '@ledgerhq/live-common/lib/helpers/currencies'
import { marketIndicatorSelector, localeSelector } from 'reducers/settings'
@ -42,16 +39,15 @@ I.defaultProps = {
}
type OwnProps = {
unit?: Unit,
val: number,
alwaysShowSign?: boolean,
animateTicker?: boolean,
showCode?: boolean,
withIcon?: boolean,
color?: string,
animateTicker?: boolean,
disableRounding?: boolean,
fiat?: string,
isPercent?: boolean,
showCode?: boolean,
unit?: Unit,
val: number,
withIcon?: boolean,
}
const mapStateToProps = (state: State, _props: OwnProps) => ({
@ -64,13 +60,11 @@ type Props = OwnProps & {
locale: string,
}
let _logged
function FormattedVal(props: Props) {
const {
animateTicker,
disableRounding,
fiat,
unit,
isPercent,
alwaysShowSign,
showCode,
@ -80,7 +74,7 @@ function FormattedVal(props: Props) {
color,
...p
} = props
let { val, unit } = props
let { val } = props
if (isUndefined(val)) {
throw new Error('FormattedVal require a `val` prop. Received `undefined`')
@ -91,20 +85,11 @@ function FormattedVal(props: Props) {
let text = ''
if (isPercent) {
// FIXME move out the % feature of this component... totally unrelated to currency & annoying for flow type.
text = `${alwaysShowSign ? (isNegative ? '- ' : '+ ') : ''}${isNegative ? val * -1 : val} %`
} else {
if (fiat) {
if (!_logged) {
_logged = true
console.warn('FormattedVal: passing fiat prop is deprecated')
}
const cur = findCurrencyByTicker(fiat)
if (cur) {
;[unit] = cur.units
}
}
if (!unit) {
return ''
throw new Error('FormattedVal require a `unit` prop. Received `undefined`')
}
if (withIcon && isNegative) {

2
src/components/modals/AddAccount/03-step-import.js

@ -38,7 +38,7 @@ function StepImport(props: Props) {
color="warmGrey"
fontSize={6}
showCode
fiat={account.currency.ticker}
unit={account.currency.units[0]}
val={account.balance}
/>
</Box>

6
yarn.lock

@ -1464,9 +1464,9 @@
npm "^5.7.1"
prebuild-install "^2.2.2"
"@ledgerhq/live-common@2.11.0":
version "2.11.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.11.0.tgz#9b8af8b76aab4094ec2189538f8330711a3b91a3"
"@ledgerhq/live-common@2.12.0":
version "2.12.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.12.0.tgz#7c60cb3d7829a0f55b6763efff96c8f4937b05f2"
dependencies:
axios "^0.18.0"
invariant "^2.2.2"

Loading…
Cancel
Save