Skip to content

Commit

Permalink
Metadata: show Notes
Browse files Browse the repository at this point in the history
Fixes #2174
  • Loading branch information
tom2drum committed Aug 26, 2024
1 parent 0684b06 commit 0803723
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/address/parseMetaPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default function parseMetaPayload(meta: AddressMetadataTag['meta']): Addr
'appLogoURL',
'appActionButtonText',
'warpcastHandle',
'data',
'alertBgColor',
'alertTextColor',
];

for (const stringField of stringFields) {
Expand Down
12 changes: 12 additions & 0 deletions mocks/metadata/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,15 @@ export const warpcastTag: AddressMetadataTagApi = {
warpcastHandle: 'duckYduck',
},
};

export const noteTag: AddressMetadataTagApi = {
slug: 'scam-tag',
name: 'Phish 🐟',
tagType: 'note',
ordinal: 100,
meta: {
alertBgColor: 'deeppink',
alertTextColor: 'white',
data: '<b>Warning!</b> This is scam! See the <a href="https://example.com" target="_blank">report</a>',
},
};
2 changes: 1 addition & 1 deletion theme/components/Alert/Alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function getBg(props: StyleFunctionProps) {
const { theme, colorScheme: c } = props;
const darkBg = transparentize(`${ c }.200`, 0.16)(theme);
return {
light: `colors.${ c }.${ c === 'red' ? '50' : '100' }`,
light: `colors.${ c }.100`,
dark: darkBg,
};
}
Expand Down
3 changes: 3 additions & 0 deletions types/api/addressMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export interface AddressMetadataTagApi extends Omit<AddressMetadataTag, 'meta'>
appLogoURL?: string;
appActionButtonText?: string;
warpcastHandle?: string;
data?: string;
alertBgColor?: string;
alertTextColor?: string;
} | null;
}

Expand Down
13 changes: 13 additions & 0 deletions ui/address/details/AddressMetadataAlert.pw.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Box } from '@chakra-ui/react';
import React from 'react';

import * as metadataMock from 'mocks/metadata/address';
import { test, expect } from 'playwright/lib';

import AddressMetadataAlert from './AddressMetadataAlert';

test('base view', async({ render }) => {
const component = await render(<Box mt={ 1 }><AddressMetadataAlert tags={ [ metadataMock.noteTag ] }/></Box>);

await expect(component).toHaveScreenshot();
});
43 changes: 43 additions & 0 deletions ui/address/details/AddressMetadataAlert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Alert } from '@chakra-ui/react';
import React from 'react';

import type { AddressMetadataTagFormatted } from 'types/client/addressMetadata';

interface Props {
tags: Array<AddressMetadataTagFormatted> | undefined;
}

const AddressMetadataAlert = ({ tags }: Props) => {
const noteTag = tags?.find(({ tagType }) => tagType === 'note');
if (!noteTag) {
return null;
}

const content = noteTag.meta?.data;

if (!content) {
return null;
}

return (
<Alert
mt="-4px"
mb={ 6 }
status="error"
bgColor={ noteTag.meta?.alertBgColor }
color={ noteTag.meta?.alertTextColor }
whiteSpace="pre-wrap"
sx={{
'& a': {
color: 'link',
_hover: {
color: 'link_hovered',
},
},
}}
dangerouslySetInnerHTML={{ __html: content }}
/>
);
};

export default React.memo(AddressMetadataAlert);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions ui/pages/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import AddressTxs from 'ui/address/AddressTxs';
import AddressUserOps from 'ui/address/AddressUserOps';
import AddressWithdrawals from 'ui/address/AddressWithdrawals';
import AddressFavoriteButton from 'ui/address/details/AddressFavoriteButton';
import AddressMetadataAlert from 'ui/address/details/AddressMetadataAlert';
import AddressQrCode from 'ui/address/details/AddressQrCode';
import AddressEnsDomains from 'ui/address/ensDomains/AddressEnsDomains';
import SolidityscanReport from 'ui/address/SolidityscanReport';
Expand Down Expand Up @@ -345,6 +346,8 @@ const AddressPageContent = () => {
secondRow={ titleSecondRow }
isLoading={ isLoading }
/>
{ !addressMetadataQuery.isPending &&
<AddressMetadataAlert tags={ addressMetadataQuery.data?.addresses?.[hash.toLowerCase()]?.tags }/> }
{ config.features.metasuites.isEnabled && <Box display="none" id="meta-suites__address" data-ready={ !isLoading }/> }
<AddressDetails addressQuery={ addressQuery } scrollRef={ tabsScrollRef }/>
{ /* should stay before tabs to scroll up with pagination */ }
Expand Down

0 comments on commit 0803723

Please sign in to comment.