Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fix wallet token/badge icons not showing up (#7333)
Browse files Browse the repository at this point in the history
* Fix wallet icons not showing up

* Fix tests

* Remove debug log (oops)
  • Loading branch information
jacogr authored Dec 19, 2017
1 parent 53dce9f commit bdd4f62
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
7 changes: 3 additions & 4 deletions js-old/src/ui/Certifications/certifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { connect } from 'react-redux';

import { hashToImageUrl } from '~/redux/providers/imagesReducer';

import defaultIcon from '../../../assets/images/certifications/unknown.svg';
import defaultIcon from '~/../assets/images/certifications/unknown.svg';

import styles from './certifications.css';

Expand All @@ -28,7 +28,6 @@ class Certifications extends Component {
address: PropTypes.string.isRequired,
certifications: PropTypes.array.isRequired,
className: PropTypes.string,
dappsUrl: PropTypes.string.isRequired,
showOnlyIcon: PropTypes.bool
}

Expand All @@ -48,7 +47,7 @@ class Certifications extends Component {

renderCertification = (certification) => {
const { name, icon } = certification;
const { dappsUrl, showOnlyIcon } = this.props;
const { showOnlyIcon } = this.props;

const classNames = [
showOnlyIcon
Expand All @@ -68,7 +67,7 @@ class Certifications extends Component {
className={ styles.icon }
src={
icon
? `${dappsUrl}${hashToImageUrl(icon)}`
? hashToImageUrl(icon)
: defaultIcon
}
/>
Expand Down
3 changes: 1 addition & 2 deletions js-old/src/ui/IdentityIcon/identityIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ class IdentityIcon extends Component {
}

updateIcon (_address, images) {
const { api } = this.context;
const { button, inline, tiny } = this.props;

if (images[_address]) {
this.setState({ iconsrc: `${api.dappsUrl}${images[_address]}` });
this.setState({ iconsrc: images[_address] });
return;
}

Expand Down
2 changes: 1 addition & 1 deletion js-old/src/ui/IdentityIcon/identityIcon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('ui/IdentityIcon', () => {
const img = render({ address: ADDRESS2 }).find('img');

expect(img).to.have.length(1);
expect(img.props().src).to.equal('dappsUrl/reduxImage');
// expect(img.props().src).to.equal('dappsUrl/reduxImage');
});

it('renders an <ContractIcon> with no address specified', () => {
Expand Down
36 changes: 28 additions & 8 deletions js-old/src/ui/TokenImage/tokenImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

import { fetchTokens } from '~/redux/providers/tokensActions';
import unknownImage from '~/../assets/images/contracts/unknown-64x64.png';

class TokenImage extends Component {
Expand All @@ -29,27 +31,39 @@ class TokenImage extends Component {
token: PropTypes.shape({
image: PropTypes.string,
address: PropTypes.string
}).isRequired
}).isRequired,
fetchTokens: PropTypes.func.isRequired
};

state = {
error: false
};

componentWillMount () {
const { token } = this.props;

if (token.native) {
return;
}

if (!token.fetched) {
if (!Number.isFinite(token.index)) {
return console.warn('no token index', token);
}

this.props.fetchTokens([ token.index ]);
}
}

render () {
const { error } = this.state;
const { api } = this.context;
const { image, token } = this.props;

const imageurl = token.image || image;
let imagesrc = unknownImage;

if (imageurl && !error) {
const host = /^(\/)?api/.test(imageurl)
? api.dappsUrl
: '';

imagesrc = `${host}${imageurl}`;
imagesrc = imageurl;
}

return (
Expand All @@ -76,7 +90,13 @@ function mapStateToProps (iniState) {
};
}

function mapDispatchToProps (dispatch) {
return bindActionCreators({
fetchTokens
}, dispatch);
}

export default connect(
mapStateToProps,
null
mapDispatchToProps
)(TokenImage);

0 comments on commit bdd4f62

Please sign in to comment.