diff --git a/src/features/wallet/components/wallet-transactions.tsx b/src/features/wallet/components/wallet-transactions.tsx index af9ec6116..933e43ac5 100644 --- a/src/features/wallet/components/wallet-transactions.tsx +++ b/src/features/wallet/components/wallet-transactions.tsx @@ -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(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 (
{showSpinner && isLoading && } + {!hasMoreTransactions && ( +
+ {intl.formatMessage(messages.noMoreTransactions)} +
+ )}
); diff --git a/src/features/wallet/index.tsx b/src/features/wallet/index.tsx index cdf1c3e96..6efe77118 100644 --- a/src/features/wallet/index.tsx +++ b/src/features/wallet/index.tsx @@ -44,85 +44,78 @@ const Wallet = () => { return ( <> - {isLoading ? + {isLoading ? ( -
- -
+
- : - ( - - - - - + ) : ( + + + + + - {walletData ? ( - <> - - + + + + + + + + + + + + + {hasTransactions &&
+ +
} +
- - - + + + - - - {hasTransactions &&
- -
} -
- - - - - - - - - - - ) => { - changeMethod((event.target.value as 'cashu' | 'lightning')); - }} - /> - - - - - - ) - : - <> - - - - - - } -
-
- ) - } + + + + + + ) => { + changeMethod((event.target.value as 'cashu' | 'lightning')); + }} + /> + + + + + ) : ( + <> + + + + + )} +
+
+ )} ); }; diff --git a/src/features/zap/hooks/useHooks.ts b/src/features/zap/hooks/useHooks.ts index 51d241fbe..d9dcdbfd4 100644 --- a/src/features/zap/hooks/useHooks.ts +++ b/src/features/zap/hooks/useHooks.ts @@ -73,7 +73,7 @@ const useWalletStore = create((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(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); } diff --git a/src/locales/en.json b/src/locales/en.json index 86ee426c1..a686ec86d 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -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",