diff --git a/apps/gateway-ui/src/components/BalanceTab.tsx b/apps/gateway-ui/src/components/BalanceTab.tsx deleted file mode 100644 index 6959c3f86..000000000 --- a/apps/gateway-ui/src/components/BalanceTab.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import React from 'react'; -import { Box, Flex, Text, useTheme } from '@chakra-ui/react'; -import { useTranslation } from '@fedimint/utils'; -import { GatewayCard } from '.'; - -interface BalanceTabProps { - balance_msat: number; -} - -export const BalanceTab = React.memo(function BalanceTab( - props: BalanceTabProps -): JSX.Element { - const { t } = useTranslation(); - const { balance_msat } = props; - const theme = useTheme(); - - return ( - - - - - {t('balance-tab.tab_header')} - - - {t('balance-tab.sentence')} - - - - - {balance_msat} - - - - - ); -}); diff --git a/apps/gateway-ui/src/components/DepositTab.tsx b/apps/gateway-ui/src/components/DepositTab.tsx deleted file mode 100644 index 25664e1f2..000000000 --- a/apps/gateway-ui/src/components/DepositTab.tsx +++ /dev/null @@ -1,138 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { - Text, - Flex, - useTheme, - Stack, - Link, - Box, - useClipboard, -} from '@chakra-ui/react'; -import { ApiContext } from '../ApiProvider'; -import { QRCodeSVG } from 'qrcode.react'; -import { useTranslation } from '@fedimint/utils'; -import { GatewayCard } from './GatewayCard'; -import { ReactComponent as CopyIcon } from '../assets/svgs/copy.svg'; -import { ReactComponent as LinkIcon } from '../assets/svgs/linkIcon.svg'; - -export interface DepositTabProps { - federationId: string; -} - -export const DepositTab = React.memo(function DepositTab({ - federationId, -}: DepositTabProps): JSX.Element { - const { t } = useTranslation(); - const { gateway } = React.useContext(ApiContext); - const [address, setAddress] = useState(''); - const [error, setError] = useState(''); - const theme = useTheme(); - const { onCopy, hasCopied } = useClipboard(address); - - useEffect(() => { - !address && - gateway - .fetchAddress(federationId) - .then((newAddress) => { - setAddress(newAddress); - setError(''); - }) - .catch(({ message, error }) => { - console.error(error); - setError(message); - }); - }, [address, federationId, gateway]); - - return ( - - - - {t('deposit-tab.tab_header')} - - - {t('deposit-tab.sentence-one')} - - - - {address ? ( - - {address} - - ) : ( - - {error} - - )} - - {hasCopied ? ( - - {t('common.copied')} - - ) : ( - - )} - - - - {address && ( - - )} - - - - - {t('deposit-tab.mempool_deposit_link_text')} - - - - - - ); -}); diff --git a/apps/gateway-ui/src/components/FederationCard.tsx b/apps/gateway-ui/src/components/FederationCard.tsx index dadb258e5..78e8697f8 100644 --- a/apps/gateway-ui/src/components/FederationCard.tsx +++ b/apps/gateway-ui/src/components/FederationCard.tsx @@ -1,8 +1,7 @@ import React from 'react'; import { Flex, Stack, useTheme, Heading } from '@chakra-ui/react'; import { Federation } from '../types'; -import { InfoTab, DepositTab, BalanceTab } from '.'; -import { WithdrawTab } from './WithdrawTab'; +import { InfoCard, DepositCard, BalanceCard, WithdrawCard } from '.'; interface FederationCardProps { federation: Federation; @@ -25,12 +24,12 @@ export const FederationCard = (props: FederationCardProps): JSX.Element => { Human Action Coalition - - + + - - + + diff --git a/apps/gateway-ui/src/components/InfoTab.tsx b/apps/gateway-ui/src/components/InfoTab.tsx deleted file mode 100644 index bf03e35b9..000000000 --- a/apps/gateway-ui/src/components/InfoTab.tsx +++ /dev/null @@ -1,94 +0,0 @@ -import React from 'react'; -import { - Text, - useTheme, - Flex, - Link, - Box, - useClipboard, -} from '@chakra-ui/react'; -import { 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 InfoTabProps { - nodeId: string; - nodeLink: string; -} - -export const InfoTab = React.memo(function InfoTab( - props: InfoTabProps -): JSX.Element { - const { t } = useTranslation(); - const { nodeId, nodeLink } = props; - const theme = useTheme(); - const { onCopy, hasCopied } = useClipboard(nodeId); - - return ( - - - {t('info-tab.tab_header')} - - - - {nodeId} - - - {hasCopied ? ( - - {t('common.copied')} - - ) : ( - - )} - - - - - {t('info-tab.amboss_node_link_text')} - - - - - ); -}); diff --git a/apps/gateway-ui/src/components/WithdrawTab.tsx b/apps/gateway-ui/src/components/WithdrawTab.tsx deleted file mode 100644 index ab3cc8dd5..000000000 --- a/apps/gateway-ui/src/components/WithdrawTab.tsx +++ /dev/null @@ -1,291 +0,0 @@ -import React, { useCallback, useState } from 'react'; -import { - Box, - Button, - Input, - InputGroup, - Modal, - ModalBody, - ModalCloseButton, - ModalContent, - ModalFooter, - ModalHeader, - ModalOverlay, - Stack, - Text, - VStack, - useTheme, -} from '@chakra-ui/react'; -import { ApiContext } from '../ApiProvider'; -import { useTranslation } from '@fedimint/utils'; -import { GatewayCard } from '.'; - -interface WithdrawObject { - amount: number; - address: string; -} - -export interface WithdrawTabProps { - federationId: string; -} - -const truncateStringFormat = (arg: string): string => { - return `${arg.substring(0, 15)}......${arg.substring( - arg.length, - arg.length - 15 - )}`; -}; - -export const WithdrawTab = React.memo(function WithdrawTab({ - federationId, -}: WithdrawTabProps): JSX.Element { - const { t } = useTranslation(); - const theme = useTheme(); - const { gateway } = React.useContext(ApiContext); - const [withdrawObject, setWithdrawObject] = useState({ - amount: 0, - address: '', - }); - const [error, setError] = useState(''); - const [modalState, setModalState] = useState(false); - const { amount, address } = withdrawObject; - - const handleInputChange = useCallback( - (event: React.ChangeEvent) => { - event.preventDefault(); - const { value, name } = event.target; - // FIXME this is a hack - if (name === 'amount') { - setWithdrawObject((prevState) => ({ - ...prevState, - [name]: parseInt(value), - })); - } else { - setWithdrawObject((prevState) => ({ ...prevState, [name]: value })); - } - }, - [] - ); - - const createWithdrawal = () => { - if (!amount && amount === 0 && typeof amount === 'number') { - setError(`${t('withdraw-tab.error-amount')}`); - return; - } - if (!address) { - setError(`${t('withdraw-tab.error-address')}`); - return; - } - // TODO: address validation - setError(''); - setModalState(true); - }; - - const startWithdrawal = () => { - gateway - .requestWithdrawal(federationId, amount, address) - .then((txId) => { - // FIXME: show this in a better way - alert(`${t('withdraw-tab.your-transaction')} ${txId}`); - setWithdrawObject({ ...withdrawObject, amount: 0, address: '' }); - setModalState(false); - }) - .catch(({ error }) => { - console.error(error); - setError(`${t('withdraw-tab.error-request')}`); - }); - }; - - return ( - - - - - {t('withdraw-tab.tab-header')} - - - {t('withdraw-tab.total_bitcoin')} {withdrawObject.amount / 100000}{' '} - {t('common.btc')} - - - {t('withdraw-tab.withdraw_all')} - - - - - - {t('common.amount')} - - handleInputChange(e)} - name='amount' - /> - - - - {t('common.address')} - - handleInputChange(e)} - name='address' - /> - - - {error && ( - - - {t('withdraw-tab.error')}: {error} - - - )} - - - - - - {modalState && ( - { - setModalState(false); - }} - onCloseClickCallback={() => { - setModalState(false); - }} - startWithdrawalCallback={startWithdrawal} - /> - )} - - ); -}); - -export interface ConfirmWithdrawModalProps { - open: boolean; - txRequest: { - amount: number; - address: string; - }; - onModalClickCallback: () => void; - onCloseClickCallback: () => void; - startWithdrawalCallback: () => void; -} - -const ConfirmWithdrawModal = ( - props: ConfirmWithdrawModalProps -): JSX.Element => { - const { t } = useTranslation(); - const { open, txRequest, onModalClickCallback, startWithdrawalCallback } = - props; - - return ( -
- <> - - - - {t('withdraw-tab.confirm-withdraw')} - - - - - {t('common.amount')}: - - {txRequest.amount} {t('common.sats')} - - - {t('withdraw-tab.to')} - - {t('common.address')}: - {truncateStringFormat(txRequest.address)} - - - - - - - - - -
- ); -}; - -export interface TransactionViewProps { - amount: number; - address: string; - txId: string; - confirmationsRequired: number; - federationId?: string; -} - -export interface TransactionInfoProps { - title: string; - detail?: string | number; - children?: React.ReactNode; - onClick?: () => void; - color?: string; -}