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

feat: switch everything to tabs #560

Merged
merged 7 commits into from
Oct 17, 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
94 changes: 70 additions & 24 deletions apps/router/src/gateway-ui/Gateway.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import React, { useState } from 'react';
import { Flex } from '@chakra-ui/react';
import {
Flex,
Tabs,
TabList,
TabPanels,
Tab,
TabPanel,
Card,
Divider,
} from '@chakra-ui/react';
import { ConnectFederationModal, LightningCard } from './components';
import { FederationsTable } from './components/federations/FederationsTable';
import { Loading } from './components/Loading';
Expand All @@ -15,8 +24,10 @@ import { useGatewayContext, useLoadGateway } from '../context/hooks';
import { ErrorMessage } from './components/ErrorMessage';
import { Login } from '@fedimint/ui';
import { GATEWAY_APP_ACTION_TYPE } from '../types/gateway';
import { useTranslation } from '@fedimint/utils';

export const Gateway = () => {
const { t } = useTranslation();
const { state, dispatch, api, id } = useGatewayContext();
const [showConnectFed, setShowConnectFed] = useState(false);
const [walletModalState, setWalletModalState] = useState<WalletModalState>({
Expand All @@ -25,6 +36,7 @@ export const Gateway = () => {
type: WalletModalType.Onchain,
selectedFederation: null,
});
const [activeTab, setActiveTab] = useState(0);

useLoadGateway();
if (state.needsAuth) {
Expand All @@ -48,29 +60,63 @@ export const Gateway = () => {
return (
<Flex direction='column' gap={4}>
<HeaderWithUnitSelector />
{state.balances && (
<WalletCard
unit={state.unit}
balances={state.balances}
setWalletModalState={setWalletModalState}
federations={state.gatewayInfo.federations}
/>
)}
<LightningCard
nodeId={state.gatewayInfo.gateway_id}
network={state.gatewayInfo.network}
alias={state.gatewayInfo.lightning_alias}
mode={state.gatewayInfo.lightning_mode}
pubkey={state.gatewayInfo.lightning_pub_key}
blockHeight={state.gatewayInfo.block_height}
syncedToChain={state.gatewayInfo.synced_to_chain}
/>
<FederationsTable
unit={state.unit}
federations={state.gatewayInfo.federations}
onConnectFederation={() => setShowConnectFed(true)}
setWalletModalState={setWalletModalState}
/>
<Card flex='1' width='100%'>
<Tabs
variant='soft-rounded'
colorScheme='blue'
index={activeTab}
onChange={setActiveTab}
orientation='vertical'
display='flex'
height='100%'
>
<Flex width='100%'>
<TabList flexDirection='column' minWidth='200px' p={4}>
<Tab justifyContent='flex-start' mb={2}>
{t('wallet.title')}
</Tab>
<Tab justifyContent='flex-start' mb={2}>
{t('info-card.card-header')}
</Tab>
<Tab justifyContent='flex-start' mb={2}>
{t('federation-card.table-title')}
</Tab>
</TabList>
<Divider orientation='vertical' />
<TabPanels flex={1} width='100%'>
<TabPanel>
{state.balances && (
<WalletCard
unit={state.unit}
balances={state.balances}
setWalletModalState={setWalletModalState}
federations={state.gatewayInfo.federations}
/>
)}
</TabPanel>
<TabPanel>
<LightningCard
nodeId={state.gatewayInfo.gateway_id}
network={state.gatewayInfo.network}
alias={state.gatewayInfo.lightning_alias}
mode={state.gatewayInfo.lightning_mode}
pubkey={state.gatewayInfo.lightning_pub_key}
blockHeight={state.gatewayInfo.block_height}
syncedToChain={state.gatewayInfo.synced_to_chain}
/>
</TabPanel>
<TabPanel>
<FederationsTable
unit={state.unit}
federations={state.gatewayInfo.federations}
onConnectFederation={() => setShowConnectFed(true)}
setWalletModalState={setWalletModalState}
/>
</TabPanel>
</TabPanels>
</Flex>
</Tabs>
</Card>
<ConnectFederationModal
isOpen={showConnectFed}
onClose={() => setShowConnectFed(false)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import React from 'react';
import {
Card,
CardHeader,
CardBody,
Text,
Flex,
Link,
useTheme,
Button,
} from '@chakra-ui/react';
import { Text, Flex, Link, useTheme, Button } from '@chakra-ui/react';
import { FederationInfo, MSats } from '@fedimint/types';
import { useTranslation, formatEllipsized, formatValue } from '@fedimint/utils';
import { Table, TableColumn, TableRow } from '@fedimint/ui';
Expand Down Expand Up @@ -101,22 +92,13 @@ export const FederationsTable: React.FC<FederationsTableProps> = ({
}));

return (
<Card>
<CardHeader>
<Flex justifyContent='space-between' alignItems='center'>
<Text size='lg' fontWeight='600'>
{t('federation-card.table-title')}
</Text>
<Flex alignItems='center'>
<Button onClick={onConnectFederation} ml={4}>
{t('connect-federation.connect-federation-button')}
</Button>
</Flex>
</Flex>
</CardHeader>
<CardBody>
<Table columns={columns} rows={rows} />
</CardBody>
</Card>
<Flex direction='column' gap={4}>
<Flex alignItems='center' justifyContent='flex-end'>
<Button onClick={onConnectFederation}>
{t('connect-federation.connect-federation-button')}
</Button>
</Flex>
<Table columns={columns} rows={rows} />
</Flex>
);
};
103 changes: 50 additions & 53 deletions apps/router/src/gateway-ui/components/lightning/LightningCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '@chakra-ui/react';
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';

Expand Down Expand Up @@ -52,58 +51,56 @@ export const LightningCard = React.memo(function LightningCard({
);

return (
<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>
}
/>
<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>
<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>
);
});
Loading
Loading