Skip to content

Commit

Permalink
Implement highlighting matches in account names
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Feb 28, 2024
1 parent 33ad4aa commit cf0f431
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions .changelog/1246.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Initial support for displaying account names
17 changes: 14 additions & 3 deletions src/app/components/Account/AccountLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useAccountName } from '../../hooks/useAccountName'
import { trimLongString } from '../../utils/trimLongString'
import { MaybeWithTooltip } from '../AdaptiveTrimmer/MaybeWithTooltip'
import Box from '@mui/material/Box'
import { HighlightedText } from '../HighlightedText'
import { AdaptiveHighlightedText } from '../HighlightedText/AdaptiveHighlightedText'
import { AdaptiveTrimmer } from '../AdaptiveTrimmer/AdaptiveTrimmer'

const WithTypographyAndLink: FC<{
Expand Down Expand Up @@ -60,13 +62,18 @@ export const AccountLink: FC<{
*/
plain?: boolean

/**
* What part of the name should be highlighted (if any)
*/
highlightedPartOfName?: string | undefined

/**
* Any extra tooltips to display
*
* (Besides the content necessary because of potential shortening)
*/
extraTooltip?: ReactNode
}> = ({ scope, address, alwaysTrim, plain, extraTooltip }) => {
}> = ({ scope, address, alwaysTrim, plain, highlightedPartOfName, extraTooltip }) => {
const { isTablet } = useScreenSize()
const { name: accountName } = useAccountName(scope, address)
const to = RouteUtils.getAccountRoute(scope, address)
Expand Down Expand Up @@ -112,7 +119,7 @@ export const AccountLink: FC<{
<MaybeWithTooltip title={tooltipPostfix}>
{accountName ? (
<span>
{accountName} ({address})
<HighlightedText text={accountName} pattern={highlightedPartOfName} /> ({address})
</span>
) : (
address
Expand All @@ -128,7 +135,11 @@ export const AccountLink: FC<{
return (
<WithTypographyAndLink to={to} plain={plain} mobile>
<>
<AdaptiveTrimmer text={accountName} strategy="end" extraTooltip={extraTooltip} />
<AdaptiveHighlightedText
text={accountName}
pattern={highlightedPartOfName}
extraTooltip={extraTooltip}
/>
<AdaptiveTrimmer text={address} strategy="middle" extraTooltip={extraTooltip} />
</>
</WithTypographyAndLink>
Expand Down
12 changes: 10 additions & 2 deletions src/app/components/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ type AccountProps = {
isLoading: boolean
tokenPrices: AllTokenPrices
showLayer?: boolean
highlightedPartOfName: string | undefined
}

export const Account: FC<AccountProps> = ({ account, token, isLoading, tokenPrices, showLayer }) => {
export const Account: FC<AccountProps> = ({
account,
token,
isLoading,
tokenPrices,
showLayer,
highlightedPartOfName,
}) => {
const { t } = useTranslation()
const { isMobile } = useScreenSize()
const address = account ? account.address_eth ?? account.address : undefined
Expand Down Expand Up @@ -67,7 +75,7 @@ export const Account: FC<AccountProps> = ({ account, token, isLoading, tokenPric
<AccountAvatar address={account.address} />
</StyledListTitleWithAvatar>
<dd>
<AccountLink scope={account} address={address!} />
<AccountLink scope={account} address={address!} highlightedPartOfName={highlightedPartOfName} />
<CopyToClipboard value={address!} />
</dd>

Expand Down
3 changes: 3 additions & 0 deletions src/app/pages/AccountDetailsPage/AccountDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type AccountDetailsProps = {
account: RuntimeAccount | undefined
token: EvmToken | undefined
tokenPrices: AllTokenPrices
highlightedPartOfName?: string | undefined
}

export const AccountDetailsCard: FC<AccountDetailsProps> = ({
Expand All @@ -21,6 +22,7 @@ export const AccountDetailsCard: FC<AccountDetailsProps> = ({
account,
token,
tokenPrices,
highlightedPartOfName,
}) => {
const { t } = useTranslation()
return (
Expand All @@ -35,6 +37,7 @@ export const AccountDetailsCard: FC<AccountDetailsProps> = ({
account={account}
token={token}
tokenPrices={tokenPrices}
highlightedPartOfName={highlightedPartOfName}
/>
</SubPageCard>
)
Expand Down
4 changes: 3 additions & 1 deletion src/app/pages/AccountDetailsPage/AccountDetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const AccountDetailsView: FC<{
token?: EvmToken
tokenPrices: AllTokenPrices
showLayer?: boolean
}> = ({ isLoading, isError, account, token, tokenPrices, showLayer }) => {
highlightedPartOfName?: string | undefined
}> = ({ isLoading, isError, account, token, tokenPrices, showLayer, highlightedPartOfName }) => {
const { t } = useTranslation()
return isError ? (
<CardEmptyState label={t('account.cantLoadDetails')} />
Expand All @@ -23,6 +24,7 @@ export const AccountDetailsView: FC<{
isLoading={isLoading}
tokenPrices={tokenPrices}
showLayer={showLayer}
highlightedPartOfName={highlightedPartOfName}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const DeferredConsensusAccountDetails: FC<{
network: Network
address: string
tokenPrices: AllTokenPrices
highlightedPartOfName: string | undefined
showLayer?: boolean
}> = () =>
// {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export const DeferredRuntimeAccountDetails: FC<{
layer: Runtime
address: string
tokenPrices: AllTokenPrices
highlightedPartOfName: string | undefined
showLayer?: boolean
}> = ({ network, layer, address, tokenPrices, showLayer }) => {
}> = ({ network, layer, address, tokenPrices, highlightedPartOfName, showLayer }) => {
const { data, isLoading, isError } = useGetRuntimeAccountsAddress(network, layer, address)
return (
<AccountDetailsView
Expand All @@ -22,6 +23,7 @@ export const DeferredRuntimeAccountDetails: FC<{
account={data?.data}
tokenPrices={tokenPrices}
showLayer={showLayer}
highlightedPartOfName={highlightedPartOfName}
/>
)
}
3 changes: 2 additions & 1 deletion src/app/pages/AccountDetailsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const AccountDetailsPage: FC = () => {
const { t } = useTranslation()

const scope = useRequiredScopeParam()
const { address } = useLoaderData() as AddressLoaderData
const { address, searchTerm } = useLoaderData() as AddressLoaderData
const { account, isLoading: isAccountLoading, isError } = useAccount(scope, address)
const isContract = !!account?.evm_contract
const { token, isLoading: isTokenLoading } = useTokenInfo(scope, address, isContract)
Expand Down Expand Up @@ -62,6 +62,7 @@ export const AccountDetailsPage: FC = () => {
account={account}
token={token}
tokenPrices={tokenPrices}
highlightedPartOfName={searchTerm}
/>
<DappBanner scope={scope} ethAddress={account?.address_eth} />
<RouterTabs
Expand Down
2 changes: 2 additions & 0 deletions src/app/pages/SearchResultsPage/SearchResultsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const SearchResultsList: FC<{
network={item.network}
address={item.address}
tokenPrices={tokenPrices}
highlightedPartOfName={searchTerm}
showLayer={true}
/>
) : (
Expand All @@ -117,6 +118,7 @@ export const SearchResultsList: FC<{
layer={item.layer}
address={item.address}
tokenPrices={tokenPrices}
highlightedPartOfName={searchTerm}
showLayer={true}
/>
)
Expand Down

0 comments on commit cf0f431

Please sign in to comment.