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

fix: Prevent BadgeStatus' tooltip from rerendering #30874

Merged
merged 1 commit into from
Mar 8, 2025
Merged
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
88 changes: 51 additions & 37 deletions ui/components/multichain/badge-status/badge-status.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import classNames from 'classnames';
import { useSelector } from 'react-redux';
import {
Expand All @@ -22,6 +22,8 @@ import Tooltip from '../../ui/tooltip';

import { BadgeStatusProps } from './badge-status.types';

const TooltipStyle = { display: 'flex' };

export const BadgeStatus: React.FC<BadgeStatusProps> = ({
className = '',
badgeBackgroundColor = BackgroundColor.backgroundAlternative,
Expand All @@ -33,6 +35,52 @@ export const BadgeStatus: React.FC<BadgeStatusProps> = ({
}): JSX.Element => {
const useBlockie = useSelector(getUseBlockie);

const tooltipContents = useMemo(() => {
return (
<BadgeWrapper
positionObj={
isConnectedAndNotActive
? { bottom: 2, right: 5 }
: { bottom: -1, right: 2 }
}
badge={
<Box
className={classNames('multichain-badge-status__badge', {
'multichain-badge-status__badge-not-connected':
isConnectedAndNotActive,
})}
backgroundColor={badgeBackgroundColor}
borderRadius={BorderRadius.full}
borderColor={badgeBorderColor}
borderWidth={2}
/>
}
>
{
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
<AvatarAccount
borderColor={BorderColor.transparent}
size={AvatarAccountSize.Md}
address={address}
variant={
useBlockie
? AvatarAccountVariant.Blockies
: AvatarAccountVariant.Jazzicon
}
marginInlineEnd={2}
/>
///: END:ONLY_INCLUDE_IF
}
</BadgeWrapper>
);
}, [
address,
badgeBackgroundColor,
badgeBorderColor,
isConnectedAndNotActive,
useBlockie,
]);

return (
<Box
className={classNames('multichain-badge-status', className)}
Expand All @@ -45,46 +93,12 @@ export const BadgeStatus: React.FC<BadgeStatusProps> = ({
{...(props as BoxProps<'div'>)}
>
<Tooltip
style={{ display: 'flex' }}
style={TooltipStyle}
title={text}
data-testid="multichain-badge-status__tooltip"
position="bottom"
>
<BadgeWrapper
positionObj={
isConnectedAndNotActive
? { bottom: 2, right: 5 }
: { bottom: -1, right: 2 }
}
badge={
<Box
className={classNames('multichain-badge-status__badge', {
'multichain-badge-status__badge-not-connected':
isConnectedAndNotActive,
})}
backgroundColor={badgeBackgroundColor}
borderRadius={BorderRadius.full}
borderColor={badgeBorderColor}
borderWidth={2}
/>
}
>
{
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
<AvatarAccount
borderColor={BorderColor.transparent}
size={AvatarAccountSize.Md}
address={address}
variant={
useBlockie
? AvatarAccountVariant.Blockies
: AvatarAccountVariant.Jazzicon
}
marginInlineEnd={2}
/>
///: END:ONLY_INCLUDE_IF
}
</BadgeWrapper>
{tooltipContents}
</Tooltip>
</Box>
);
Expand Down
Loading