Skip to content

Commit

Permalink
Implementation name behind proxy name (#2071)
Browse files Browse the repository at this point in the history
* icon for proxy contract

* add custom tooltip for proxy contract

* add name to tooltip and refactor

* tests

* center the popup content
  • Loading branch information
tom2drum authored Jul 8, 2024
1 parent 18b419e commit 45eb874
Show file tree
Hide file tree
Showing 18 changed files with 173 additions and 29 deletions.
4 changes: 4 additions & 0 deletions icons/contracts/proxy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions lib/contexts/addressHighlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export function AddressHighlightProvider({ children }: AddressHighlightProviderP
);
}

export function useAddressHighlightContext() {
export function useAddressHighlightContext(disabled?: boolean) {
const context = React.useContext(AddressHighlightContext);
if (context === undefined) {
if (context === undefined || disabled) {
return null;
}
return context;
Expand Down
11 changes: 11 additions & 0 deletions mocks/address/implementations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const multiple = [
{ address: '0xA84d24bD8ACE4d349C5f8c5DeeDd8bc071Ce5e2b', name: null },
{ address: '0xc9e91eDeA9DC16604022e4E5b437Df9c64EdB05A', name: 'Diamond' },
{ address: '0x2041832c62C0F89426b48B5868146C0b1fcd23E7', name: null },
{ address: '0x5f7DC6ECcF05594429671F83cc0e42EE18bC0974', name: 'VariablePriceFacet' },
{ address: '0x7abC92E242e88e4B0d6c5Beb4Df80e94D2c8A78c', name: null },
{ address: '0x84178a0c58A860eCCFB7E3aeA64a09543062A356', name: 'MultiSaleFacet' },
{ address: '0x33aD95537e63e9f09d96dE201e10715Ed40D9400', name: 'SVGTemplatesFacet' },
{ address: '0xfd86Aa7f902185a8Df9859c25E4BF52D3DaDd9FA', name: 'ERC721AReceiverFacet' },
{ address: '0x6945a35df18e59Ce09fec4B6cD3C4F9cFE6369de', name: null },
];
1 change: 1 addition & 0 deletions public/icons/name.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
| "clock"
| "coins/bitcoin"
| "collection"
| "contracts/proxy"
| "contracts/regular_many"
| "contracts/regular"
| "contracts/verified_many"
Expand Down
4 changes: 1 addition & 3 deletions types/api/addressParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export interface UserTags {

export type AddressParamBasic = {
hash: string;
// API doesn't return hash in this model yet
// will be fixed in the future releases
implementations: Array<Omit<AddressImplementation, 'address'>> | null;
implementations: Array<AddressImplementation> | null;
name: string | null;
is_contract: boolean;
is_verified: boolean | null;
Expand Down
2 changes: 1 addition & 1 deletion ui/deposits/optimisticL2/OptimisticDepositsListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const OptimisticDepositsListItem = ({ item, isLoading }: Props) => {
<ListItemMobileGrid.Label isLoading={ isLoading }>L1 txn origin</ListItemMobileGrid.Label>
<ListItemMobileGrid.Value>
<AddressEntityL1
address={{ hash: item.l1_tx_origin, name: '', is_contract: false, is_verified: false, ens_domain_name: null }}
address={{ hash: item.l1_tx_origin, name: '', is_contract: false, is_verified: false, ens_domain_name: null, implementations: null }}
isLoading={ isLoading }
noCopy
truncation="constant"
Expand Down
2 changes: 1 addition & 1 deletion ui/deposits/optimisticL2/OptimisticDepositsTableItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const OptimisticDepositsTableItem = ({ item, isLoading }: Props) => {
</Td>
<Td verticalAlign="middle">
<AddressEntityL1
address={{ hash: item.l1_tx_origin, name: '', is_contract: false, is_verified: false, ens_domain_name: null }}
address={{ hash: item.l1_tx_origin, name: '', is_contract: false, is_verified: false, ens_domain_name: null, implementations: null }}
isLoading={ isLoading }
truncation="constant"
noCopy
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ const AddressPageContent = () => {
/>
) }
<AddressEntity
address={{ ...addressQuery.data, hash, name: '', ens_domain_name: '' }}
address={{ ...addressQuery.data, hash, name: '', ens_domain_name: '', implementations: null }}
isLoading={ isLoading }
fontFamily="heading"
fontSize="lg"
Expand Down
57 changes: 55 additions & 2 deletions ui/shared/entities/address/AddressEntity.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';

import { AddressHighlightProvider } from 'lib/contexts/addressHighlight';
import * as addressMock from 'mocks/address/address';
import * as implementationsMock from 'mocks/address/implementations';
import { test, expect } from 'playwright/lib';

import AddressEntity from './AddressEntity';
Expand Down Expand Up @@ -30,7 +31,7 @@ test.describe('contract', () => {
test('unverified', async({ render, page }) => {
const component = await render(
<AddressEntity
address={{ ...addressMock.contract, is_verified: false }}
address={{ ...addressMock.contract, is_verified: false, implementations: null }}
/>,
);

Expand All @@ -41,14 +42,66 @@ test.describe('contract', () => {
test('verified', async({ render }) => {
const component = await render(
<AddressEntity
address={{ ...addressMock.contract, is_verified: true }}
address={{ ...addressMock.contract, is_verified: true, implementations: null }}
/>,
);

await expect(component).toHaveScreenshot();
});
});

test.describe('proxy contract', () => {
test.use({ viewport: { width: 500, height: 300 } });

test('with implementation name', async({ render, page }) => {
const component = await render(
<AddressEntity
address={ addressMock.contract }
/>,
);

await component.getByText(/home/i).hover();
await expect(page.getByText('Proxy contract')).toBeVisible();
await expect(page).toHaveScreenshot();
});

test('without implementation name', async({ render, page }) => {
const component = await render(
<AddressEntity
address={{ ...addressMock.contract, implementations: [ { address: addressMock.contract.implementations?.[0].address } ] }}
/>,
);

await component.getByText(/eternal/i).hover();
await expect(page.getByText('Proxy contract')).toBeVisible();
await expect(page).toHaveScreenshot();
});

test('without any name', async({ render, page }) => {
const component = await render(
<AddressEntity
address={{ ...addressMock.contract, name: undefined, implementations: [ { address: addressMock.contract.implementations?.[0].address } ] }}
/>,
);

await component.getByText(addressMock.contract.hash.slice(0, 4)).hover();
await expect(page.getByText('Proxy contract')).toBeVisible();
await expect(page).toHaveScreenshot();
});

test('with multiple implementations', async({ render, page }) => {
const component = await render(
<AddressEntity
address={{ ...addressMock.contract, implementations: implementationsMock.multiple }}
/>,
);

await component.getByText(/eternal/i).hover();
await expect(page.getByText('Proxy contract')).toBeVisible();
await expect(page).toHaveScreenshot();
});
});

test.describe('loading', () => {
test('without alias', async({ render }) => {
const component = await render(
Expand Down
39 changes: 20 additions & 19 deletions ui/shared/entities/address/AddressEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useAddressHighlightContext } from 'lib/contexts/addressHighlight';
import * as EntityBase from 'ui/shared/entities/base/components';

import { getIconProps } from '../base/utils';
import AddressEntityContentProxy from './AddressEntityContentProxy';
import AddressIdenticon from './AddressIdenticon';

type LinkProps = EntityBase.LinkBaseProps & Pick<EntityProps, 'address'>;
Expand Down Expand Up @@ -57,27 +58,18 @@ const Icon = (props: IconProps) => {
);
}

if (props.address.is_verified) {
return (
<Tooltip label="Verified contract">
<span>
<EntityBase.Icon
{ ...props }
name="contracts/verified"
color="green.500"
borderRadius={ 0 }
/>
</span>
</Tooltip>
);
}
const isProxy = Boolean(props.address.implementations?.length);
const isVerified = isProxy ? props.address.is_verified && props.address.implementations?.every(({ name }) => Boolean(name)) : props.address.is_verified;
const contractIconName: EntityBase.IconBaseProps['name'] = props.address.is_verified ? 'contracts/verified' : 'contracts/regular';
const label = (isVerified ? 'verified ' : '') + (isProxy ? 'proxy contract' : 'contract');

return (
<Tooltip label="Contract">
<Tooltip label={ label.slice(0, 1).toUpperCase() + label.slice(1) }>
<span>
<EntityBase.Icon
{ ...props }
name="contracts/regular"
name={ isProxy ? 'contracts/proxy' : contractIconName }
color={ isVerified ? 'green.500' : undefined }
borderRadius={ 0 }
/>
</span>
Expand All @@ -95,12 +87,18 @@ const Icon = (props: IconProps) => {
);
};

type ContentProps = Omit<EntityBase.ContentBaseProps, 'text'> & Pick<EntityProps, 'address'>;
export type ContentProps = Omit<EntityBase.ContentBaseProps, 'text'> & Pick<EntityProps, 'address'>;

const Content = chakra((props: ContentProps) => {
const nameTag = props.address.metadata?.tags.find(tag => tag.tagType === 'name')?.name;
const nameText = nameTag || props.address.ens_domain_name || props.address.name;

const isProxy = props.address.implementations && props.address.implementations.length > 0;

if (isProxy) {
return <AddressEntityContentProxy { ...props }/>;
}

if (nameText) {
const label = (
<VStack gap={ 0 } py={ 1 } color="inherit">
Expand Down Expand Up @@ -140,15 +138,18 @@ const Copy = (props: CopyProps) => {
const Container = EntityBase.Container;

export interface EntityProps extends EntityBase.EntityBaseProps {
address: Pick<AddressParam, 'hash' | 'name' | 'is_contract' | 'is_verified' | 'ens_domain_name' | 'metadata'>;
address: Pick<AddressParam,
'hash' | 'name' | 'is_contract' | 'is_verified' | 'implementations' | 'ens_domain_name' | 'metadata'
>;
isSafeAddress?: boolean;
noHighlight?: boolean;
}

const AddressEntry = (props: EntityProps) => {
const linkProps = _omit(props, [ 'className' ]);
const partsProps = _omit(props, [ 'className', 'onClick' ]);

const context = useAddressHighlightContext();
const context = useAddressHighlightContext(props.noHighlight);

return (
<Container
Expand Down
72 changes: 72 additions & 0 deletions ui/shared/entities/address/AddressEntityContentProxy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Box, DarkMode, Popover, PopoverBody, PopoverContent, PopoverTrigger, Portal, useColorModeValue, Flex, PopoverArrow } from '@chakra-ui/react';
import React from 'react';

import * as EntityBase from 'ui/shared/entities/base/components';

import type { ContentProps } from './AddressEntity';
import AddressEntity from './AddressEntity';

const AddressEntityContentProxy = (props: ContentProps) => {
const bgColor = useColorModeValue('gray.700', 'gray.900');

const implementations = props.address.implementations;

const handleClick = React.useCallback((event: React.MouseEvent) => {
event.stopPropagation();
}, []);

if (!implementations || implementations.length === 0) {
return null;
}

const colNum = Math.min(implementations.length, 3);
const implementationName = implementations.length === 1 && implementations[0].name ? implementations[0].name : undefined;

return (
<Popover trigger="hover" isLazy>
<PopoverTrigger>
<Box display="inline-flex" w="100%">
<EntityBase.Content
{ ...props }
truncation={ implementationName || props.address.name ? 'tail' : 'dynamic' }
text={ implementationName || props.address.name || props.address.hash }
/>
</Box>
</PopoverTrigger>
<Portal>
<DarkMode>
<PopoverContent bgColor={ bgColor } w="fit-content" borderRadius="sm" maxW={{ base: '100vw', lg: '410px' }} onClick={ handleClick }>
<PopoverArrow bgColor={ bgColor }/>
<PopoverBody color="white" p={ 2 } fontSize="sm" lineHeight={ 5 } textAlign="center">
<Box fontWeight={ 600 }>
Proxy contract
{ props.address.name ? ` (${ props.address.name })` : '' }
</Box>
<AddressEntity address={{ hash: props.address.hash }} noLink noIcon noHighlight justifyContent="center"/>
<Box fontWeight={ 600 } mt={ 2 }>
Implementation{ implementations.length > 1 ? 's' : '' }
{ implementationName ? ` (${ implementationName })` : '' }
</Box>
<Flex flexWrap="wrap" columnGap={ 3 }>
{ implementations.map((item) => (
<AddressEntity
key={ item.address }
address={{ hash: item.address }}
noLink
noIcon
noHighlight
minW={ `calc((100% - ${ colNum - 1 } * 12px) / ${ colNum })` }
flex={ 1 }
justifyContent={ colNum === 1 ? 'center' : undefined }
/>
)) }
</Flex>
</PopoverBody>
</PopoverContent>
</DarkMode>
</Portal>
</Popover>
);
};

export default React.memo(AddressEntityContentProxy);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions ui/shared/entities/base/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const Content = chakra(({ className, isLoading, asProp, text, truncation = 'dyna
tailLength={ tailLength }
/>
);
case 'tail':
case 'none':
return <chakra.span as={ asProp }>{ text }</chakra.span>;
}
Expand All @@ -153,6 +154,7 @@ const Content = chakra(({ className, isLoading, asProp, text, truncation = 'dyna
isLoaded={ !isLoading }
overflow="hidden"
whiteSpace="nowrap"
textOverflow={ truncation === 'tail' ? 'ellipsis' : undefined }
>
{ children }
</Skeleton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const SearchBarSuggestAddress = ({ data, isMobile, searchTerm }: Props) => {
name: '',
is_verified: data.is_smart_contract_verified,
ens_domain_name: null,
implementations: null,
}}
/>
);
Expand Down
1 change: 1 addition & 0 deletions ui/tokens/TokensTableItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const TokensTableItem = ({
is_contract: true,
is_verified: false,
ens_domain_name: null,
implementations: null,
};

return (
Expand Down

0 comments on commit 45eb874

Please sign in to comment.