merge-requests/3333/head
danidfra 2025-04-01 18:05:07 -03:00
rodzic 21fc7c8ed9
commit 0c92375c42
4 zmienionych plików z 83 dodań i 81 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ const messages = defineMessages({
title: { id: 'wallet.transactions', defaultMessage: 'Transactions' },
more: { id: 'wallet.transactions.show_more', defaultMessage: 'Show More' },
loading: { id: 'wallet.loading', defaultMessage: 'Loading…' },
noMoreTransactions: { id: 'wallet.transactions.no_more', defaultMessage: 'You reached the end of transactions' },
});
const WalletTransactions = () => {
@ -17,13 +18,15 @@ const WalletTransactions = () => {
const { isLoading, expandTransactions } = useTransactions();
const observerRef = useRef<HTMLDivElement | null>(null);
const [showSpinner, setShowSpinner] = useState(false);
const [hasMoreTransactions, setHasMoreTransactions] = useState(true);
useEffect(() => {
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
async ([entry]) => {
if (entry.isIntersecting && !isLoading && hasMoreTransactions) {
setShowSpinner(true);
if (!isLoading) expandTransactions();
const hasMore = await expandTransactions();
setHasMoreTransactions(hasMore);
}
},
{ rootMargin: '100px' },
@ -34,13 +37,18 @@ const WalletTransactions = () => {
}
return () => observer.disconnect();
}, [expandTransactions, isLoading]);
}, [expandTransactions, isLoading, hasMoreTransactions]);
return (
<Column label={intl.formatMessage(messages.title)}>
<Transactions />
<div className='flex w-full justify-center' ref={observerRef}>
{showSpinner && isLoading && <Spinner />}
{!hasMoreTransactions && (
<div className='py-4 text-center text-gray-600'>
{intl.formatMessage(messages.noMoreTransactions)}
</div>
)}
</div>
</Column>
);

Wyświetl plik

@ -44,14 +44,11 @@ const Wallet = () => {
return (
<>
{isLoading ?
{isLoading ? (
<Stack className='h-screen items-center justify-center'>
<div className='rounded-lg border border-gray-200 p-10 dark:border-gray-700'>
<Spinner size={50} withText={false} />
</div>
</Stack>
:
(
) : (
<Column label={intl.formatMessage(messages.wallet)} transparent withHeader={false} slim>
<Card className='space-y-4 overflow-hidden'>
<CardHeader>
@ -108,21 +105,17 @@ const Wallet = () => {
</ListItem>
</List>
</CardBody>
</>
)
:
) : (
<>
<CardBody>
<CreateWallet />
</CardBody>
</>
}
)}
</Card>
</Column>
)
}
)}
</>
);
};

Wyświetl plik

@ -73,7 +73,7 @@ const useWalletStore = create<WalletState>((set) => ({
const useWallet = () => {
const api = useApi();
const { wallet, setWallet, setAcceptsZapsCashu, hasFetchedWallet, setHasFetchedWallet } = useWalletStore();
const [isLoading, setIsLoading] = useState(false);
const [isLoading, setIsLoading] = useState(!hasFetchedWallet);
const [error, setError] = useState<string | null>(null);
const createWallet = async (walletInfo: IWalletInfo) => {
@ -118,7 +118,6 @@ const useWallet = () => {
useEffect(() => {
if (!hasFetchedWallet) {
setHasFetchedWallet(true);
getWallet(false);
}
}, []);
@ -153,8 +152,7 @@ const useTransactions = () => {
const expandTransactions = async () => {
if (!nextTransaction || !transactions) {
toast.info('You reached the end of transactions');
return;
return false;
}
try {
setIsLoading(true);
@ -166,10 +164,12 @@ const useTransactions = () => {
const newTransactions = [...(transactions ?? []), ...normalizedData ];
setTransactions(newTransactions, prev, next);
return true; // Return true to indicate successful expansion
} catch (err) {
const messageError = err instanceof Error ? err.message : 'Error expanding transactions';
toast.error(messageError);
setError(messageError);
return false;
} finally {
setIsLoading(false);
}

Wyświetl plik

@ -1740,6 +1740,7 @@
"wallet.title": "Wallet",
"wallet.transactions": "Transactions",
"wallet.transactions.more": "More",
"wallet.transactions.no_more": "You reached the end of transactions",
"wallet.transactions.no_transactions": "You don't have transactions yet.",
"wallet.transactions.show_more": "Show More",
"who_to_follow.title": "People To Follow",