diff --git a/.eslintrc b/.eslintrc index 9e0c6786..c93f6044 100644 --- a/.eslintrc +++ b/.eslintrc @@ -16,6 +16,7 @@ }, "rules": { "camelcase": 0, + "global-require": 0, "import/no-extraneous-dependencies": 0, "import/no-named-as-default": 0, "import/prefer-default-export": 0, @@ -28,8 +29,8 @@ "no-return-assign": 0, "no-shadow": 0, "no-underscore-dangle": 0, + "no-use-before-define": 0, "no-void": 0, - "global-require": 0, "react/forbid-prop-types": 0, "react/jsx-curly-brace-presence": 0, "react/jsx-filename-extension": 0, diff --git a/src/actions/accounts.js b/src/actions/accounts.js index 93da42ca..af67eb97 100644 --- a/src/actions/accounts.js +++ b/src/actions/accounts.js @@ -1,8 +1,9 @@ // @flow -import db from 'helpers/db' import sortBy from 'lodash/sortBy' +import db from 'helpers/db' + import type { Dispatch } from 'redux' import type { Account } from 'types/common' @@ -13,7 +14,7 @@ function sortAccounts(accounts, orderAccounts) { const accountsSorted = sortBy(accounts, a => { if (order === 'balance') { - return a.data.balance + return a.balance } return a[order] diff --git a/src/components/AccountPage.js b/src/components/AccountPage.js index fdeddde8..549269b0 100644 --- a/src/components/AccountPage.js +++ b/src/components/AccountPage.js @@ -1,6 +1,6 @@ // @flow -import React, { PureComponent, Fragment } from 'react' +import React, { PureComponent } from 'react' import { compose } from 'redux' import { connect } from 'react-redux' import { translate } from 'react-i18next' @@ -9,11 +9,11 @@ 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, AccountData } from 'types/common' +import type { T, Account } from 'types/common' import { formatBTC } from 'helpers/format' -import { getAccountById, getAccountData } from 'reducers/accounts' +import { getAccountById } from 'reducers/accounts' import { openModal } from 'reducers/modals' import Box, { Card } from 'components/base/Box' @@ -26,29 +26,20 @@ import TransactionsList from 'components/TransactionsList' type Props = { t: T, account: Account, - accountData: AccountData, openModal: Function, } const mapStateToProps: MapStateToProps<*, *, *> = (state, props) => ({ account: getAccountById(state, props.match.params.id), - accountData: getAccountData(state, props.match.params.id), }) 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 + const { account, openModal, t } = this.props // Don't even throw if we jumped in wrong account route if (!account) { @@ -86,33 +77,27 @@ class AccountPage extends PureComponent { /> - {accountData && ( - - - - - {formatBTC(accountData.balance)} - - + + + + {formatBTC(account.balance)} + + - - - - - - - - + + + - - )} + + + + + ) } diff --git a/src/components/DashboardPage/AccountCard.js b/src/components/DashboardPage/AccountCard.js index a133c245..01d33c6e 100644 --- a/src/components/DashboardPage/AccountCard.js +++ b/src/components/DashboardPage/AccountCard.js @@ -37,15 +37,13 @@ const AccountCard = ({ - {account.data && ( - - )} + const getAllTransactions = accounts => { const allTransactions = accounts.reduce((result, account) => { - const transactions = get(account, 'data.transactions', []) + const transactions = get(account, 'transactions', []) result = [ ...result, @@ -103,7 +103,7 @@ const getAllTransactions = accounts => { return result }, []) - return sortBy(allTransactions, t => t.received_at) + return sortBy(allTransactions, t => t.receivedAt) .reverse() .slice(0, ALL_TRANSACTIONS_LIMIT) } diff --git a/src/components/SelectAccount/index.js b/src/components/SelectAccount/index.js index 43835586..a414a601 100644 --- a/src/components/SelectAccount/index.js +++ b/src/components/SelectAccount/index.js @@ -7,7 +7,7 @@ import { translate } from 'react-i18next' import noop from 'lodash/noop' import type { MapStateToProps } from 'react-redux' -import type { T, Account } from 'types/common' +import type { T, Accounts, Account } from 'types/common' import { formatBTC } from 'helpers/format' @@ -30,14 +30,14 @@ const renderItem = item => ( - {formatBTC(item.data.balance)} + {formatBTC(item.balance)} ) type Props = { - accounts: Array, + accounts: Accounts, onChange?: () => Account | void, value?: Account | null, t: T, diff --git a/src/components/SelectAccount/stories.js b/src/components/SelectAccount/stories.js index 115f3b52..f7bf5d2f 100644 --- a/src/components/SelectAccount/stories.js +++ b/src/components/SelectAccount/stories.js @@ -12,17 +12,16 @@ const stories = storiesOf('Components/SelectAccount', module) const accounts = [...Array(20)].map(() => ({ id: chance.string(), - name: chance.name(), + address: chance.string(), + addresses: [], + balance: chance.floating({ min: 0, max: 20 }), coinType: 0, currency: getCurrencyByCoinType(0), + index: chance.integer({ min: 0, max: 20 }), + name: chance.name(), + path: '', + transactions: [], unit: getDefaultUnitByCoinType(0), - data: { - address: chance.string(), - balance: chance.floating({ min: 0, max: 20 }), - currentIndex: chance.integer({ min: 0, max: 20 }), - path: '', - transactions: [], - }, })) type State = { diff --git a/src/components/SideBar/index.js b/src/components/SideBar/index.js index f8924170..811983cf 100644 --- a/src/components/SideBar/index.js +++ b/src/components/SideBar/index.js @@ -110,7 +110,7 @@ class SideBar extends PureComponent { color="warmGrey" unit={account.unit} showCode - val={account.data ? account.data.balance : 0} + val={account.balance || 0} /> } iconActiveColor={account.currency.color} diff --git a/src/components/TransactionsList/index.js b/src/components/TransactionsList/index.js index 45b529ad..4736ca7d 100644 --- a/src/components/TransactionsList/index.js +++ b/src/components/TransactionsList/index.js @@ -73,11 +73,13 @@ const Cell = styled(Box).attrs({ const Transaction = ({ onAccountClick, tx, + withAccounts, }: { onAccountClick?: Function, tx: TransactionType, + withAccounts?: boolean, }) => { - const time = moment(tx.received_at) + const time = moment(tx.receivedAt) const Icon = getIconByCoinType(get(tx, 'account.currency.coinType')) return ( @@ -87,22 +89,23 @@ const Transaction = ({ {time.format('HH:mm')} - {tx.account && ( - onAccountClick && onAccountClick(tx.account)} - > - - {Icon && } - - - {tx.account.name} - - - )} + {withAccounts && + tx.account && ( + onAccountClick && onAccountClick(tx.account)} + > + + {Icon && } + + + {tx.account.name} + + + )} 0 ? 'From' : 'To'} - {tx.balance > 0 ? get(tx, 'inputs.0.address') : get(tx, 'outputs.0.address')} + {tx.address} @@ -135,6 +138,7 @@ const Transaction = ({ Transaction.defaultProps = { onAccountClick: noop, + withAccounts: false, } type Props = { @@ -181,6 +185,7 @@ class TransactionsList extends Component { {transactions.map(t => ( diff --git a/src/components/TransactionsList/stories.js b/src/components/TransactionsList/stories.js index 73c73eee..9ace0e99 100644 --- a/src/components/TransactionsList/stories.js +++ b/src/components/TransactionsList/stories.js @@ -9,14 +9,16 @@ const stories = storiesOf('Components/TransactionsList', module) const transactions = [ { + address: '5c6ea1716520c7d6e038d36a3223faced3c', hash: '5c6ea1716520c7d6e038d36a3223faced3c4b8f7ffb69d9fb5bd527d562fdb62', balance: 130000000, - received_at: '2018-01-09T16:03:52Z', + receivedAt: '2018-01-09T16:03:52Z', }, { + address: '27416a48caab90fab053b507b8b6b9d4', hash: '27416a48caab90fab053b507b8b6b9d48fba75421d3bfdbae4b85f64024bc9c4', balance: 65000000, - received_at: '2018-01-09T16:02:40Z', + receivedAt: '2018-01-09T16:02:40Z', }, ] diff --git a/src/components/modals/AddAccount/index.js b/src/components/modals/AddAccount/index.js index 242e8d13..4e99f363 100644 --- a/src/components/modals/AddAccount/index.js +++ b/src/components/modals/AddAccount/index.js @@ -260,7 +260,7 @@ class AddAccountModal extends PureComponent { ...defaultState, }) - addAccount = ({ id, name, ...data }) => { + addAccount = account => { const { currency } = this.state const { addAccount } = this.props @@ -269,12 +269,10 @@ class AddAccountModal extends PureComponent { } addAccount({ - id, - name, + ...account, coinType: currency.coinType, currency, unit: getDefaultUnitByCoinType(currency.coinType), - data, }) } diff --git a/src/components/modals/Receive.js b/src/components/modals/Receive.js index eb9dd27b..1b1e281b 100644 --- a/src/components/modals/Receive.js +++ b/src/components/modals/Receive.js @@ -1,6 +1,6 @@ // @flow -import React, { PureComponent, Fragment } from 'react' +import React, { PureComponent } from 'react' import { translate } from 'react-i18next' import get from 'lodash/get' @@ -62,7 +62,6 @@ class ReceiveModal extends PureComponent { onHide={this.handleHide} render={({ data, onClose }) => { const account = this.getAccount(data) - const accountData = get(account, 'data', {}) return ( @@ -73,24 +72,16 @@ class ReceiveModal extends PureComponent { - {accountData && ( - - - - - - - - )} + + + + +