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

fixed: replace the image when rendering url with a placeholder #508

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { CardMedia } from '@mui/material';
import React from 'react';

import flowgrey from 'ui/FRWAssets/svg/flow-grey.svg';

interface IconWithPlaceholderProps {
imageUrl: string;
width?: string | number;
height?: string | number;
borderRadius?: string | number;
backgroundColor?: string;
}

const IconWithPlaceholder: React.FC<IconWithPlaceholderProps> = ({
imageUrl,
width = '60px',
height = '60px',
borderRadius = '12px',
backgroundColor = 'text.secondary',
}) => {
return (
<CardMedia
component="img"
sx={{
width,
height,
borderRadius,
backgroundColor,
}}
image={imageUrl}
onError={(e) => {
e.currentTarget.onerror = null;
e.currentTarget.src = flowgrey;
}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using the Google favicon api as a fallback. It should work nicely

Suggested change
}}
e.currentTarget.src = `https://www.google.com/s2/favicons?sz=256&domain_url=${imageUrl}`;

/>
);
};

export default IconWithPlaceholder;
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import {
Accordion,
AccordionSummary,
AccordionDetails,
CardMedia,
} from '@mui/material';
import React from 'react';
import Highlight from 'react-highlight';

import placeholder from 'ui/FRWAssets/image/placeholder.png';
import IconWithPlaceholder from '../EthApprovalComponents/IconWithPlaceholder';

export const DefaultBlock = ({ title, host, data, logo }) => {
const hexToString = (hex) => {
Expand All @@ -38,15 +39,7 @@ export const DefaultBlock = ({ title, host, data, logo }) => {
return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '12px' }}>
<Box sx={{ display: 'flex', gap: '18px', marginBottom: '0px' }}>
<img
style={{
height: '60px',
width: '60px',
borderRadius: '12px',
backgroundColor: 'text.secondary',
}}
src={logo ? logo : placeholder}
/>
<IconWithPlaceholder imageUrl={logo} />
<Stack direction="column" spacing={1} sx={{ justifyContent: 'space-between' }}>
<Typography>{title}</Typography>
<Typography color="secondary.main" variant="overline">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CopyButton } from 'ui/FRWComponent';
import { formatAddress, HexToDecimalConverter } from 'ui/utils';

import IconFlow from '../../../../../../components/iconfont/IconFlow';

import IconWithPlaceholder from '../EthApprovalComponents/IconWithPlaceholder';
const convertToFlow = (value) => {
return Number(HexToDecimalConverter(value)) / 1_000_000_000_000_000_000;
};
Expand All @@ -18,15 +18,7 @@ export const TransactionBlock = ({ title, data, logo, lilicoEnabled, decodedCall
return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '12px' }}>
<Box sx={{ display: 'flex', gap: '18px', marginBottom: '0px' }}>
<img
style={{
height: '60px',
width: '60px',
borderRadius: '12px',
backgroundColor: 'text.secondary',
}}
src={logo ? logo : placeholder}
/>
<IconWithPlaceholder imageUrl={logo} />
<Stack direction="column" spacing={1} sx={{ justifyContent: 'space-between' }}>
<Typography color="text.secondary" sx={{ fontSize: '12px' }}>
Sign Transaction from
Expand Down
12 changes: 2 additions & 10 deletions src/ui/views/Approval/components/EthApproval/EthConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LLPrimaryButton, LLSecondaryButton, LLSpinner, LLConnectLoading } from
import { useApproval, useWallet, formatAddress } from 'ui/utils';

import CheckCircleIcon from '../../../../../../components/iconfont/IconCheckmark';
import IconWithPlaceholder from '../EthApprovalComponents/IconWithPlaceholder';

// import EthMove from '../EthMove';

Expand Down Expand Up @@ -153,16 +154,7 @@ const EthConnect = ({ params: { icon, name, origin } }: ConnectProps) => {
{isEvm && (
<Box sx={{ display: 'flex', flexDirection: 'column', margin: '18px', gap: '18px' }}>
<Box sx={{ display: 'flex', gap: '18px', marginBottom: '0px' }}>
<CardMedia
component="img"
sx={{
height: '60px',
width: '60px',
borderRadius: '12px',
backgroundColor: 'text.secondary',
}}
image={icon}
/>
<IconWithPlaceholder imageUrl={icon} />
<Stack direction="column" sx={{ justifyContent: 'space-between' }}>
<Typography
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { LLConnectLoading, LLLinkingLoading } from '@/ui/FRWComponent';
import { LLPrimaryButton, LLSecondaryButton } from 'ui/FRWComponent';
import { useApproval, useWallet, formatAddress } from 'ui/utils';

import IconWithPlaceholder from '../EthApprovalComponents/IconWithPlaceholder';
interface ConnectProps {
params: any;
}
Expand Down Expand Up @@ -276,11 +277,8 @@ const EthSignType = ({ params }: ConnectProps) => {
>
{params.session && (
<Box sx={{ marginBottom: '2px', display: 'flex' }}>
<CardMedia
image={params.session.icon}
sx={{ width: '64px', height: '64px', marginRight: '16px' }}
/>
<Box>
<IconWithPlaceholder imageUrl={params.session.icon} />
<Box sx={{ marginLeft: '16px' }}>
<Typography sx={{ fontSize: '12px', color: '#737373' }}>
Sign Type Message from
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { LLConnectLoading, LLLinkingLoading } from '@/ui/FRWComponent';
import { LLPrimaryButton, LLSecondaryButton } from 'ui/FRWComponent';
import { useApproval, useWallet } from 'ui/utils';

import IconWithPlaceholder from '../EthApprovalComponents/IconWithPlaceholder';

interface ConnectProps {
params: any;
}
Expand Down Expand Up @@ -177,11 +179,8 @@ const EthSignV1 = ({ params }: ConnectProps) => {
>
{params.session && (
<Box sx={{ marginBottom: '2px', display: 'flex' }}>
<CardMedia
image={params.session.icon}
sx={{ width: '64px', height: '64px', marginRight: '16px' }}
/>
<Box>
<IconWithPlaceholder imageUrl={params.session.icon} />
<Box sx={{ marginLeft: '16px' }}>
<Typography sx={{ fontSize: '12px', color: '#737373' }}>
Sign Type Message from
</Typography>
Expand Down
Loading