Skip to content

Commit

Permalink
Truncated did label
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiaMineJP committed Aug 14, 2024
1 parent d92ed1d commit 71282c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/gui/src/components/did/DIDProfileDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Wallet } from '@chia-network/api';
import { useGetDIDsQuery } from '@chia-network/api-react';
import { DropdownActions, DropdownActionsProps, MenuItem } from '@chia-network/core';
import { DropdownActions, DropdownActionsProps, MenuItem, truncateValue } from '@chia-network/core';
import type { TruncateValueOptions } from '@chia-network/core/src/components/Truncate/Truncate';
import { Trans, t } from '@lingui/macro';
import { PermIdentity as PermIdentityIcon } from '@mui/icons-material';
import { ListItemIcon } from '@mui/material';
Expand All @@ -14,6 +15,7 @@ type DIDProfileDropdownProps = DropdownActionsProps & {
defaultTitle?: string | React.ReactElement;
currentDID?: string;
includeNoneOption?: boolean;
truncate?: TruncateValueOptions | boolean;
};

export default function DIDProfileDropdown(props: DIDProfileDropdownProps) {
Expand All @@ -23,6 +25,7 @@ export default function DIDProfileDropdown(props: DIDProfileDropdownProps) {
defaultTitle = t`All Profiles`,
currentDID = '',
includeNoneOption = false,
truncate,
...rest
} = props;
const { data: allDIDWallets, isLoading } = useGetDIDsQuery();
Expand Down Expand Up @@ -50,8 +53,15 @@ export default function DIDProfileDropdown(props: DIDProfileDropdownProps) {

const wallet = didWallets?.find((walletItem: Wallet) => walletItem.id === walletId);

return wallet?.name || defaultTitle;
}, [defaultTitle, didWallets, isLoading, walletId]);
const retVal = wallet?.name || defaultTitle;
if (!truncate) {
return retVal;
}

const truncateOptions = truncate === true ? {} : truncate;

return truncateValue(retVal, truncateOptions);
}, [defaultTitle, didWallets, isLoading, walletId, truncate]);

function handleWalletChange(newWalletId?: number) {
onChange?.(newWalletId);
Expand Down
6 changes: 6 additions & 0 deletions packages/gui/src/components/signVerify/SigningEntityDID.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import DIDProfileDropdown from '../did/DIDProfileDropdown';

import { SignMessageEntityType, SignMessageDIDEntity } from './SignMessageEntities';

const TRUNCATE_OPTIONS = {
leftLength: 12,
rightLength: 12,
};

export type SigningEntityDIDProps = {
entityName: string;
entityValueName: string;
Expand Down Expand Up @@ -72,6 +77,7 @@ export default function SigningEntityDID(props: SigningEntityDIDProps) {
color="primary"
disabled={isLoading}
fullWidth
truncate={TRUNCATE_OPTIONS}
/>
<TextField
label={<Trans>DID</Trans>}
Expand Down

0 comments on commit 71282c2

Please sign in to comment.