Skip to content

Commit 6a9fa7e

Browse files
authored
Merge pull request #1814 from oasisprotocol/csillag/use-highlighting-also-on-validator-links
Also apply highlighting to validator links
2 parents cf608fe + df1d48c commit 6a9fa7e

File tree

7 files changed

+54
-43
lines changed

7 files changed

+54
-43
lines changed

.changelog/1814.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Also apply highlighting to validator links

src/app/components/Account/AccountLink.tsx

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, ReactNode, useEffect } from 'react'
1+
import { FC, ReactNode } from 'react'
22
import { Link as RouterLink } from 'react-router-dom'
33
import { useScreenSize } from '../../hooks/useScreensize'
44
import Link from '@mui/material/Link'
@@ -8,43 +8,13 @@ import Typography from '@mui/material/Typography'
88
import { SearchScope } from '../../../types/searchScope'
99
import { useAccountMetadata } from '../../hooks/useAccountMetadata'
1010
import { trimLongString } from '../../utils/trimLongString'
11-
import { MaybeWithTooltip } from '../AdaptiveTrimmer/MaybeWithTooltip'
11+
import { MaybeWithTooltip } from '../Tooltip/MaybeWithTooltip'
1212
import Box from '@mui/material/Box'
1313
import { HighlightedText } from '../HighlightedText'
1414
import { AdaptiveHighlightedText } from '../HighlightedText/AdaptiveHighlightedText'
1515
import { AdaptiveTrimmer } from '../AdaptiveTrimmer/AdaptiveTrimmer'
1616
import { AccountMetadataSourceIndicator } from './AccountMetadataSourceIndicator'
17-
import { useAddressHighlighting } from '../HighlightingContext'
18-
import { COLORS } from '../../../styles/theme/colors'
19-
20-
const WithHighlighting: FC<{ children: ReactNode; address: string }> = ({ children, address }) => {
21-
const { highlightedAddress, highlightAddress, releaseAddress } = useAddressHighlighting()
22-
useEffect(() => () => releaseAddress(address)) // Release address on umount
23-
const isHighlighted = !!highlightedAddress && highlightedAddress.toLowerCase() === address.toLowerCase()
24-
return (
25-
<Box
26-
onMouseEnter={() => highlightAddress(address)}
27-
onMouseLeave={() => releaseAddress(address)}
28-
sx={{
29-
display: 'inline-flex',
30-
alignItems: 'center',
31-
verticalAlign: 'middle',
32-
padding: '4px 4px 2px 4px',
33-
...(isHighlighted
34-
? {
35-
background: COLORS.warningLight,
36-
border: `1px dashed ${COLORS.warningColor}`,
37-
borderRadius: '6px',
38-
}
39-
: {
40-
border: `1px dashed transparent`,
41-
}),
42-
}}
43-
>
44-
{children}
45-
</Box>
46-
)
47-
}
17+
import { WithHighlighting } from '../HighlightingContext/WithHighlighting'
4818

4919
const WithTypographyAndLink: FC<{
5020
scope: SearchScope

src/app/components/AdaptiveTrimmer/AdaptiveDynamicTrimmer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC, ReactNode, useCallback, useEffect, useRef, useState } from 'react'
22
import Box from '@mui/material/Box'
33
import InfoIcon from '@mui/icons-material/Info'
4-
import { MaybeWithTooltip } from './MaybeWithTooltip'
4+
import { MaybeWithTooltip } from '../Tooltip/MaybeWithTooltip'
55

66
type AdaptiveDynamicTrimmerProps = {
77
getFullContent: () => {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { FC, ReactNode, useEffect } from 'react'
2+
import { useAddressHighlighting } from './index'
3+
import { COLORS } from '../../../styles/theme/colors'
4+
import Box from '@mui/material/Box'
5+
6+
export const WithHighlighting: FC<{ children: ReactNode; address: string }> = ({ children, address }) => {
7+
const { highlightedAddress, highlightAddress, releaseAddress } = useAddressHighlighting()
8+
useEffect(() => () => releaseAddress(address)) // Release address on umount
9+
const isHighlighted = !!highlightedAddress && highlightedAddress.toLowerCase() === address.toLowerCase()
10+
return (
11+
<Box
12+
onMouseEnter={() => highlightAddress(address)}
13+
onMouseLeave={() => releaseAddress(address)}
14+
sx={{
15+
display: 'inline-flex',
16+
alignItems: 'center',
17+
verticalAlign: 'middle',
18+
padding: '4px 4px 2px 4px',
19+
...(isHighlighted
20+
? {
21+
background: COLORS.warningLight,
22+
border: `1px dashed ${COLORS.warningColor}`,
23+
borderRadius: '6px',
24+
}
25+
: {
26+
border: `1px dashed transparent`,
27+
}),
28+
}}
29+
>
30+
{children}
31+
</Box>
32+
)
33+
}
File renamed without changes.

src/app/components/Transactions/TransactionLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useScreenSize } from '../../hooks/useScreensize'
77
import { RouteUtils } from '../../utils/route-utils'
88
import { SearchScope } from '../../../types/searchScope'
99
import { AdaptiveTrimmer } from '../AdaptiveTrimmer/AdaptiveTrimmer'
10-
import { MaybeWithTooltip } from '../AdaptiveTrimmer/MaybeWithTooltip'
10+
import { MaybeWithTooltip } from '../Tooltip/MaybeWithTooltip'
1111
import { trimLongString } from '../../utils/trimLongString'
1212
import Box from '@mui/material/Box'
1313

src/app/components/Validators/ValidatorLink.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { HighlightedText } from '../HighlightedText'
1111
import { useValidatorName } from '../../hooks/useValidatorName'
1212
import Box from '@mui/material/Box'
1313
import { AccountMetadataSourceIndicator } from '../Account/AccountMetadataSourceIndicator'
14-
import { MaybeWithTooltip } from '../AdaptiveTrimmer/MaybeWithTooltip'
14+
import { MaybeWithTooltip } from '../Tooltip/MaybeWithTooltip'
15+
import { WithHighlighting } from '../HighlightingContext/WithHighlighting'
1516

1617
type ValidatorLinkProps = {
1718
address: string
@@ -110,15 +111,21 @@ const DesktopValidatorLink: FC<DesktopValidatorLinkProps> = ({
110111
highlightedPart,
111112
}) => {
112113
if (alwaysTrim) {
113-
return name ? (
114-
<TrimValidatorEndLinkLabel name={name} to={to} highlightedPart={highlightedPart} />
115-
) : (
116-
<TrimLinkLabel label={address} to={to} />
114+
return (
115+
<WithHighlighting address={address}>
116+
{name ? (
117+
<TrimValidatorEndLinkLabel name={name} to={to} highlightedPart={highlightedPart} />
118+
) : (
119+
<TrimLinkLabel label={address} to={to} />
120+
)}
121+
</WithHighlighting>
117122
)
118123
}
119124
return (
120-
<Link component={RouterLink} to={to}>
121-
{name ? <HighlightedText text={name} pattern={highlightedPart} /> : address}
122-
</Link>
125+
<WithHighlighting address={address}>
126+
<Link component={RouterLink} to={to}>
127+
{name ? <HighlightedText text={name} pattern={highlightedPart} /> : address}
128+
</Link>
129+
</WithHighlighting>
123130
)
124131
}

0 commit comments

Comments
 (0)