Skip to content

Commit

Permalink
UX: Fix token image not displaying in asset listing (#17575)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkwing authored Feb 6, 2023
1 parent 4b8aebb commit 02d608d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions ui/components/app/token-cell/token-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function TokenCell({
address,
decimals,
balanceError,
image,
symbol,
string,
onClick,
Expand Down Expand Up @@ -45,6 +46,7 @@ export default function TokenCell({
tokenAddress={address}
tokenSymbol={symbol}
tokenDecimals={decimals}
tokenImage={image}
warning={warning}
primary={`${string || 0}`}
secondary={formattedFiat}
Expand All @@ -61,6 +63,7 @@ TokenCell.propTypes = {
string: PropTypes.string,
onClick: PropTypes.func.isRequired,
isERC721: PropTypes.bool,
image: PropTypes.string,
};

TokenCell.defaultProps = {
Expand Down
26 changes: 21 additions & 5 deletions ui/components/ui/identicon/identicon.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export default class Identicon extends Component {
ipfsGateway: PropTypes.string,
};

state = {
imageLoadingError: false,
};

static defaultProps = {
addBorder: false,
address: undefined,
Expand Down Expand Up @@ -93,6 +97,9 @@ export default class Identicon extends Component {
src={image}
style={getStyles(diameter)}
alt={alt}
onError={() => {
this.setState({ imageLoadingError: true });
}}
/>
);
}
Expand Down Expand Up @@ -124,16 +131,25 @@ export default class Identicon extends Component {
);
}

shouldComponentUpdate(nextProps) {
renderBlockieOrJazzIcon() {
const { useBlockie } = this.props;
return useBlockie ? this.renderBlockie() : this.renderJazzicon();
}

shouldComponentUpdate(nextProps, nextState) {
// We only want to re-render if props are different.
return !isEqual(nextProps, this.props);
return !isEqual(nextProps, this.props) || !isEqual(nextState, this.state);
}

render() {
const { address, image, useBlockie, addBorder, diameter, tokenList } =
this.props;
const { address, image, addBorder, diameter, tokenList } = this.props;
const { imageLoadingError } = this.state;
const size = diameter + 8;

if (imageLoadingError) {
return this.renderBlockieOrJazzIcon();
}

if (image) {
return this.renderImage();
}
Expand All @@ -148,7 +164,7 @@ export default class Identicon extends Component {
className={classnames({ 'identicon__address-wrapper': addBorder })}
style={addBorder ? getStyles(size) : null}
>
{useBlockie ? this.renderBlockie() : this.renderJazzicon()}
{this.renderBlockieOrJazzIcon()}
</div>
);
}
Expand Down

0 comments on commit 02d608d

Please sign in to comment.