Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX: Fix token image not displaying in asset listing #17575

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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