From a368cc8b7bab50c57b68c52485732a6481aef75b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Fri, 1 Jun 2018 16:54:53 +0200 Subject: [PATCH] last fixes for graph --- package.json | 2 +- src/components/BalanceSummary/index.js | 10 +++------- src/components/DashboardPage/AccountCard.js | 2 +- src/components/base/Chart/Tooltip.js | 10 +++++----- src/components/base/Chart/handleMouseEvents.js | 3 +-- src/components/base/Chart/index.js | 12 ++++-------- src/components/base/Chart/refreshDraw.js | 4 ++-- src/components/base/Chart/stories.js | 2 +- yarn.lock | 6 +++--- 9 files changed, 21 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 7502bfbf..3384d2fd 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@ledgerhq/hw-transport": "^4.12.0", "@ledgerhq/hw-transport-node-hid": "^4.12.0", "@ledgerhq/ledger-core": "1.4.1", - "@ledgerhq/live-common": "^2.20.0", + "@ledgerhq/live-common": "2.22.0", "axios": "^0.18.0", "babel-runtime": "^6.26.0", "bcryptjs": "^2.4.3", diff --git a/src/components/BalanceSummary/index.js b/src/components/BalanceSummary/index.js index 94f5d6d6..80080c44 100644 --- a/src/components/BalanceSummary/index.js +++ b/src/components/BalanceSummary/index.js @@ -1,7 +1,7 @@ // @flow import React, { Fragment } from 'react' -import { formatCurrencyUnit } from '@ledgerhq/live-common/lib/helpers/currencies' +import { formatShort } from '@ledgerhq/live-common/lib/helpers/currencies' import type { Currency, Account } from '@ledgerhq/live-common/lib/types' import Chart from 'components/base/Chart' @@ -54,17 +54,13 @@ const BalanceSummary = ({ - account - ? formatCurrencyUnit(account.unit, val) - : formatCurrencyUnit(counterValue.units[0], val) - } + renderTickY={val => formatShort(counterValue.units[0], val)} renderTooltip={ isAvailable && !account ? d => ( diff --git a/src/components/DashboardPage/AccountCard.js b/src/components/DashboardPage/AccountCard.js index 0805632f..4a6c8b9a 100644 --- a/src/components/DashboardPage/AccountCard.js +++ b/src/components/DashboardPage/AccountCard.js @@ -88,7 +88,7 @@ const AccountCard = ({ hideAxis isInteractive={false} id={`account-chart-${account.id}`} - account={account} + unit={account.unit} /> )} diff --git a/src/components/base/Chart/Tooltip.js b/src/components/base/Chart/Tooltip.js index 2ccbdbec..900afa8e 100644 --- a/src/components/base/Chart/Tooltip.js +++ b/src/components/base/Chart/Tooltip.js @@ -3,7 +3,7 @@ import React, { Fragment } from 'react' import styled from 'styled-components' -import type { Account, Currency } from '@ledgerhq/live-common/lib/types' +import type { Unit, Currency } from '@ledgerhq/live-common/lib/types' import FormattedVal from 'components/base/FormattedVal' import Box from 'components/base/Box' @@ -25,12 +25,12 @@ const Container = styled(Box).attrs({ const Tooltip = ({ item, renderTooltip, - account, + unit, counterValue, }: { item: Item, renderTooltip?: Function, - account?: Account, + unit?: ?Unit, counterValue: Currency, }) => (
@@ -57,13 +57,13 @@ const Tooltip = ({ unit={counterValue.units[0]} val={item.value} /> - {account && ( + {unit && ( )} diff --git a/src/components/base/Chart/handleMouseEvents.js b/src/components/base/Chart/handleMouseEvents.js index bf5a918a..77096ed3 100644 --- a/src/components/base/Chart/handleMouseEvents.js +++ b/src/components/base/Chart/handleMouseEvents.js @@ -30,7 +30,6 @@ export default function handleMouseEvents({ renderTooltip?: Function, }) { const { MARGINS, HEIGHT, WIDTH, NODES, DATA, x, y } = ctx - const { account } = props const bisectDate = d3.bisector(d => d.parsedDate).left @@ -94,7 +93,7 @@ export default function handleMouseEvents({ mixed, // eslint-disable-line react/no-unused-prop-types + renderTickY: (t: number) => string | number, // eslint-disable-line react/no-unused-prop-types } class Chart extends PureComponent { @@ -71,8 +68,7 @@ class Chart extends PureComponent { id: 'chart', isInteractive: true, tickXScale: 'month', - renderTickY: (t: number, account: Account): mixed => - account ? formatShort(account.unit, t) : '', + renderTickY: (t: *) => t, } componentDidMount() { diff --git a/src/components/base/Chart/refreshDraw.js b/src/components/base/Chart/refreshDraw.js index 193b53ba..fa3d2e31 100644 --- a/src/components/base/Chart/refreshDraw.js +++ b/src/components/base/Chart/refreshDraw.js @@ -30,7 +30,7 @@ function getRenderTickX(selectedTime) { export default function refreshDraw({ ctx, props }: { ctx: CTX, props: Props }) { const { NODES, WIDTH, HEIGHT, MARGINS, COLORS, INVALIDATED, DATA, x, y } = ctx - const { hideAxis, isInteractive, tickXScale, account, renderTickY } = props + const { hideAxis, isInteractive, tickXScale, renderTickY } = props const nbTicksX = getTickXCount(tickXScale) const renderTickX = getRenderTickX(tickXScale) @@ -87,7 +87,7 @@ export default function refreshDraw({ ctx, props }: { ctx: CTX, props: Props }) d3 .axisLeft(y) .ticks(3) - .tickFormat(val => renderTickY(val, account)), + .tickFormat(renderTickY), ) NODES.axisBot.call( d3 diff --git a/src/components/base/Chart/stories.js b/src/components/base/Chart/stories.js index e1f4e704..a88182bb 100644 --- a/src/components/base/Chart/stories.js +++ b/src/components/base/Chart/stories.js @@ -62,7 +62,7 @@ class Wrapper extends Component { color={color('color', '#5f8ced')} data={data.slice(start, stop)} height={number('height', 300)} - account={fakeAccount} + unit={fakeAccount.unit} /> ) diff --git a/yarn.lock b/yarn.lock index b0176c5b..799f056e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1495,9 +1495,9 @@ npm "^5.7.1" prebuild-install "^2.2.2" -"@ledgerhq/live-common@^2.20.0": - version "2.20.0" - resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.20.0.tgz#e6ec2a3a01a224edac82b093e2f1564312a30d0d" +"@ledgerhq/live-common@2.22.0": + version "2.22.0" + resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.22.0.tgz#f958ee28cc09af40a6bed484e73204f01b54d709" dependencies: axios "^0.18.0" invariant "^2.2.2"