Skip to content

Commit

Permalink
feat: extract formatEllipsized util, use in gateway for node ID
Browse files Browse the repository at this point in the history
  • Loading branch information
wbobeirne committed Aug 31, 2023
1 parent d5bb69a commit bda9484
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/gateway-ui/src/components/GatewayCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const GatewayCard = React.memo(function GatewayCard({
children,
}: GatewayCardProps) {
return (
<Card w='100%' h='100%' maxWidth='100%' maxH='100%'>
<Card w='100%' maxWidth='100%'>
<CardHeader>
<Text size='lg' fontWeight='600'>
{title}
Expand Down
6 changes: 3 additions & 3 deletions apps/gateway-ui/src/components/InfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Box,
useClipboard,
} from '@chakra-ui/react';
import { useTranslation } from '@fedimint/utils';
import { formatEllipsized, useTranslation } from '@fedimint/utils';
import { GatewayCard } from '.';
import { ReactComponent as CopyIcon } from '../assets/svgs/copy.svg';
import { ReactComponent as LinkIcon } from '../assets/svgs/linkIcon.svg';
Expand All @@ -27,7 +27,7 @@ export const InfoCard = React.memo(function InfoCard(

return (
<GatewayCard title={t('info-card.card_header')}>
<Flex gap='8px'>
<Flex gap='8px' mb='8px'>
<Text
fontSize='md'
color={theme.colors.gray[900]}
Expand All @@ -37,7 +37,7 @@ export const InfoCard = React.memo(function InfoCard(
cursor='pointer'
onClick={onCopy}
>
{nodeId}
{formatEllipsized(nodeId)}
</Text>
<Box>
{hasCopied ? (
Expand Down
9 changes: 3 additions & 6 deletions apps/guardian-ui/src/components/GatewaysCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ import {
} from '@chakra-ui/react';
import { ConfigResponse, Gateway } from '../types';
import { Table, TableColumn, TableRow } from '@fedimint/ui';
import { useTranslation } from '@fedimint/utils';
import { useTranslation, formatEllipsized } from '@fedimint/utils';
import { useAdminContext } from '../hooks';
import { LightningModuleRpc } from '../GuardianApi';

const ellipsisSandwich = (text: string) =>
`${text.substring(0, 6)}...${text.substring(text.length - 6)}`;

type TableKey = 'nodeId' | 'gatewayId' | 'fee';

interface GatewaysCardProps {
Expand Down Expand Up @@ -79,7 +76,7 @@ export const GatewaysCard: React.FC<GatewaysCardProps> = ({ config }) => {
key: gateway_id,
nodeId: (
<Flex direction='column' gap='4px'>
<Text>{ellipsisSandwich(node_pub_key)}</Text>
<Text>{formatEllipsized(node_pub_key)}</Text>
<Text size='xs'>
<Link
color={theme.colors.blue[600]}
Expand All @@ -94,7 +91,7 @@ export const GatewaysCard: React.FC<GatewaysCardProps> = ({ config }) => {
</Text>
</Flex>
),
gatewayId: ellipsisSandwich(gateway_id),
gatewayId: formatEllipsized(gateway_id),
fee: fee,
outgoingFee: fee,
};
Expand Down
11 changes: 11 additions & 0 deletions packages/utils/src/format.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Given a string, turn it into an "ellipsis sandwich" with the start and
* end showing. If the text is shorter than it would be with an ellipsis,
* the full string is returned instead.
*/
export function formatEllipsized(text: string, size = 6) {
if (text.length <= size * 2 + 3) {
return text;
}
return `${text.substring(0, size)}...${text.substring(text.length - size)}`;
}
1 change: 1 addition & 0 deletions packages/utils/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './i18n';
export * from './format';

0 comments on commit bda9484

Please sign in to comment.