Skip to content

Commit

Permalink
Filecoin: display address id instead of hash (#2497)
Browse files Browse the repository at this point in the history
  • Loading branch information
isstuev authored Jan 6, 2025
1 parent de43f3d commit d461297
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ui/shared/entities/address/AddressEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import AddressIdenticon from './AddressIdenticon';

type LinkProps = EntityBase.LinkBaseProps & Pick<EntityProps, 'address'>;

const getDisplayedAddress = (address: AddressProp, altHash?: string) => {
return address.filecoin?.robust ?? address.filecoin?.id ?? altHash ?? address.hash;
};

const Link = chakra((props: LinkProps) => {
const defaultHref = route({ pathname: '/address/[hash]', query: { ...props.query, hash: props.address.hash } });

Expand Down Expand Up @@ -80,7 +84,7 @@ const Icon = (props: IconProps) => {
<Flex marginRight={ styles.marginRight }>
<AddressIdenticon
size={ props.size === 'lg' ? 30 : 20 }
hash={ props.address.filecoin?.robust ?? props.address.hash }
hash={ getDisplayedAddress(props.address) }
/>
</Flex>
);
Expand All @@ -89,6 +93,7 @@ const Icon = (props: IconProps) => {
export type ContentProps = Omit<EntityBase.ContentBaseProps, 'text'> & Pick<EntityProps, 'address'> & { altHash?: string };

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

Expand All @@ -102,7 +107,9 @@ const Content = chakra((props: ContentProps) => {
const label = (
<VStack gap={ 0 } py={ 1 } color="inherit">
<Box fontWeight={ 600 } whiteSpace="pre-wrap" wordBreak="break-word">{ nameText }</Box>
<Box whiteSpace="pre-wrap" wordBreak="break-word">{ props.address.filecoin?.robust ?? props.altHash ?? props.address.hash }</Box>
<Box whiteSpace="pre-wrap" wordBreak="break-word">
{ displayedAddress }
</Box>
</VStack>
);

Expand All @@ -118,7 +125,7 @@ const Content = chakra((props: ContentProps) => {
return (
<EntityBase.Content
{ ...props }
text={ props.address.filecoin?.robust ?? props.altHash ?? props.address.hash }
text={ displayedAddress }
/>
);
});
Expand All @@ -129,7 +136,7 @@ const Copy = (props: CopyProps) => {
return (
<EntityBase.Copy
{ ...props }
text={ props.address.filecoin?.robust ?? props.altHash ?? props.address.hash }
text={ getDisplayedAddress(props.address, props.altHash) }
/>
);
};
Expand Down

0 comments on commit d461297

Please sign in to comment.