Refactor wallet-relays and remove unnecessary toast

merge-requests/3333/head
danidfra 2025-03-21 12:43:53 -03:00
rodzic 6ad87ed385
commit 085d98f7b8
2 zmienionych plików z 13 dodań i 19 usunięć

Wyświetl plik

@ -56,7 +56,6 @@ const WalletMints = () => {
useEffect(() => {
getWallet(api, false);
toast.error(intl.formatMessage(messages.loadingError));
}, []);
useEffect(

Wyświetl plik

@ -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<string[]>([]);
const [initialRelays, setInitialRelays] = useState<string[]>([]);
const [mints, setMints] = useState<string[]>([]);
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 (
<Column label={intl.formatMessage(messages.title)} >
<Stack space={2}>