Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata: show Notes #2191

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading