soapbox/src/features/wallet/index.tsx

119 wiersze
4.5 KiB
TypeScript
Czysty Zwykły widok Historia

2025-03-23 20:19:42 +00:00
import moreIcon from '@tabler/icons/outline/dots-circle-horizontal.svg';
2025-02-13 16:52:36 +00:00
import { defineMessages, useIntl } from 'react-intl';
import List, { ListItem } from 'soapbox/components/list.tsx';
2025-03-23 20:19:42 +00:00
import Button from 'soapbox/components/ui/button.tsx';
2025-02-13 16:52:36 +00:00
import { Card, CardBody, CardHeader, CardTitle } from 'soapbox/components/ui/card.tsx';
import { Column } from 'soapbox/components/ui/column.tsx';
2025-02-20 23:55:01 +00:00
import Spinner from 'soapbox/components/ui/spinner.tsx';
import Stack from 'soapbox/components/ui/stack.tsx';
2025-03-15 18:12:31 +00:00
import { SelectDropdown } from 'soapbox/features/forms/index.tsx';
2025-03-18 14:19:30 +00:00
import Balance from 'soapbox/features/wallet/components/balance.tsx';
import CreateWallet from 'soapbox/features/wallet/components/create-wallet.tsx';
import Transactions from 'soapbox/features/wallet/components/transactions.tsx';
2025-03-23 20:40:49 +00:00
import { useTransactions, useWallet } from 'soapbox/features/zap/hooks/useHooks.ts';
2025-03-15 18:12:31 +00:00
import { usePaymentMethod } from 'soapbox/features/zap/usePaymentMethod.ts';
2025-02-13 16:52:36 +00:00
import { useOwnAccount } from 'soapbox/hooks/useOwnAccount.ts';
const messages = defineMessages({
2025-03-18 14:19:30 +00:00
payment: { id: 'wallet.payment', defaultMessage: 'Payment Method' },
2025-03-21 19:51:17 +00:00
relays: { id: 'wallet.relays', defaultMessage: 'Wallet Relays' },
2025-03-18 14:19:30 +00:00
transactions: { id: 'wallet.transactions', defaultMessage: 'Transactions' },
wallet: { id: 'wallet.title', defaultMessage: 'Wallet' },
2025-03-18 14:19:30 +00:00
management: { id: 'wallet.management', defaultMessage: 'Wallet Management' },
mints: { id: 'wallet.mints', defaultMessage: 'Mints' },
2025-03-23 20:19:42 +00:00
more: { id: 'wallet.transactions.more', defaultMessage: 'More' },
2025-02-13 16:52:36 +00:00
});
2025-03-15 18:12:31 +00:00
const paymentMethods = {
zap: 'zap',
cashu: 'cashu',
};
/** User Wallet page. */
2025-03-18 14:19:30 +00:00
const Wallet = () => {
2025-02-13 16:52:36 +00:00
const intl = useIntl();
const { account } = useOwnAccount();
2025-03-21 19:51:17 +00:00
const { wallet: walletData, isLoading } = useWallet();
2025-03-15 18:12:31 +00:00
const { method, changeMethod } = usePaymentMethod();
2025-03-23 20:40:49 +00:00
const { transactions } = useTransactions();
const hasTransactions = transactions && transactions.length > 0;
2025-02-13 16:52:36 +00:00
if (!account) return null;
return (
2025-02-20 23:55:01 +00:00
<>
{isLoading ?
<Stack className='h-screen justify-center'>
<Spinner size={40} withText={false} />
</Stack>
:
(
2025-03-18 14:19:30 +00:00
<Column label={intl.formatMessage(messages.wallet)} transparent withHeader={false} slim>
2025-02-20 23:55:01 +00:00
<Card className='space-y-4'>
<CardHeader>
2025-03-18 14:19:30 +00:00
<CardTitle title={intl.formatMessage(messages.wallet)} />
2025-02-20 23:55:01 +00:00
</CardHeader>
{walletData ? (
<>
<CardBody>
<Stack className='rounded-lg border p-6 black:border-gray-500 dark:border-gray-500' alignItems='center' space={4}>
<Balance />
</Stack>
2025-02-20 23:55:01 +00:00
</CardBody>
<CardHeader>
<CardTitle title={intl.formatMessage(messages.transactions)} />
</CardHeader>
<CardBody>
2025-03-25 16:29:40 +00:00
<Transactions limit={4} />
{hasTransactions && <div className='flex w-full justify-center'>
2025-03-23 20:19:42 +00:00
<Button icon={moreIcon} theme='primary' to='/wallet/transactions'>
{intl.formatMessage(messages.more)}
</Button>
2025-03-23 20:40:49 +00:00
</div>}
2025-02-20 23:55:01 +00:00
</CardBody>
<CardHeader>
<CardTitle title={intl.formatMessage(messages.management)} />
</CardHeader>
<CardBody>
<List>
2025-03-23 20:19:42 +00:00
<ListItem label={intl.formatMessage(messages.mints)} to='/wallet/mints' />
<ListItem label={intl.formatMessage(messages.relays)} to='/wallet/relays' />
2025-03-15 18:12:31 +00:00
<ListItem label={intl.formatMessage(messages.payment)} >
<SelectDropdown
className='max-w-[200px]'
items={paymentMethods}
defaultValue={method}
onChange={(event: React.ChangeEvent<HTMLSelectElement>) => {
changeMethod((event.target.value as 'cashu' | 'zap'));
}}
/>
</ListItem>
2025-02-20 23:55:01 +00:00
</List>
</CardBody>
</>
)
:
<>
<CardBody>
2025-03-20 19:58:52 +00:00
<CreateWallet />
2025-02-20 23:55:01 +00:00
</CardBody>
</>
}
</Card>
</Column>
2025-02-13 16:52:36 +00:00
)
2025-02-20 23:55:01 +00:00
}
</>
2025-02-13 16:52:36 +00:00
);
};
2025-03-18 14:19:30 +00:00
export default Wallet;