diff --git a/src/components/AccountPage.js b/src/components/AccountPage.js index 6a2356cd..fdeddde8 100644 --- a/src/components/AccountPage.js +++ b/src/components/AccountPage.js @@ -39,6 +39,13 @@ const mapDispatchToProps = { openModal, } +function enrichTransactionsWithAccount(transactions, account) { + return transactions.map(t => ({ + ...t, + account, + })) +} + class AccountPage extends PureComponent { render() { const { account, accountData, openModal, t } = this.props @@ -100,7 +107,9 @@ class AccountPage extends PureComponent { - + )} diff --git a/src/components/DashboardPage/AccountCard.js b/src/components/DashboardPage/AccountCard.js index db6662f5..c5089370 100644 --- a/src/components/DashboardPage/AccountCard.js +++ b/src/components/DashboardPage/AccountCard.js @@ -27,7 +27,7 @@ const AccountCard = ({ - {account.type} + {account.unit.code} {account.name} @@ -40,7 +40,7 @@ const AccountCard = ({ diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index 2bd671a7..97f9912b 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -96,11 +96,7 @@ const getAllTransactions = accounts => { ...result, ...transactions.map(t => ({ ...t, - account: { - id: account.id, - name: account.name, - type: account.type, - }, + account, })), ] diff --git a/src/components/SelectAccount/stories.js b/src/components/SelectAccount/stories.js index d9dc4bbb..78bcb3bc 100644 --- a/src/components/SelectAccount/stories.js +++ b/src/components/SelectAccount/stories.js @@ -3,6 +3,7 @@ import React, { PureComponent } from 'react' import { storiesOf } from '@storybook/react' import Chance from 'chance' +import { getCurrencyByCoinType, getDefaultUnitByCoinType } from '@ledgerhq/currencies' import { SelectAccount } from 'components/SelectAccount' @@ -12,7 +13,9 @@ const stories = storiesOf('SelectAccount', module) const accounts = [...Array(20)].map(() => ({ id: chance.string(), name: chance.name(), - type: 'BTC', + coinType: 0, + currency: getCurrencyByCoinType(0), + unit: getDefaultUnitByCoinType(0), data: { address: chance.string(), balance: chance.floating({ min: 0, max: 20 }), diff --git a/src/components/SideBar/index.js b/src/components/SideBar/index.js index d1480188..05f7456f 100644 --- a/src/components/SideBar/index.js +++ b/src/components/SideBar/index.js @@ -106,7 +106,7 @@ class SideBar extends PureComponent { diff --git a/src/components/TransactionsList/index.js b/src/components/TransactionsList/index.js index 9b1dafd3..665d8851 100644 --- a/src/components/TransactionsList/index.js +++ b/src/components/TransactionsList/index.js @@ -121,7 +121,13 @@ const Transaction = ({ - + ) diff --git a/src/components/base/FormattedVal.js b/src/components/base/FormattedVal.js index ed428d00..13b16b63 100644 --- a/src/components/base/FormattedVal.js +++ b/src/components/base/FormattedVal.js @@ -4,6 +4,7 @@ import React from 'react' import styled from 'styled-components' import { formatCurrencyUnit } from '@ledgerhq/currencies' +import type { Unit } from '@ledgerhq/currencies' import Text from 'components/base/Text' @@ -12,31 +13,16 @@ const T = styled(Text).attrs({ color: p => (p.isNegative ? p.theme.colors.grenade : p.theme.colors.green), })`` -const currencies = { - BTC: { - name: 'bitcoin', - code: 'BTC', - symbol: 'b', - magnitude: 8, - }, - USD: { - name: 'dollar', - code: 'USD', - symbol: '$', - magnitude: 0, - }, -} - type Props = { val: number, isPercent?: boolean, - currency?: any, + unit?: Unit | null, alwaysShowSign?: boolean, showCode?: boolean, } function FormattedVal(props: Props) { - const { val, isPercent, currency, alwaysShowSign, showCode, ...p } = props + const { val, isPercent, unit, alwaysShowSign, showCode, ...p } = props const isNegative = val < 0 @@ -45,11 +31,10 @@ function FormattedVal(props: Props) { if (isPercent) { text = `${alwaysShowSign ? (isNegative ? '- ' : '+ ') : ''}${val} %` } else { - const curr = currency ? currencies[currency.toUpperCase()] : null - if (!curr) { - return `[invalid currency ${currency || '(null)'}]` + if (!unit) { + return '' } - text = formatCurrencyUnit(curr, val, { + text = formatCurrencyUnit(unit, val, { alwaysShowSign, showCode, }) @@ -63,7 +48,7 @@ function FormattedVal(props: Props) { } FormattedVal.defaultProps = { - currency: null, + unit: null, isPercent: false, alwaysShowSign: false, showCode: false, diff --git a/src/components/modals/AddAccount/index.js b/src/components/modals/AddAccount/index.js index c8e1745b..242e8d13 100644 --- a/src/components/modals/AddAccount/index.js +++ b/src/components/modals/AddAccount/index.js @@ -6,6 +6,9 @@ import { compose } from 'redux' import { translate } from 'react-i18next' import { ipcRenderer } from 'electron' import differenceBy from 'lodash/differenceBy' +import { listCurrencies, getDefaultUnitByCoinType } from '@ledgerhq/currencies' + +import type { Currency } from '@ledgerhq/currencies' import { MODAL_ADD_ACCOUNT } from 'constants' @@ -30,25 +33,24 @@ import CreateAccount from './CreateAccount' import ImportAccounts from './ImportAccounts' import RestoreAccounts from './RestoreAccounts' -const currencies = [ - { - key: 'btc', - name: 'Bitcoin', - }, -] +const currencies = listCurrencies().map(currency => ({ + key: currency.coinType, + name: currency.name, + data: currency, +})) const Steps = { - chooseWallet: (props: Object) => ( + chooseCurrency: (props: Object) => (