diff --git a/src/features/wallet/components/wallet-mints.tsx b/src/features/wallet/components/wallet-mints.tsx index 5a30df0a6..de7ffbb86 100644 --- a/src/features/wallet/components/wallet-mints.tsx +++ b/src/features/wallet/components/wallet-mints.tsx @@ -56,7 +56,6 @@ const WalletMints = () => { useEffect(() => { getWallet(api, false); - toast.error(intl.formatMessage(messages.loadingError)); }, []); useEffect( diff --git a/src/features/wallet/components/wallet-relays.tsx b/src/features/wallet/components/wallet-relays.tsx index 0e362bafb..f39ac1b5d 100644 --- a/src/features/wallet/components/wallet-relays.tsx +++ b/src/features/wallet/components/wallet-relays.tsx @@ -5,8 +5,8 @@ import Button from 'soapbox/components/ui/button.tsx'; import { Column } from 'soapbox/components/ui/column.tsx'; import Stack from 'soapbox/components/ui/stack.tsx'; import { RelayEditor } from 'soapbox/features/wallet/components/editable-lists.tsx'; +import { useCashu } from 'soapbox/features/zap/hooks/useCashu.ts'; import { useApi } from 'soapbox/hooks/useApi.ts'; -import { WalletData, baseWalletSchema } from 'soapbox/schemas/wallet.ts'; import toast from 'soapbox/toast.tsx'; import { isURL } from 'soapbox/utils/auth.ts'; @@ -23,27 +23,12 @@ const messages = defineMessages({ const WalletRelays = () => { const intl = useIntl(); const api = useApi(); + const { wallet, getWallet } = useCashu(); const [relays, setRelays] = useState([]); const [initialRelays, setInitialRelays] = useState([]); const [mints, setMints] = useState([]); - 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); - setMints(normalizedData.mints); - setRelays(normalizedData.relays); - setInitialRelays(normalizedData.relays); - } - - } catch (error) { - toast.error(intl.formatMessage(messages.loadingError)); - } - }; - const handleClick = async () =>{ if (relays.length <= 0) { toast.error(intl.formatMessage(messages.empty)); @@ -70,9 +55,19 @@ const WalletRelays = () => { }; useEffect(() => { - fetchWallet(); + getWallet(api, false); }, []); + useEffect( + () => { + if (wallet) { + setMints(wallet.mints ?? []); + setInitialRelays(wallet.relays ?? []); + setRelays(wallet.relays ?? []); + } + }, [wallet], + ); + return (