Commit 04cfee67 authored by lewtran's avatar lewtran

Simplify import

parent ef6c0865
import xss from 'xss';
import escapeRegExp from 'lib/escapeRegExp'; import escapeRegExp from 'lib/escapeRegExp';
export default function highlightText(text: string, query: string) { export default function highlightText(text: string, query: string) {
const regex = new RegExp('(' + escapeRegExp(query) + ')', 'gi'); const regex = new RegExp('(' + escapeRegExp(query) + ')', 'gi');
return text.replace(regex, '<mark>$1</mark>'); return xss(text.replace(regex, '<mark>$1</mark>'));
} }
...@@ -65,7 +65,7 @@ const SearchResultListItem = ({ data, searchTerm, isLoading }: Props) => { ...@@ -65,7 +65,7 @@ const SearchResultListItem = ({ data, searchTerm, isLoading }: Props) => {
> >
<Skeleton <Skeleton
isLoaded={ !isLoading } isLoaded={ !isLoading }
dangerouslySetInnerHTML={{ __html: xss(highlightText(name, searchTerm)) }} dangerouslySetInnerHTML={{ __html: highlightText(name, searchTerm) }}
whiteSpace="nowrap" whiteSpace="nowrap"
overflow="hidden" overflow="hidden"
textOverflow="ellipsis" textOverflow="ellipsis"
...@@ -101,14 +101,14 @@ const SearchResultListItem = ({ data, searchTerm, isLoading }: Props) => { ...@@ -101,14 +101,14 @@ const SearchResultListItem = ({ data, searchTerm, isLoading }: Props) => {
isLoading={ isLoading } isLoading={ isLoading }
onClick={ handleLinkClick } onClick={ handleLinkClick }
> >
<span dangerouslySetInnerHTML={{ __html: xss(highlightText(data.name, searchTerm)) }}/> <span dangerouslySetInnerHTML={{ __html: highlightText(data.name, searchTerm) }}/>
</LinkInternal> </LinkInternal>
</Flex> </Flex>
); );
} }
case 'app': { case 'app': {
const title = <span dangerouslySetInnerHTML={{ __html: xss(highlightText(data.app.title, searchTerm)) }}/>; const title = <span dangerouslySetInnerHTML={{ __html: highlightText(data.app.title, searchTerm) }}/>;
return ( return (
<Flex alignItems="center"> <Flex alignItems="center">
<Image <Image
...@@ -252,8 +252,7 @@ const SearchResultListItem = ({ data, searchTerm, isLoading }: Props) => { ...@@ -252,8 +252,7 @@ const SearchResultListItem = ({ data, searchTerm, isLoading }: Props) => {
case 'contract': case 'contract':
case 'address': { case 'address': {
const shouldHighlightHash = data.address.toLowerCase() === searchTerm.toLowerCase(); const shouldHighlightHash = data.address.toLowerCase() === searchTerm.toLowerCase();
// eslint-disable-next-line max-len return data.name ? <span dangerouslySetInnerHTML={{ __html: shouldHighlightHash ? xss(data.name) : highlightText(data.name, searchTerm) }}/> : null;
return data.name ? <span dangerouslySetInnerHTML={{ __html: shouldHighlightHash ? xss(data.name) : xss(highlightText(data.name, searchTerm)) }}/> : null;
} }
default: default:
......
...@@ -68,7 +68,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading }: Props) => { ...@@ -68,7 +68,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading }: Props) => {
overflow="hidden" overflow="hidden"
textOverflow="ellipsis" textOverflow="ellipsis"
whiteSpace="nowrap" whiteSpace="nowrap"
dangerouslySetInnerHTML={{ __html: xss(highlightText(name, searchTerm)) }} dangerouslySetInnerHTML={{ __html: highlightText(name, searchTerm) }}
/> />
</LinkInternal> </LinkInternal>
{ data.is_verified_via_admin_panel && <Icon as={ verifiedToken } boxSize={ 4 } ml={ 1 } color="green.500"/> } { data.is_verified_via_admin_panel && <Icon as={ verifiedToken } boxSize={ 4 } ml={ 1 } color="green.500"/> }
...@@ -119,7 +119,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading }: Props) => { ...@@ -119,7 +119,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading }: Props) => {
</Flex> </Flex>
</Td> </Td>
<Td colSpan={ 2 } fontSize="sm" verticalAlign="middle"> <Td colSpan={ 2 } fontSize="sm" verticalAlign="middle">
<span dangerouslySetInnerHTML={{ __html: shouldHighlightHash ? xss(data.name) : xss(highlightText(data.name, searchTerm)) }}/> <span dangerouslySetInnerHTML={{ __html: shouldHighlightHash ? xss(data.name) : highlightText(data.name, searchTerm) }}/>
</Td> </Td>
</> </>
); );
...@@ -151,7 +151,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading }: Props) => { ...@@ -151,7 +151,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading }: Props) => {
isLoading={ isLoading } isLoading={ isLoading }
onClick={ handleLinkClick } onClick={ handleLinkClick }
> >
<span dangerouslySetInnerHTML={{ __html: xss(highlightText(data.name, searchTerm)) }}/> <span dangerouslySetInnerHTML={{ __html: highlightText(data.name, searchTerm) }}/>
</LinkInternal> </LinkInternal>
</Flex> </Flex>
</Td> </Td>
...@@ -169,7 +169,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading }: Props) => { ...@@ -169,7 +169,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading }: Props) => {
} }
case 'app': { case 'app': {
const title = <span dangerouslySetInnerHTML={{ __html: xss(highlightText(data.app.title, searchTerm)) }}/>; const title = <span dangerouslySetInnerHTML={{ __html: highlightText(data.app.title, searchTerm) }}/>;
return ( return (
<> <>
<Td fontSize="sm"> <Td fontSize="sm">
......
import { Box, Text, Grid, Flex, Icon } from '@chakra-ui/react'; import { Box, Text, Grid, Flex, Icon } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import xss from 'xss';
import type { SearchResultAddressOrContract } from 'types/api/search'; import type { SearchResultAddressOrContract } from 'types/api/search';
...@@ -25,7 +24,7 @@ const SearchBarSuggestAddress = ({ data, isMobile, searchTerm }: Props) => { ...@@ -25,7 +24,7 @@ const SearchBarSuggestAddress = ({ data, isMobile, searchTerm }: Props) => {
whiteSpace="nowrap" whiteSpace="nowrap"
textOverflow="ellipsis" textOverflow="ellipsis"
> >
<span dangerouslySetInnerHTML={{ __html: xss(highlightText(data.name, searchTerm)) }}/> <span dangerouslySetInnerHTML={{ __html: highlightText(data.name, searchTerm) }}/>
</Text> </Text>
); );
const isContractVerified = data.is_smart_contract_verified && <Icon as={ iconSuccess } color="green.500" ml={ 1 }/>; const isContractVerified = data.is_smart_contract_verified && <Icon as={ iconSuccess } color="green.500" ml={ 1 }/>;
......
import { Icon, Image, Flex, Text, useColorModeValue } from '@chakra-ui/react'; import { Icon, Image, Flex, Text, useColorModeValue } from '@chakra-ui/react';
import NextLink from 'next/link'; import NextLink from 'next/link';
import React from 'react'; import React from 'react';
import xss from 'xss';
import type { MarketplaceAppOverview } from 'types/client/marketplace'; import type { MarketplaceAppOverview } from 'types/client/marketplace';
...@@ -41,7 +40,7 @@ const SearchBarSuggestApp = ({ data, isMobile, searchTerm, onClick }: Props) => ...@@ -41,7 +40,7 @@ const SearchBarSuggestApp = ({ data, isMobile, searchTerm, onClick }: Props) =>
textOverflow="ellipsis" textOverflow="ellipsis"
ml={ 2 } ml={ 2 }
> >
<span dangerouslySetInnerHTML={{ __html: xss(highlightText(data.title, searchTerm)) }}/> <span dangerouslySetInnerHTML={{ __html: highlightText(data.title, searchTerm) }}/>
</Text> </Text>
{ data.external && <Icon as={ arrowIcon } boxSize={ 4 } verticalAlign="middle"/> } { data.external && <Icon as={ arrowIcon } boxSize={ 4 } verticalAlign="middle"/> }
</Flex> </Flex>
...@@ -71,7 +70,7 @@ const SearchBarSuggestApp = ({ data, isMobile, searchTerm, onClick }: Props) => ...@@ -71,7 +70,7 @@ const SearchBarSuggestApp = ({ data, isMobile, searchTerm, onClick }: Props) =>
w="200px" w="200px"
flexShrink={ 0 } flexShrink={ 0 }
> >
<span dangerouslySetInnerHTML={{ __html: xss(highlightText(data.title, searchTerm)) }}/> <span dangerouslySetInnerHTML={{ __html: highlightText(data.title, searchTerm) }}/>
</Text> </Text>
<Text <Text
variant="secondary" variant="secondary"
......
import { Grid, Text, Flex, Icon } from '@chakra-ui/react'; import { Grid, Text, Flex, Icon } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import xss from 'xss';
import type { SearchResultLabel } from 'types/api/search'; import type { SearchResultLabel } from 'types/api/search';
...@@ -25,7 +24,7 @@ const SearchBarSuggestLabel = ({ data, isMobile, searchTerm }: Props) => { ...@@ -25,7 +24,7 @@ const SearchBarSuggestLabel = ({ data, isMobile, searchTerm }: Props) => {
whiteSpace="nowrap" whiteSpace="nowrap"
textOverflow="ellipsis" textOverflow="ellipsis"
> >
<span dangerouslySetInnerHTML={{ __html: xss(highlightText(data.name, searchTerm)) }}/> <span dangerouslySetInnerHTML={{ __html: highlightText(data.name, searchTerm) }}/>
</Text> </Text>
); );
......
import { Grid, Text, Flex, Icon } from '@chakra-ui/react'; import { Grid, Text, Flex, Icon } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import xss from 'xss';
import type { SearchResultToken } from 'types/api/search'; import type { SearchResultToken } from 'types/api/search';
...@@ -26,7 +25,7 @@ const SearchBarSuggestToken = ({ data, isMobile, searchTerm }: Props) => { ...@@ -26,7 +25,7 @@ const SearchBarSuggestToken = ({ data, isMobile, searchTerm }: Props) => {
whiteSpace="nowrap" whiteSpace="nowrap"
textOverflow="ellipsis" textOverflow="ellipsis"
> >
<span dangerouslySetInnerHTML={{ __html: xss(highlightText(data.name + (data.symbol ? ` (${ data.symbol })` : ''), searchTerm)) }}/> <span dangerouslySetInnerHTML={{ __html: highlightText(data.name + (data.symbol ? ` (${ data.symbol })` : ''), searchTerm) }}/>
</Text> </Text>
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment