{ this.renderVault() }
@@ -115,15 +158,10 @@ export default class Header extends Component {
}
renderTxCount () {
- const { balance, isContract } = this.props;
-
- if (!balance || isContract) {
- return null;
- }
-
- const { txCount } = balance;
+ const { isContract } = this.props;
+ const { txCount } = this.state;
- if (!txCount) {
+ if (!txCount || isContract) {
return null;
}
diff --git a/js/src/views/Account/Header/header.spec.js b/js/src/views/Account/Header/header.spec.js
index 4f56044f0a7..48c0b1a998d 100644
--- a/js/src/views/Account/Header/header.spec.js
+++ b/js/src/views/Account/Header/header.spec.js
@@ -18,6 +18,8 @@ import BigNumber from 'bignumber.js';
import { shallow } from 'enzyme';
import React from 'react';
+import { ETH_TOKEN } from '~/util/tokens';
+
import Header from './';
const ACCOUNT = {
@@ -28,17 +30,44 @@ const ACCOUNT = {
},
uuid: '0xabcdef'
};
+const subscriptions = {};
let component;
let instance;
+const api = {
+ subscribe: (method, callback) => {
+ subscriptions[method] = (subscriptions[method] || []).concat(callback);
+ return Promise.resolve(0);
+ },
+ eth: {
+ getTransactionCount: () => Promise.resolve(new BigNumber(1))
+ }
+};
+
+function reduxStore () {
+ const getState = () => ({
+ balances: {},
+ tokens: {
+ [ETH_TOKEN.id]: ETH_TOKEN
+ }
+ });
+
+ return {
+ getState,
+ dispatch: () => null,
+ subscribe: () => null
+ };
+}
+
function render (props = {}) {
if (props && !props.account) {
props.account = ACCOUNT;
}
component = shallow(
-
+
,
+ { context: { api } }
);
instance = component.instance();
@@ -72,8 +101,9 @@ describe('views/Account/Header', () => {
let balance;
beforeEach(() => {
- render({ balance: { balance: 'testing' } });
- balance = component.find('Balance');
+ render();
+ balance = component.find('Connect(Balance)')
+ .shallow({ context: { store: reduxStore() } });
});
it('renders', () => {
@@ -81,11 +111,7 @@ describe('views/Account/Header', () => {
});
it('passes the account', () => {
- expect(balance.props().account).to.deep.equal(ACCOUNT);
- });
-
- it('passes the balance', () => {
-
+ expect(balance.props().address).to.deep.equal(ACCOUNT.address);
});
});
@@ -177,24 +203,33 @@ describe('views/Account/Header', () => {
});
describe('renderTxCount', () => {
- it('renders null when contract', () => {
- render({ balance: { txCount: new BigNumber(1) }, isContract: true });
+ it('renders null when txCount is null', () => {
+ render();
expect(instance.renderTxCount()).to.be.null;
});
- it('renders null when no balance', () => {
- render({ balance: null, isContract: false });
- expect(instance.renderTxCount()).to.be.null;
- });
+ it('renders null when contract', () => {
+ render({ isContract: true });
- it('renders null when txCount is null', () => {
- render({ balance: { txCount: null }, isContract: false });
- expect(instance.renderTxCount()).to.be.null;
+ subscriptions['eth_blockNumber'].forEach((callback) => {
+ callback();
+
+ setTimeout(() => {
+ expect(instance.renderTxCount()).to.be.null;
+ });
+ });
});
it('renders the tx count', () => {
- render({ balance: { txCount: new BigNumber(1) }, isContract: false });
- expect(instance.renderTxCount()).not.to.be.null;
+ render();
+
+ subscriptions['eth_blockNumber'].forEach((callback) => {
+ callback();
+
+ setTimeout(() => {
+ expect(instance.renderTxCount()).not.to.be.null;
+ });
+ });
});
});
diff --git a/js/src/views/Account/account.js b/js/src/views/Account/account.js
index 98f02afe3c0..6f38cdf72b0 100644
--- a/js/src/views/Account/account.js
+++ b/js/src/views/Account/account.js
@@ -46,8 +46,7 @@ class Account extends Component {
fetchCertifications: PropTypes.func.isRequired,
setVisibleAccounts: PropTypes.func.isRequired,
- accounts: PropTypes.object,
- balances: PropTypes.object,
+ account: PropTypes.object,
certifications: PropTypes.object,
netVersion: PropTypes.string.isRequired,
params: PropTypes.object
@@ -83,12 +82,9 @@ class Account extends Component {
}
render () {
- const { accounts, balances } = this.props;
+ const { account } = this.props;
const { address } = this.props.params;
- const account = (accounts || {})[address];
- const balance = (balances || {})[address];
-
if (!account) {
return null;
}
@@ -102,17 +98,15 @@ class Account extends Component {
{ this.renderFaucetDialog() }
{ this.renderFundDialog() }
{ this.renderPasswordDialog(account) }
- { this.renderTransferDialog(account, balance) }
+ { this.renderTransferDialog(account) }
{ this.renderVerificationDialog() }
- { this.renderActionbar(account, balance) }
+ { this.renderActionbar(account) }
@@ -143,16 +137,14 @@ class Account extends Component {
return certifications.length !== 0;
}
- renderActionbar (account, balance) {
+ renderActionbar (account) {
const { certifications, netVersion } = this.props;
const { address } = this.props.params;
- const showTransferButton = !!(balance && balance.tokens);
const isVerifiable = this.isMainnet(netVersion);
const isFaucettable = this.isFaucettable(netVersion, certifications, address);
const buttons = [
}
key='transferFunds'
label={
@@ -374,18 +366,14 @@ class Account extends Component {
);
}
- renderTransferDialog (account, balance) {
+ renderTransferDialog (account) {
if (!this.store.isTransferVisible) {
return null;
}
- const { balances } = this.props;
-
return (
);
@@ -407,15 +395,17 @@ class Account extends Component {
}
}
-function mapStateToProps (state) {
+function mapStateToProps (state, props) {
+ const { address } = props.params;
+
const { accounts } = state.personal;
- const { balances } = state.balances;
const certifications = state.certifications;
const { netVersion } = state.nodeStatus;
+ const account = (accounts || {})[address];
+
return {
- accounts,
- balances,
+ account,
certifications,
netVersion
};
diff --git a/js/src/views/Accounts/List/list.js b/js/src/views/Accounts/List/list.js
index edd90db7b95..2fa3be70b13 100644
--- a/js/src/views/Accounts/List/list.js
+++ b/js/src/views/Accounts/List/list.js
@@ -14,21 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see
.
+import { pick } from 'lodash';
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Container, SectionList } from '~/ui';
import { fetchCertifiers, fetchCertifications } from '~/redux/providers/certifications/actions';
+import { ETH_TOKEN } from '~/util/tokens';
import Summary from '../Summary';
import styles from './list.css';
class List extends Component {
static propTypes = {
- accounts: PropTypes.object,
- balances: PropTypes.object,
+ balances: PropTypes.object.isRequired,
certifications: PropTypes.object.isRequired,
+ accounts: PropTypes.object,
disabled: PropTypes.object,
empty: PropTypes.bool,
link: PropTypes.string,
@@ -51,7 +53,7 @@ class List extends Component {
}
render () {
- const { accounts, balances, disabled, empty } = this.props;
+ const { accounts, disabled, empty } = this.props;
if (empty) {
return (
@@ -67,13 +69,11 @@ class List extends Component {
.getAddresses()
.map((address) => {
const account = accounts[address] || {};
- const balance = balances[address] || {};
const isDisabled = disabled ? disabled[address] : false;
const owners = account.owners || null;
return {
account,
- balance,
isDisabled,
owners
};
@@ -88,13 +88,12 @@ class List extends Component {
}
renderSummary = (item) => {
- const { account, balance, isDisabled, owners } = item;
+ const { account, isDisabled, owners } = item;
const { handleAddSearchToken, link } = this.props;
return (
token.token.tag.toLowerCase() === 'eth');
- const ethB = balanceB.tokens.find(token => token.token.tag.toLowerCase() === 'eth');
+ const ethA = balanceA[ETH_TOKEN.id];
+ const ethB = balanceB[ETH_TOKEN.id];
if (!ethA && !ethB) {
return 0;
@@ -171,7 +170,7 @@ class List extends Component {
return 1;
}
- return -1 * ethA.value.comparedTo(ethB.value);
+ return -1 * ethA.comparedTo(ethB);
}
if (key === 'tags') {
@@ -257,10 +256,12 @@ class List extends Component {
}
}
-function mapStateToProps (state) {
+function mapStateToProps (state, props) {
+ const addresses = Object.keys(props.accounts);
+ const balances = pick(state.balances, addresses);
const { certifications } = state;
- return { certifications };
+ return { balances, certifications };
}
function mapDispatchToProps (dispatch) {
diff --git a/js/src/views/Accounts/Summary/summary.js b/js/src/views/Accounts/Summary/summary.js
index 601f9d8c239..ded53ab7ccc 100644
--- a/js/src/views/Accounts/Summary/summary.js
+++ b/js/src/views/Accounts/Summary/summary.js
@@ -36,7 +36,6 @@ class Summary extends Component {
static propTypes = {
account: PropTypes.object.isRequired,
accountsInfo: PropTypes.object.isRequired,
- balance: PropTypes.object,
disabled: PropTypes.bool,
link: PropTypes.string,
name: PropTypes.string,
@@ -74,20 +73,6 @@ class Summary extends Component {
return true;
}
- const prevTokens = this.props.balance.tokens || [];
- const nextTokens = nextProps.balance.tokens || [];
-
- if (prevTokens.length !== nextTokens.length) {
- return true;
- }
-
- const prevValues = prevTokens.map((t) => ({ value: t.value.toNumber(), image: t.token.image }));
- const nextValues = nextTokens.map((t) => ({ value: t.value.toNumber(), image: t.token.image }));
-
- if (!isEqual(prevValues, nextValues)) {
- return true;
- }
-
const prevOwners = this.props.owners;
const nextOwners = nextProps.owners;
@@ -249,15 +234,11 @@ class Summary extends Component {
}
renderBalance (onlyEth) {
- const { balance } = this.props;
-
- if (!balance) {
- return null;
- }
+ const { account } = this.props;
return (
account.uuid);
const _hasAccounts = Object.keys(_accounts).length > 0;
@@ -147,7 +146,6 @@ class Accounts extends Component {
account.wallet);
const hasWallets = Object.keys(wallets).length > 0;
@@ -175,7 +173,6 @@ class Accounts extends Component {
link='wallet'
search={ searchValues }
accounts={ wallets }
- balances={ balances }
order={ sortOrder }
handleAddSearchToken={ this.onAddSearchToken }
/>
@@ -183,7 +180,7 @@ class Accounts extends Component {
}
renderExternalAccounts () {
- const { accounts, balances } = this.props;
+ const { accounts } = this.props;
const { wallets } = this.hwstore;
const hardware = pickBy(accounts, (account) => account.hardware);
const external = pickBy(accounts, (account) => account.external);
@@ -210,7 +207,6 @@ class Accounts extends Component {
@@ -92,7 +90,6 @@ class Address extends Component {
- );
- }
-
return (
{ this.renderBlockNumber(account.meta) }
@@ -520,13 +517,11 @@ class Contract extends Component {
function mapStateToProps (state) {
const { accounts, accountsInfo, contracts } = state.personal;
- const { balances } = state.balances;
const { netVersion } = state.nodeStatus;
return {
accounts,
accountsInfo,
- balances,
contracts,
netVersion
};
diff --git a/js/src/views/Contracts/contracts.js b/js/src/views/Contracts/contracts.js
index 33b475c5ff0..52ed7cdae91 100644
--- a/js/src/views/Contracts/contracts.js
+++ b/js/src/views/Contracts/contracts.js
@@ -57,7 +57,6 @@ class Contracts extends Component {
static propTypes = {
setVisibleAccounts: PropTypes.func.isRequired,
- balances: PropTypes.object,
accounts: PropTypes.object,
contracts: PropTypes.object,
hasContracts: PropTypes.bool
@@ -96,7 +95,7 @@ class Contracts extends Component {
}
render () {
- const { contracts, hasContracts, balances } = this.props;
+ const { contracts, hasContracts } = this.props;
const { searchValues, sortOrder } = this.state;
return (
@@ -109,7 +108,6 @@ class Contracts extends Component {
link='contracts'
search={ searchValues }
accounts={ contracts }
- balances={ balances }
empty={ !hasContracts }
order={ sortOrder }
orderFallback='name'
@@ -267,13 +265,11 @@ class Contracts extends Component {
function mapStateToProps (state) {
const { accounts, contracts, hasContracts } = state.personal;
- const { balances } = state.balances;
return {
accounts,
contracts,
- hasContracts,
- balances
+ hasContracts
};
}
diff --git a/js/src/views/ParityBar/parityBar.js b/js/src/views/ParityBar/parityBar.js
index 9d5027acfb7..b8dd669d523 100644
--- a/js/src/views/ParityBar/parityBar.js
+++ b/js/src/views/ParityBar/parityBar.js
@@ -48,7 +48,6 @@ class ParityBar extends Component {
};
static propTypes = {
- balances: PropTypes.object,
dapp: PropTypes.bool,
externalLink: PropTypes.string,
pending: PropTypes.array
@@ -370,13 +369,9 @@ class ParityBar extends Component {
}
renderAccount = (account) => {
- const { balances } = this.props;
- const balance = balances[account.address];
-
return (
);
}
@@ -700,11 +695,9 @@ class ParityBar extends Component {
}
function mapStateToProps (state) {
- const { balances } = state.balances;
const { pending } = state.signer;
return {
- balances,
pending
};
}
diff --git a/js/src/views/Wallet/wallet.js b/js/src/views/Wallet/wallet.js
index 84d4dbe5b1f..e996e5fdc15 100644
--- a/js/src/views/Wallet/wallet.js
+++ b/js/src/views/Wallet/wallet.js
@@ -65,7 +65,6 @@ class Wallet extends Component {
static propTypes = {
address: PropTypes.string.isRequired,
- balance: nullableProptype(PropTypes.object.isRequired),
netVersion: PropTypes.string.isRequired,
owned: PropTypes.bool.isRequired,
setVisibleAccounts: PropTypes.func.isRequired,
@@ -105,7 +104,7 @@ class Wallet extends Component {
}
render () {
- const { walletAccount, balance, wallet } = this.props;
+ const { walletAccount, wallet } = this.props;
if (!walletAccount) {
return null;
@@ -125,7 +124,6 @@ class Wallet extends Component {
{ this.renderInfos() }
@@ -212,15 +210,13 @@ class Wallet extends Component {
}
renderActionbar () {
- const { balance, owned } = this.props;
- const showTransferButton = !!(balance && balance.tokens);
+ const { owned } = this.props;
const buttons = [];
if (owned) {
buttons.push(
}
key='transferFunds'
label={
@@ -343,12 +339,11 @@ class Wallet extends Component {
return null;
}
- const { walletAccount, balance } = this.props;
+ const { walletAccount } = this.props;
return (
);
@@ -391,7 +386,6 @@ function mapStateToProps (_, initProps) {
return (state) => {
const { netVersion } = state.nodeStatus;
const { accountsInfo = {}, accounts = {} } = state.personal;
- const { balances } = state.balances;
const walletAccount = accounts[address] || accountsInfo[address] || null;
if (walletAccount) {
@@ -399,12 +393,10 @@ function mapStateToProps (_, initProps) {
}
const wallet = state.wallet.wallets[address] || {};
- const balance = balances[address] || null;
const owned = !!accounts[address];
return {
address,
- balance,
netVersion,
owned,
wallet,
diff --git a/js/src/views/WriteContract/writeContract.js b/js/src/views/WriteContract/writeContract.js
index 86262820dc9..72620cc3705 100644
--- a/js/src/views/WriteContract/writeContract.js
+++ b/js/src/views/WriteContract/writeContract.js
@@ -446,9 +446,9 @@ class WriteContract extends Component {
return (