Commit 5d6fd12d authored by Igor Stuev's avatar Igor Stuev Committed by GitHub

Merge pull request #2289 from blockscout/fe-2236

Public tags: improvement batch
parents 391b20fe b9ace387
...@@ -102,3 +102,14 @@ export const noteTag: AddressMetadataTagApi = { ...@@ -102,3 +102,14 @@ export const noteTag: AddressMetadataTagApi = {
data: '<b>Warning!</b> This is scam! See the <a href="https://example.com" target="_blank">report</a>', data: '<b>Warning!</b> This is scam! See the <a href="https://example.com" target="_blank">report</a>',
}, },
}; };
export const noteTag2: AddressMetadataTagApi = {
slug: 'note0',
name: 'note_0',
tagType: 'note',
ordinal: 0,
meta: {
alertStatus: 'info',
data: 'The token MILF was launched on May 13, 2021. The maximum total supply of the token is 100 billion.',
},
};
...@@ -6,7 +6,7 @@ import { test, expect } from 'playwright/lib'; ...@@ -6,7 +6,7 @@ import { test, expect } from 'playwright/lib';
import AddressMetadataAlert from './AddressMetadataAlert'; import AddressMetadataAlert from './AddressMetadataAlert';
test('base view', async({ render }) => { test('base view', async({ render }) => {
const component = await render(<AddressMetadataAlert tags={ [ metadataMock.noteTag ] }/>); const component = await render(<AddressMetadataAlert tags={ [ metadataMock.noteTag, metadataMock.noteTag2 ] }/>);
await expect(component).toHaveScreenshot(); await expect(component).toHaveScreenshot();
}); });
import { Alert, chakra } from '@chakra-ui/react'; import { Alert, Flex, chakra } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import type { AddressMetadataTagFormatted } from 'types/client/addressMetadata'; import type { AddressMetadataTagFormatted } from 'types/client/addressMetadata';
...@@ -9,35 +9,34 @@ interface Props { ...@@ -9,35 +9,34 @@ interface Props {
} }
const AddressMetadataAlert = ({ tags, className }: Props) => { const AddressMetadataAlert = ({ tags, className }: Props) => {
const noteTag = tags?.find(({ tagType }) => tagType === 'note'); const noteTags = tags?.filter(({ tagType }) => tagType === 'note').filter(({ meta }) => meta?.data);
if (!noteTag) {
return null;
}
const content = noteTag.meta?.data;
if (!content) { if (!noteTags?.length) {
return null; return null;
} }
return ( return (
<Alert <Flex flexDir="column" gap={ 3 } className={ className }>
className={ className } { noteTags.map((noteTag) => (
status={ noteTag.meta?.alertStatus ?? 'error' } <Alert
bgColor={ noteTag.meta?.alertBgColor } key={ noteTag.name }
color={ noteTag.meta?.alertTextColor } status={ noteTag.meta?.alertStatus ?? 'error' }
whiteSpace="pre-wrap" bgColor={ noteTag.meta?.alertBgColor }
display="inline-block" color={ noteTag.meta?.alertTextColor }
sx={{ whiteSpace="pre-wrap"
'& a': { display="inline-block"
color: 'link', sx={{
_hover: { '& a': {
color: 'link_hovered', color: 'link',
}, _hover: {
}, color: 'link_hovered',
}} },
dangerouslySetInnerHTML={{ __html: content }} },
/> }}
dangerouslySetInnerHTML={{ __html: noteTag.meta?.data ?? '' }}
/>
)) }
</Flex>
); );
}; };
......
...@@ -282,7 +282,7 @@ const AddressPageContent = () => { ...@@ -282,7 +282,7 @@ const AddressPageContent = () => {
{ slug: 'mud', name: 'MUD World', tagType: 'custom' as const, ordinal: -10 } : { slug: 'mud', name: 'MUD World', tagType: 'custom' as const, ordinal: -10 } :
undefined, undefined,
...formatUserTags(addressQuery.data), ...formatUserTags(addressQuery.data),
...(addressMetadataQuery.data?.addresses?.[hash.toLowerCase()]?.tags || []), ...(addressMetadataQuery.data?.addresses?.[hash.toLowerCase()]?.tags.filter(tag => tag.tagType !== 'note') || []),
].filter(Boolean).sort(sortEntityTags); ].filter(Boolean).sort(sortEntityTags);
}, [ addressMetadataQuery.data, addressQuery.data, hash, isSafeAddress, userOpsAccountQuery.data, mudTablesCountQuery.data, usernameApiTag ]); }, [ addressMetadataQuery.data, addressQuery.data, hash, isSafeAddress, userOpsAccountQuery.data, mudTablesCountQuery.data, usernameApiTag ]);
......
...@@ -45,7 +45,7 @@ const EntityTags = ({ tags, className, isLoading }: Props) => { ...@@ -45,7 +45,7 @@ const EntityTags = ({ tags, className, isLoading }: Props) => {
+{ tags.length - visibleNum } +{ tags.length - visibleNum }
</Tag> </Tag>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent w="300px"> <PopoverContent maxW="300px" w="auto">
<PopoverBody > <PopoverBody >
<Flex columnGap={ 2 } rowGap={ 2 } flexWrap="wrap"> <Flex columnGap={ 2 } rowGap={ 2 } flexWrap="wrap">
{ tags.slice(visibleNum).map((tag) => <EntityTag key={ tag.slug } data={ tag }/>) } { tags.slice(visibleNum).map((tag) => <EntityTag key={ tag.slug } data={ tag }/>) }
......
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