diff --git a/package.json b/package.json index 4f7ad6b8..7502bfbf 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.19.0", + "@ledgerhq/live-common": "^2.20.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 be091a8f..e3f9e693 100644 --- a/src/components/BalanceSummary/index.js +++ b/src/components/BalanceSummary/index.js @@ -1,6 +1,7 @@ // @flow import React, { Fragment } from 'react' +import { formatCurrencyUnit } from '@ledgerhq/live-common/lib/helpers/currencies' import type { Currency, Account } from '@ledgerhq/live-common/lib/types' import Chart from 'components/base/Chart' @@ -59,6 +60,9 @@ const BalanceSummary = ({ height={250} currency={counterValue} tickXScale={selectedTime} + renderTickY={(val, account) => + account ? formatCurrencyUnit(account.unit, val) : val + } renderTooltip={ isAvailable && !account ? d => ( diff --git a/src/components/base/Chart/index.js b/src/components/base/Chart/index.js index 21cba1b6..e94807b8 100644 --- a/src/components/base/Chart/index.js +++ b/src/components/base/Chart/index.js @@ -36,6 +36,7 @@ import React, { PureComponent } from 'react' import * as d3 from 'd3' import noop from 'lodash/noop' +import { formatShort } from '@ledgerhq/live-common/lib/helpers/currencies' import type { Account } from '@ledgerhq/live-common/lib/types' @@ -58,6 +59,7 @@ export type Props = { dateFormat?: string, // eslint-disable-line react/no-unused-prop-types isInteractive?: boolean, // eslint-disable-line react/no-unused-prop-types renderTooltip?: Function, // eslint-disable-line react/no-unused-prop-types + renderTickY?: (t: number, account: Account) => mixed, // eslint-disable-line react/no-unused-prop-types } class Chart extends PureComponent { @@ -69,6 +71,8 @@ class Chart extends PureComponent { id: 'chart', isInteractive: true, tickXScale: 'month', + renderTickY: (t: number, account: Account): mixed => + account ? formatShort(account.unit, t) : t, } componentDidMount() { diff --git a/src/components/base/Chart/refreshDraw.js b/src/components/base/Chart/refreshDraw.js index eac16978..ca57b2fd 100644 --- a/src/components/base/Chart/refreshDraw.js +++ b/src/components/base/Chart/refreshDraw.js @@ -2,7 +2,6 @@ import * as d3 from 'd3' import moment from 'moment' -import { formatShort } from '@ledgerhq/live-common/lib/helpers/currencies' import { colors as themeColors } from 'styles/theme' @@ -31,11 +30,10 @@ 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 } = props + const { hideAxis, isInteractive, tickXScale, account, renderTickY } = props const nbTicksX = getTickXCount(tickXScale) const renderTickX = getRenderTickX(tickXScale) - const renderTickY = t => (account ? formatShort(account.unit, t) : t) const area = d3 .area() @@ -89,7 +87,7 @@ export default function refreshDraw({ ctx, props }: { ctx: CTX, props: Props }) d3 .axisLeft(y) .ticks(3) - .tickFormat(val => (renderTickY ? renderTickY(val) : val)), + .tickFormat(val => (renderTickY && account ? renderTickY(val, account) : val)), ) NODES.axisBot.call( d3 diff --git a/yarn.lock b/yarn.lock index 686fe014..b0176c5b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1495,9 +1495,9 @@ npm "^5.7.1" prebuild-install "^2.2.2" -"@ledgerhq/live-common@2.19.0": - version "2.19.0" - resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.19.0.tgz#bc0e12cbf1a9742a5c6497513d0269fdc6a90b95" +"@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" dependencies: axios "^0.18.0" invariant "^2.2.2"