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

Truncated did label #2447

Merged
merged 1 commit into from
Aug 30, 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
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
Loading