Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 3164fef

Browse files
authored
Fix: add stopPropagation to the external link (#220)
* Fix: add stopPropagation to the external link * Update snapshots * prettier * Add type in the storybook
1 parent 50033f1 commit 3164fef

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@safe-global/safe-react-components",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "Safe UI components",
55
"main": "dist/index.min.js",
66
"typings": "dist/index.d.ts",

src/components/EthHashInfo/EthHashInfo.stories.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import * as React from 'react';
22

3-
import EthHashInfo from './';
3+
import EthHashInfo, { type EthHashInfoProps } from './';
44

5-
export const Main = ({ size }): React.ReactElement => {
5+
export const Main = ({
6+
size,
7+
}: {
8+
size?: EthHashInfoProps['avatarSize'];
9+
}): React.ReactElement => {
610
return (
711
<EthHashInfo
8-
avatarSize={size || null}
12+
avatarSize={size}
913
showPrefix
1014
prefix="eth"
1115
address="0x40A2aCCbd92BCA938b02010E17A5b8929b49130D"

src/components/EthHashInfo/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const EthHashInfo = ({
5050
const theme = useTheme();
5151
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
5252

53+
const onError = React.useCallback(() => {
54+
setFallbackToIdenticon(true);
55+
}, []);
56+
5357
return (
5458
<Container>
5559
{showAvatar && (
@@ -58,7 +62,7 @@ const EthHashInfo = ({
5862
<img
5963
src={customAvatar}
6064
alt={address}
61-
onError={() => setFallbackToIdenticon(true)}
65+
onError={onError}
6266
width={avatarSize}
6367
height={avatarSize}
6468
/>
@@ -82,11 +86,9 @@ const EthHashInfo = ({
8286
<AddressContainer>
8387
<Box fontWeight="inherit" fontSize="inherit">
8488
{showPrefix && shouldPrefix && prefix && <b>{prefix}:</b>}
85-
{isMobile ? (
86-
<span>{shortenAddress(address)}</span>
87-
) : (
88-
<span>{shortAddress ? shortenAddress(address) : address}</span>
89-
)}
89+
<span>
90+
{shortAddress || isMobile ? shortenAddress(address) : address}
91+
</span>
9092
</Box>
9193

9294
{showCopyButton && (

src/components/ExplorerButton/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export type ExplorerButtonProps = {
1010
href: string;
1111
};
1212

13+
const stopPropagation = (e: React.SyntheticEvent) => e.stopPropagation();
14+
1315
const ExplorerButton = ({
1416
title,
1517
href,
@@ -22,6 +24,7 @@ const ExplorerButton = ({
2224
href={href}
2325
target="_blank"
2426
rel="noopener noreferrer"
27+
onClick={stopPropagation}
2528
size="small">
2629
<Icon component={LinkIcon} />
2730
</IconButton>

tests/src/components/ExplorerButton/__snapshots__/ExplorerButton.stories.storyshot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ exports[`Storyshots Components/ExplorerButton Main 1`] = `
4949
data-mui-internal-clone-element={true}
5050
href="https://goerli.etherscan.io/address/0x51A099ac1BF46D471110AA8974024Bfe518Fd6C4"
5151
onBlur={[Function]}
52+
onClick={[Function]}
5253
onContextMenu={[Function]}
5354
onDragLeave={[Function]}
5455
onFocus={[Function]}

0 commit comments

Comments
 (0)