diff --git a/js/src/modals/Transfer/Details/details.js b/js/src/modals/Transfer/Details/details.js
index 97d42ffefd4..a1d0cc637c7 100644
--- a/js/src/modals/Transfer/Details/details.js
+++ b/js/src/modals/Transfer/Details/details.js
@@ -14,15 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see .
-import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
-import { Checkbox, MenuItem } from 'material-ui';
-import { isEqual } from 'lodash';
+import { Checkbox } from 'material-ui';
-import Form, { Input, InputAddressSelect, AddressSelect, Select } from '~/ui/Form';
+import Form, { Input, InputAddressSelect, AddressSelect } from '~/ui/Form';
import { nullableProptype } from '~/util/proptypes';
-import imageUnknown from '../../../../assets/images/contracts/unknown-64x64.png';
+import TokenSelect from './tokenSelect';
import styles from '../transfer.css';
const CHECK_STYLE = {
@@ -31,110 +29,12 @@ const CHECK_STYLE = {
left: '1em'
};
-class TokenSelect extends Component {
- static contextTypes = {
- api: PropTypes.object
- }
-
- static propTypes = {
- onChange: PropTypes.func.isRequired,
- balance: PropTypes.object.isRequired,
- images: PropTypes.object.isRequired,
- tag: PropTypes.string.isRequired
- };
-
- componentWillMount () {
- this.computeTokens();
- }
-
- componentWillReceiveProps (nextProps) {
- const prevTokens = this.props.balance.tokens.map((t) => `${t.token.tag}_${t.value.toNumber()}`);
- const nextTokens = nextProps.balance.tokens.map((t) => `${t.token.tag}_${t.value.toNumber()}`);
-
- if (!isEqual(prevTokens, nextTokens)) {
- this.computeTokens(nextProps);
- }
- }
-
- computeTokens (props = this.props) {
- const { api } = this.context;
- const { balance, images } = this.props;
-
- const items = balance.tokens
- .filter((token, index) => !index || token.value.gt(0))
- .map((balance, index) => {
- const token = balance.token;
- const isEth = index === 0;
- let imagesrc = token.image;
-
- if (!imagesrc) {
- imagesrc =
- images[token.address]
- ? `${api.dappsUrl}${images[token.address]}`
- : imageUnknown;
- }
- let value = 0;
-
- if (isEth) {
- value = api.util.fromWei(balance.value).toFormat(3);
- } else {
- const format = balance.token.format || 1;
- const decimals = format === 1 ? 0 : Math.min(3, Math.floor(format / 10));
-
- value = new BigNumber(balance.value).div(format).toFormat(decimals);
- }
-
- const label = (
-
-
+
{ value }
@@ -125,14 +109,3 @@ class Balance extends Component {
);
}
}
-
-function mapStateToProps (state) {
- const { images } = state;
-
- return { images };
-}
-
-export default connect(
- mapStateToProps,
- null
-)(Balance);
diff --git a/js/src/ui/Balance/balance.spec.js b/js/src/ui/Balance/balance.spec.js
index f12e8485118..8a886b39b77 100644
--- a/js/src/ui/Balance/balance.spec.js
+++ b/js/src/ui/Balance/balance.spec.js
@@ -16,7 +16,6 @@
import { shallow } from 'enzyme';
import React from 'react';
-import sinon from 'sinon';
import apiutil from '~/api/util';
@@ -32,7 +31,6 @@ const BALANCE = {
let api;
let component;
-let store;
function createApi () {
api = {
@@ -43,36 +41,22 @@ function createApi () {
return api;
}
-function createStore () {
- store = {
- dispatch: sinon.stub(),
- subscribe: sinon.stub(),
- getState: () => {
- return {
- images: {}
- };
- }
- };
-
- return store;
-}
-
function render (props = {}) {
if (!props.balance) {
props.balance = BALANCE;
}
+ const api = createApi();
+
component = shallow(
,
{
- context: {
- store: createStore()
- }
+ context: { api }
}
- ).find('Balance').shallow({ context: { api: createApi() } });
+ );
return component;
}
@@ -91,18 +75,18 @@ describe('ui/Balance', () => {
});
it('renders all the non-zero balances', () => {
- expect(component.find('img')).to.have.length(2);
+ expect(component.find('Connect(TokenImage)')).to.have.length(2);
});
describe('render specifiers', () => {
it('renders only the single token with showOnlyEth', () => {
render({ showOnlyEth: true });
- expect(component.find('img')).to.have.length(1);
+ expect(component.find('Connect(TokenImage)')).to.have.length(1);
});
it('renders all the tokens with showZeroValues', () => {
render({ showZeroValues: true });
- expect(component.find('img')).to.have.length(3);
+ expect(component.find('Connect(TokenImage)')).to.have.length(3);
});
it('shows ETH with zero value with showOnlyEth & showZeroValues', () => {
@@ -116,7 +100,7 @@ describe('ui/Balance', () => {
]
}
});
- expect(component.find('img')).to.have.length(1);
+ expect(component.find('Connect(TokenImage)')).to.have.length(1);
});
});
});
diff --git a/js/src/ui/TokenImage/index.js b/js/src/ui/TokenImage/index.js
new file mode 100644
index 00000000000..f0b2f9d4965
--- /dev/null
+++ b/js/src/ui/TokenImage/index.js
@@ -0,0 +1,17 @@
+// Copyright 2015-2017 Parity Technologies (UK) Ltd.
+// This file is part of Parity.
+
+// Parity is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Parity is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Parity. If not, see
.
+
+export default from './tokenImage';
diff --git a/js/src/ui/TokenImage/tokenImage.js b/js/src/ui/TokenImage/tokenImage.js
new file mode 100644
index 00000000000..e0e66d22b71
--- /dev/null
+++ b/js/src/ui/TokenImage/tokenImage.js
@@ -0,0 +1,72 @@
+// Copyright 2015-2017 Parity Technologies (UK) Ltd.
+// This file is part of Parity.
+
+// Parity is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Parity is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Parity. If not, see
.
+
+import React, { Component, PropTypes } from 'react';
+import { connect } from 'react-redux';
+
+import unknownImage from '~/../assets/images/contracts/unknown-64x64.png';
+
+class TokenImage extends Component {
+ static contextTypes = {
+ api: PropTypes.object
+ };
+
+ static propTypes = {
+ image: PropTypes.string,
+ token: PropTypes.shape({
+ image: PropTypes.string,
+ address: PropTypes.string
+ }).isRequired
+ };
+
+ render () {
+ const { api } = this.context;
+ const { image, token } = this.props;
+
+ const imageurl = token.image || image;
+ let imagesrc = unknownImage;
+
+ if (imageurl) {
+ const host = /^(\/)?api/.test(imageurl)
+ ? api.dappsUrl
+ : '';
+
+ imagesrc = `${host}${imageurl}`;
+ }
+
+ return (
+
+ );
+ }
+}
+
+function mapStateToProps (iniState) {
+ const { images } = iniState;
+
+ return (_, props) => {
+ const { token } = props;
+
+ return { image: images[token.address] };
+ };
+}
+
+export default connect(
+ mapStateToProps,
+ null
+)(TokenImage);
diff --git a/js/src/views/Account/Header/header.spec.js b/js/src/views/Account/Header/header.spec.js
index 4881edb3724..4f56044f0a7 100644
--- a/js/src/views/Account/Header/header.spec.js
+++ b/js/src/views/Account/Header/header.spec.js
@@ -73,7 +73,7 @@ describe('views/Account/Header', () => {
beforeEach(() => {
render({ balance: { balance: 'testing' } });
- balance = component.find('Connect(Balance)');
+ balance = component.find('Balance');
});
it('renders', () => {
diff --git a/js/src/views/Account/account.js b/js/src/views/Account/account.js
index c92ce0c7750..230ee788a0a 100644
--- a/js/src/views/Account/account.js
+++ b/js/src/views/Account/account.js
@@ -37,7 +37,6 @@ class Account extends Component {
static propTypes = {
fetchCertifiers: PropTypes.func.isRequired,
fetchCertifications: PropTypes.func.isRequired,
- images: PropTypes.object.isRequired,
setVisibleAccounts: PropTypes.func.isRequired,
accounts: PropTypes.object,
@@ -257,14 +256,13 @@ class Account extends Component {
return null;
}
- const { balances, images } = this.props;
+ const { balances } = this.props;
return (
);
@@ -289,12 +287,10 @@ class Account extends Component {
function mapStateToProps (state) {
const { accounts } = state.personal;
const { balances } = state.balances;
- const { images } = state;
return {
accounts,
- balances,
- images
+ balances
};
}
diff --git a/js/src/views/Wallet/wallet.js b/js/src/views/Wallet/wallet.js
index 33be32c3bc0..317541599f7 100644
--- a/js/src/views/Wallet/wallet.js
+++ b/js/src/views/Wallet/wallet.js
@@ -66,7 +66,6 @@ class Wallet extends Component {
static propTypes = {
address: PropTypes.string.isRequired,
balance: nullableProptype(PropTypes.object.isRequired),
- images: PropTypes.object.isRequired,
isTest: PropTypes.bool.isRequired,
owned: PropTypes.bool.isRequired,
setVisibleAccounts: PropTypes.func.isRequired,
@@ -315,13 +314,12 @@ class Wallet extends Component {
return null;
}
- const { walletAccount, balance, images } = this.props;
+ const { walletAccount, balance } = this.props;
return (
);
@@ -365,7 +363,6 @@ function mapStateToProps (_, initProps) {
const { isTest } = state.nodeStatus;
const { accountsInfo = {}, accounts = {} } = state.personal;
const { balances } = state.balances;
- const { images } = state;
const walletAccount = accounts[address] || accountsInfo[address] || null;
if (walletAccount) {
@@ -379,7 +376,6 @@ function mapStateToProps (_, initProps) {
return {
address,
balance,
- images,
isTest,
owned,
wallet,