import { useEffect, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import List, { ListItem } from 'soapbox/components/list.tsx'; import { Card, CardBody, CardHeader, CardTitle } from 'soapbox/components/ui/card.tsx'; import { Column } from 'soapbox/components/ui/column.tsx'; import Spinner from 'soapbox/components/ui/spinner.tsx'; import Stack from 'soapbox/components/ui/stack.tsx'; import { SelectDropdown } from 'soapbox/features/forms/index.tsx'; 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'; import { usePaymentMethod } from 'soapbox/features/zap/usePaymentMethod.ts'; import { useApi } from 'soapbox/hooks/useApi.ts'; import { useOwnAccount } from 'soapbox/hooks/useOwnAccount.ts'; import { WalletData, baseWalletSchema } from 'soapbox/schemas/wallet.ts'; import toast from 'soapbox/toast.tsx'; const messages = defineMessages({ payment: { id: 'wallet.payment', defaultMessage: 'Payment Method' }, relays: { id: 'wallet.relays', defaultMessage: 'Relays' }, transactions: { id: 'wallet.transactions', defaultMessage: 'Transactions' }, wallet: { id: 'wallet', defaultMessage: 'Wallet' }, management: { id: 'wallet.management', defaultMessage: 'Wallet Management' }, mints: { id: 'wallet.mints', defaultMessage: 'Mints' }, }); const paymentMethods = { zap: 'zap', cashu: 'cashu', }; /** User Wallet page. */ const Wallet = () => { const api = useApi(); const intl = useIntl(); const { account } = useOwnAccount(); const [walletData, setWalletData] = useState(undefined); const [isLoading, setIsLoading] = useState(true); const { method, changeMethod } = usePaymentMethod(); const fetchWallet = async () => { try { const response = await api.get('/api/v1/ditto/cashu/wallet'); const data: WalletData = await response.json(); if (data) { const normalizedData = baseWalletSchema.parse(data); setWalletData(normalizedData); } } catch (error) { toast.error('Wallet not found'); } finally { setIsLoading(false); } }; useEffect(() => { fetchWallet(); }, []); if (!account) return null; return ( <> {isLoading ? : ( {walletData ? ( <> ) => { changeMethod((event.target.value as 'cashu' | 'zap')); }} /> ) : <> } ) } ); }; export default Wallet;