diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 022217f5..00000000 --- a/jest.config.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - globals: { - __DEV__: true, - __TEST__: true, - }, -} diff --git a/package.json b/package.json index f085da15..4a030d08 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "history": "^4.7.2", "i18next": "^10.5.0", "i18next-node-fs-backend": "^1.0.0", - "ledger-test-library": "KhalilBellakrid/ledger-test-library-nodejs", + "ledger-test-library": "KhalilBellakrid/ledger-test-library-nodejs#7d37482", "lodash": "^4.17.5", "moment": "^2.20.1", "object-path": "^0.11.4", @@ -118,7 +118,7 @@ "chance": "^1.0.13", "concurrently": "^3.5.1", "dotenv": "^5.0.1", - "electron": "1.8.2", + "electron": "1.8.3", "electron-builder": "^20.2.0", "electron-devtools-installer": "^2.2.3", "electron-rebuild": "^1.7.3", diff --git a/src/actions/counterValues.js b/src/actions/counterValues.js index 3d604a82..f0a596a7 100644 --- a/src/actions/counterValues.js +++ b/src/actions/counterValues.js @@ -8,21 +8,22 @@ import get from 'lodash/get' import db from 'helpers/db' -type InitCounterValues = () => { type: string, payload: Object } +export type InitCounterValues = () => { type: string, payload: Object } export const initCounterValues: InitCounterValues = () => ({ type: 'UPDATE_COUNTER_VALUES', payload: db.get('counterValues'), }) -type UpdateCounterValues = Object => { type: string, payload: Object } +export type UpdateCounterValues = Object => { type: string, payload: Object } export const updateCounterValues: UpdateCounterValues = payload => ({ type: 'DB:UPDATE_COUNTER_VALUES', payload, }) -type FetchCounterValues = (?number) => (Dispatch<*>, Function) => Promise +export type FetchCounterValues = (?number) => (Dispatch<*>, Function) => Promise export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, getState) => { - const { accounts, counterValues } = getState() + const { accounts, counterValues, settings } = getState() + const { counterValue } = settings let coinTypes = [] @@ -36,7 +37,7 @@ export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, get const fetchCounterValuesByCoinType = coinType => { const { code } = getDefaultUnitByCoinType(coinType) - const todayCounterValues = get(counterValues, `${code}-USD.${today}`, null) + const todayCounterValues = get(counterValues, `${code}-${counterValue}.${today}`, null) if (todayCounterValues !== null) { return null @@ -44,10 +45,10 @@ export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, get return axios .get( - `https://min-api.cryptocompare.com/data/histoday?&extraParams=ledger-test&fsym=${code}&tsym=USD&allData=1`, + `https://min-api.cryptocompare.com/data/histoday?&extraParams=ledger-test&fsym=${code}&tsym=${counterValue}&allData=1`, ) .then(({ data }) => ({ - symbol: `${code}-USD`, + symbol: `${code}-${counterValue}`, values: data.Data.reduce((result, d) => { const date = moment(d.time * 1000).format('YYYY-MM-DD') result[date] = d.close diff --git a/src/components/AccountPage/index.js b/src/components/AccountPage/index.js index 5225575a..4375d8dd 100644 --- a/src/components/AccountPage/index.js +++ b/src/components/AccountPage/index.js @@ -8,10 +8,10 @@ import { Redirect } from 'react-router' import { MODAL_SEND, MODAL_RECEIVE, MODAL_SETTINGS_ACCOUNT } from 'constants' -import type { MapStateToProps } from 'react-redux' import type { T, Account } from 'types/common' import { getAccountById } from 'reducers/accounts' +import { getCounterValue } from 'reducers/settings' import { openModal } from 'reducers/modals' import IconControls from 'icons/Controls' @@ -32,8 +32,9 @@ import TransactionsList from 'components/TransactionsList' import AccountHeader from './AccountHeader' -const mapStateToProps: MapStateToProps<*, *, *> = (state, props) => ({ +const mapStateToProps = (state, props) => ({ account: getAccountById(state, props.match.params.id), + counterValue: getCounterValue(state), }) const mapDispatchToProps = { @@ -41,6 +42,7 @@ const mapDispatchToProps = { } type Props = { + counterValue: string, t: T, account?: Account, openModal: Function, @@ -64,7 +66,7 @@ class AccountPage extends PureComponent { }) render() { - const { account, openModal, t } = this.props + const { account, openModal, t, counterValue } = this.props const { selectedTime, daysCount } = this.state // Don't even throw if we jumped in wrong account route @@ -101,6 +103,7 @@ class AccountPage extends PureComponent { { { /> - + {t('dashboard:totalBalance')} moment(t).format(format) +} + type Props = { + counterValue: string, chartColor: string, chartId: string, accounts: Accounts, @@ -23,6 +48,7 @@ type Props = { } const BalanceSummary = ({ + counterValue, chartColor, chartId, accounts, @@ -30,10 +56,11 @@ const BalanceSummary = ({ daysCount, renderHeader, }: Props) => { - const unit = getFiatUnit('USD') + const unit = getFiatUnit(counterValue) return ( ( @@ -66,8 +93,10 @@ const BalanceSummary = ({ showCode: true, }) } - renderTickX={t => moment(t).format('MMM. D')} + renderTickX={renderTickX(selectedTime)} renderTickY={t => formatShort(unit, t)} + tickCountX={getTickCountX(selectedTime)} + tickCountY={4} /> diff --git a/src/components/CalculateBalance.js b/src/components/CalculateBalance.js index 669d4789..ba24e52d 100644 --- a/src/components/CalculateBalance.js +++ b/src/components/CalculateBalance.js @@ -7,16 +7,15 @@ import find from 'lodash/find' import first from 'lodash/first' import last from 'lodash/last' -import type { MapStateToProps } from 'react-redux' import type { Accounts } from 'types/common' import { getBalanceHistoryForAccounts } from 'helpers/balance' -const mapStateToProps: MapStateToProps<*, *, *> = state => ({ +const mapStateToProps = state => ({ counterValues: state.counterValues, }) -function calculateBalance(props) { +function calculateBalance(props: Object) { const interval = { start: moment() .subtract(props.daysCount, 'days') @@ -25,7 +24,7 @@ function calculateBalance(props) { } const allBalances = getBalanceHistoryForAccounts({ - fiat: 'USD', + counterValue: props.counterValue, accounts: props.accounts, counterValues: props.counterValues, interval, diff --git a/src/components/DashboardPage/AccountCard.js b/src/components/DashboardPage/AccountCard.js index b55fe56e..fcb9bf89 100644 --- a/src/components/DashboardPage/AccountCard.js +++ b/src/components/DashboardPage/AccountCard.js @@ -12,10 +12,12 @@ import CalculateBalance from 'components/CalculateBalance' import FormattedVal from 'components/base/FormattedVal' const AccountCard = ({ + counterValue, account, onClick, daysCount, }: { + counterValue: string, account: Account, onClick: Function, daysCount: number, @@ -57,6 +59,7 @@ const AccountCard = ({ ( @@ -64,7 +67,7 @@ const AccountCard = ({ (p.isActive ? 1 : 0)}; ` -const mapStateToProps: MapStateToProps<*, *, *> = state => ({ +const mapStateToProps = state => ({ orderAccounts: getOrderAccounts(state), }) diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index 81f1c234..96018305 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -10,10 +10,10 @@ import chunk from 'lodash/chunk' import get from 'lodash/get' import sortBy from 'lodash/sortBy' -import type { MapStateToProps } from 'react-redux' import type { Account, Accounts, T } from 'types/common' import { getVisibleAccounts } from 'reducers/accounts' +import { getCounterValue } from 'reducers/settings' import { updateOrderAccounts } from 'actions/accounts' import { saveSettings } from 'actions/settings' @@ -28,8 +28,9 @@ import TransactionsList from 'components/TransactionsList' import AccountCard from './AccountCard' import AccountsOrder from './AccountsOrder' -const mapStateToProps: MapStateToProps<*, *, *> = state => ({ +const mapStateToProps = state => ({ accounts: getVisibleAccounts(state), + counterValue: getCounterValue(state), }) const mapDispatchToProps = { @@ -42,6 +43,7 @@ type Props = { t: T, accounts: Accounts, push: Function, + counterValue: string, } type State = { @@ -107,7 +109,7 @@ class DashboardPage extends PureComponent { }) render() { - const { push, accounts, t } = this.props + const { push, accounts, t, counterValue } = this.props const { accountsChunk, allTransactions, selectedTime, daysCount } = this.state const totalAccounts = accounts.length @@ -132,6 +134,7 @@ class DashboardPage extends PureComponent { {totalAccounts > 0 && ( { renderHeader={({ totalBalance, selectedTime, sinceBalance, refBalance }) => ( { /> ) : ( = state => ({ +const mapStateToProps = state => ({ accounts: getAccounts(state), settings: state.settings, isLocked: isLocked(state), }) -const mapDispatchToProps = { +const mapDispatchToProps: Object = { fetchAccounts, unlock, } diff --git a/src/components/ReceiveBox.js b/src/components/ReceiveBox.js index 98435405..8d91b07b 100644 --- a/src/components/ReceiveBox.js +++ b/src/components/ReceiveBox.js @@ -5,7 +5,6 @@ import { connect } from 'react-redux' import styled from 'styled-components' import { ipcRenderer } from 'electron' -import type { MapStateToProps } from 'react-redux' import type { Account, Device } from 'types/common' import { getCurrentDevice } from 'reducers/devices' @@ -48,7 +47,7 @@ const Action = styled(Box).attrs({ } ` -const mapStateToProps: MapStateToProps<*, *, *> = state => ({ +const mapStateToProps = state => ({ currentDevice: getCurrentDevice(state), }) diff --git a/src/components/SelectAccount/index.js b/src/components/SelectAccount/index.js index 37d4df94..f6e0baac 100644 --- a/src/components/SelectAccount/index.js +++ b/src/components/SelectAccount/index.js @@ -6,32 +6,28 @@ import { connect } from 'react-redux' import { translate } from 'react-i18next' import noop from 'lodash/noop' -import type { MapStateToProps } from 'react-redux' import type { T, Accounts, Account } from 'types/common' -import { formatBTC } from 'helpers/format' - import { getVisibleAccounts } from 'reducers/accounts' import Select from 'components/base/Select' +import FormattedVal from 'components/base/FormattedVal' import Box from 'components/base/Box' import Text from 'components/base/Text' -const mapStateToProps: MapStateToProps<*, *, *> = state => ({ +const mapStateToProps = state => ({ accounts: getVisibleAccounts(state), }) -const renderItem = item => ( +const renderItem = a => ( - {item.name} + {a.name} - - {formatBTC(item.balance)} - + ) diff --git a/src/components/SettingsPage/Money.js b/src/components/SettingsPage/Money.js new file mode 100644 index 00000000..9028d1c6 --- /dev/null +++ b/src/components/SettingsPage/Money.js @@ -0,0 +1,88 @@ +// @flow + +import React, { PureComponent } from 'react' +import { getFiatUnit } from '@ledgerhq/currencies' + +import type { SettingsMoney, T } from 'types/common' + +import Box, { Card } from 'components/base/Box' +import Button from 'components/base/Button' +import Label from 'components/base/Label' +import Select from 'components/base/Select' + +const counterValues = ['USD', 'EUR', 'JPY', 'GBP'].sort().map(c => { + const { name } = getFiatUnit(c) + return { + key: c, + name, + } +}) + +type InputValue = SettingsMoney + +type Props = { + t: T, + settings: SettingsMoney, + onSaveSettings: Function, +} + +type State = { + inputValue: InputValue, +} + +class TabProfile extends PureComponent { + state = { + inputValue: { + counterValue: this.props.settings.counterValue, + }, + } + + handleChangeInput = (key: $Keys) => (value: $Values) => + this.setState(prev => ({ + inputValue: { + ...prev.inputValue, + [key]: value, + }, + })) + + handleSubmit = (e: SyntheticEvent) => { + e.preventDefault() + + const { onSaveSettings } = this.props + const { inputValue } = this.state + + onSaveSettings({ + ...inputValue, + }) + } + + render() { + const { t } = this.props + const { inputValue } = this.state + + const currentCounterValues = counterValues.find(l => l.key === inputValue.counterValue) + + return ( +
+ + + +