Files
self/app/src/utils/formatUserId.ts
Justin Hernandez 4721d12b09 SEL-570: Display user ID in prove screen (#790)
* Display user ID on prove screen

* Add user ID formatting util and tests

* Clarify user ID formatting

* fix nice

* add tests and save toggle wip

* update tests based on feedback

* say connected wallet when wallet
2025-07-25 12:58:33 -07:00

22 lines
666 B
TypeScript

// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
/**
* Format a user identifier for display.
*
* Hex addresses are truncated to keep the UI compact while
* UUIDs (and other string values) are shown in full.
*/
export function formatUserId(
userId: string | null | undefined,
userIdType: 'hex' | 'uuid' | undefined,
): string | null {
if (!userId) {
return null;
}
if (userIdType === 'hex') {
const address = userId.startsWith('0x') ? userId : `0x${userId}`;
return `${address.slice(0, 4)}...${address.slice(-4)}`;
}
return userId;
}