diff --git a/package.json b/package.json index 6b33ac26..1ef4d994 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.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", diff --git a/src/components/AccountPage/index.js b/src/components/AccountPage/index.js index cdda36cb..f972c9f7 100644 --- a/src/components/AccountPage/index.js +++ b/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 { 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 { chartId={`account-chart-${account.id}`} counterValue={counterValue} daysCount={daysCount} - onCalculate={this.handleCalculateBalance} selectedTime={selectedTime} renderHeader={({ totalBalance, sinceBalance, refBalance }) => ( @@ -173,7 +134,7 @@ class AccountPage extends PureComponent { animateTicker alwaysShowSign={false} color="warmGrey" - fiat={counterValue} + unit={counterValue.units[0]} fontSize={6} showCode val={totalBalance} diff --git a/src/components/BalanceSummary/BalanceInfos.js b/src/components/BalanceSummary/BalanceInfos.js index 99463c2a..bcf29524 100644 --- a/src/components/BalanceSummary/BalanceInfos.js +++ b/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) { {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 ( - + {t('dashboard:totalBalance')} { - const currency = getFiatCurrencyByTicker(counterValue) const account = accounts.length === 1 ? accounts[0] : undefined return ( - + {({ isAvailable, balanceHistory, balanceStart, balanceEnd }) => !isAvailable ? null : ( @@ -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} /> diff --git a/src/components/CounterValue/index.js b/src/components/CounterValue/index.js index 1874ee01..16f4b08b 100644 --- a/src/components/CounterValue/index.js +++ b/src/components/CounterValue/index.js @@ -55,7 +55,7 @@ class CounterValue extends PureComponent { return ( void, daysCount: number, }) => ( @@ -66,7 +66,7 @@ const AccountCard = ({ {isAvailable ? ( ) -AccountCard.defaultProps = { - onClick: undefined, -} - export default AccountCard diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index aec0c8a3..d2894086 100644 --- a/src/components/DashboardPage/index.js +++ b/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 { } } - 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 { {totalAccounts > 0 && ( (
{account && ( diff --git a/src/components/base/Chart/handleMouseEvents.js b/src/components/base/Chart/handleMouseEvents.js index 9809b066..bf5a918a 100644 --- a/src/components/base/Chart/handleMouseEvents.js +++ b/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) - + , ), diff --git a/src/components/base/FormattedVal/__tests__/FormattedVal.test.js b/src/components/base/FormattedVal/__tests__/FormattedVal.test.js index a3fbf606..7748a7aa 100644 --- a/src/components/base/FormattedVal/__tests__/FormattedVal.test.js +++ b/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 = - const tree = render(component) - expect(tree).toMatchSnapshot() - }) }) }) diff --git a/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap b/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap index 66a34cff..45d28048 100644 --- a/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap +++ b/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`] = ` -
- 20.00 -
-`; - exports[`components FormattedVal renders a formatted val 1`] = `
({ @@ -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) { diff --git a/src/components/modals/AddAccount/03-step-import.js b/src/components/modals/AddAccount/03-step-import.js index 05482527..8821aaed 100644 --- a/src/components/modals/AddAccount/03-step-import.js +++ b/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} /> diff --git a/yarn.lock b/yarn.lock index f25bb9d9..4b330f02 100644 --- a/yarn.lock +++ b/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"