-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #516 from Kodylow/new-gateway-typing
- Loading branch information
Showing
10 changed files
with
174 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 80 additions & 54 deletions
134
apps/gateway-ui/src/components/lightning/LightningCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.