Skip to content

Commit

Permalink
feat: better lightning card
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Sep 6, 2024
1 parent 7140edf commit 8f25ad2
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 74 deletions.
5 changes: 5 additions & 0 deletions apps/gateway-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export const App = React.memo(function Admin(): JSX.Element {
<LightningCard
nodeId={gatewayInfo.gateway_id}
network={gatewayInfo.network}
alias={gatewayInfo.lightning_alias}
mode={gatewayInfo.lightning_mode}
pubkey={gatewayInfo.lightning_pub_key}
blockHeight={gatewayInfo.block_height}
syncedToChain={gatewayInfo.synced_to_chain}
/>
<FederationsTable
unit={unit}
Expand Down
134 changes: 80 additions & 54 deletions apps/gateway-ui/src/components/lightning/LightningCard.tsx
Original file line number Diff line number Diff line change
@@ -1,83 +1,109 @@
import React from 'react';
import {
Text,
useTheme,
Flex,
Link,
Box,
useClipboard,
SimpleGrid,
} from '@chakra-ui/react';
import { Network } from '@fedimint/types';
import { LightningMode, Network } from '@fedimint/types';
import { formatEllipsized, getNodeUrl, 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';

interface LightningCardProps {
nodeId: string;
network?: Network;
network: Network;
alias: string;
mode: LightningMode;
pubkey: string;
blockHeight: number;
syncedToChain: boolean;
}

export const LightningCard = React.memo(function LightningCard({
nodeId,
network,
alias,
mode,
pubkey,
blockHeight,
syncedToChain,
}: LightningCardProps): JSX.Element {
const { t } = useTranslation();
const theme = useTheme();
const { onCopy, hasCopied } = useClipboard(nodeId);
const url = getNodeUrl(nodeId, network);

const InfoItem = ({
label,
value,
}: {
label: string;
value: React.ReactNode;
}) => (
<Flex>
<Text fontWeight='bold' mr={2}>
{label}:
</Text>
<Text>{value}</Text>
</Flex>
);

return (
<GatewayCard title={t('info-card.card_header')}>
<Flex alignItems='center'>
<Text
fontSize='md'
color={theme.colors.gray[900]}
fontFamily={theme.fonts.body}
mr='2'
>
{formatEllipsized(nodeId, 24)}
</Text>
<Box>
{hasCopied ? (
<Text
fontSize='xs'
fontWeight='semibold'
color={theme.colors.green[500]}
bgColor={theme.colors.green[50]}
p='1'
px='2'
borderRadius='full'
>
{t('common.copied')}
</Text>
) : (
<Box
as={CopyIcon}
color={theme.colors.gray[500]}
height='20px'
width='20px'
onClick={onCopy}
cursor='pointer'
_hover={{ color: theme.colors.gray[700] }}
/>
)}
</Box>
</Flex>
<Link
fontSize='sm'
color={theme.colors.blue[600]}
fontFamily={theme.fonts.body}
href={url.toString()}
target='_blank'
rel='noreferrer'
display='flex'
alignItems='center'
_hover={{ textDecoration: 'underline', color: theme.colors.blue[700] }}
>
{t('federation-card.view-link-on', { host: url.host })}
<Box as={LinkIcon} ml='1' boxSize='4' />
</Link>
<GatewayCard title={t('info-card.card-header')}>
<SimpleGrid columns={2} spacing={4}>
<InfoItem
label={t('info-card.node-id')}
value={
<Flex alignItems='center' gap={2}>
{formatEllipsized(nodeId, 8)}
<Box
ml={2}
as={CopyIcon}
color='gray.500'
height='20px'
width='20px'
onClick={onCopy}
cursor='pointer'
_hover={{ color: 'gray.700' }}
/>
{hasCopied && (
<Text fontSize='xs' color='green.500' ml={2}>
{t('common.copied')}
</Text>
)}
<Link
fontSize='sm'
color='blue.600'
href={url.toString()}
target='_blank'
rel='noreferrer'
display='flex'
alignItems='center'
_hover={{ textDecoration: 'underline', color: 'blue.700' }}
>
{t('federation-card.view-link-on', { host: url.host })}
<Box as={LinkIcon} ml={1} boxSize={4} />
</Link>
</Flex>
}
/>

<InfoItem label={t('info-card.alias')} value={alias} />
<InfoItem
label={t('info-card.pubkey')}
value={formatEllipsized(pubkey, 8)}
/>
<InfoItem label={t('info-card.network')} value={network} />
<InfoItem label={t('info-card.block-height')} value={blockHeight} />
<InfoItem
label={t('info-card.synced-to-chain')}
value={syncedToChain ? 'Yes' : 'No'}
/>
<InfoItem label={t('info-card.mode')} value={Object.keys(mode)[0]} />
</SimpleGrid>
</GatewayCard>
);
});
9 changes: 8 additions & 1 deletion apps/gateway-ui/src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@
"title": "Lightning Gateway Dashboard"
},
"info-card": {
"card_header": "Lightning Node ID"
"card-header": "Lightning Node Info",
"node-id": "Node ID",
"alias": "Alias",
"mode": "Mode",
"pubkey": "Pubkey",
"network": "Network",
"block-height": "Block Height",
"synced-to-chain": "Synced to Chain"
},
"withdraw-card": {
"address-label": "Your address:",
Expand Down
41 changes: 22 additions & 19 deletions packages/types/src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,35 @@ export enum GatewayState {
Disconnected = 'Disconnected',
}

export enum LightningConfig {
Lnd = 'lnd',
Cln = 'cln',
Ldk = 'ldk',
export interface LndMode {
Lnd: {
lnd_rpc_addr: string;
lnd_tls_cert: string;
lnd_macaroon: string;
};
}

export interface LndConfig {
lnd_rpc_addr: string;
lnd_tls_cert: string;
lnd_macaroon: string;
export interface ClnMode {
Cln: {
cln_extension_addr: string;
};
}

export interface ClnConfig {
cln_extension_addr: string;
export interface LdkMode {
Ldk: {
esplora_server_url: string;
network: Network;
lightning_port: number;
};
}

export interface LdkConfig {
esplora_server_url: string;
network: Network;
lightning_port: number;
}
export type LightningMode = LndMode | ClnMode | LdkMode;

export type LightningMode =
| { mode: LightningConfig.Lnd; config: LndConfig }
| { mode: LightningConfig.Cln; config: ClnConfig }
| { mode: LightningConfig.Ldk; config: LdkConfig };
export enum LightningType {
Lnd = 'Lnd',
Cln = 'Cln',
Ldk = 'Ldk',
}

export interface GatewayFedConfig {
federations: Record<string, JsonClientConfig>;
Expand Down

0 comments on commit 8f25ad2

Please sign in to comment.