|
1 | | -import { useCallback, useEffect, useMemo, useState } from 'react'; |
2 | 1 | import { useSnapshot } from 'valtio'; |
| 2 | +import { useCallback, useEffect, useMemo, useState } from 'react'; |
3 | 3 | import { ScrollView, View, type StyleProp, type ViewStyle, RefreshControl } from 'react-native'; |
4 | 4 | import { |
5 | 5 | FlexView, |
@@ -30,6 +30,7 @@ interface Props { |
30 | 30 | export function AccountActivity({ style }: Props) { |
31 | 31 | const Theme = useTheme(); |
32 | 32 | const [refreshing, setRefreshing] = useState(false); |
| 33 | + const [initialLoad, setInitialLoad] = useState(true); |
33 | 34 | const { loading, transactions, next } = useSnapshot(TransactionsController.state); |
34 | 35 | const { caipNetwork } = useSnapshot(NetworkController.state); |
35 | 36 | const networkImage = AssetUtil.getNetworkImage(caipNetwork); |
@@ -62,23 +63,29 @@ export function AccountActivity({ style }: Props) { |
62 | 63 | if (!TransactionsController.state.transactions.length) { |
63 | 64 | TransactionsController.fetchTransactions(AccountController.state.address, true); |
64 | 65 | } |
| 66 | + // Set initial load to false after first fetch |
| 67 | + const timer = setTimeout(() => setInitialLoad(false), 100); |
| 68 | + |
| 69 | + return () => clearTimeout(timer); |
65 | 70 | }, []); |
66 | 71 |
|
67 | | - if (loading && !transactions.length) { |
| 72 | + // Show loading spinner during initial load or when loading with no transactions |
| 73 | + if ((initialLoad || loading) && !transactions.length) { |
68 | 74 | return ( |
69 | 75 | <FlexView style={[styles.placeholder, style]} alignItems="center" justifyContent="center"> |
70 | 76 | <LoadingSpinner /> |
71 | 77 | </FlexView> |
72 | 78 | ); |
73 | 79 | } |
74 | 80 |
|
75 | | - if (!Object.keys(transactionsByYear).length) { |
| 81 | + // Only show placeholder when we're not in initial load or loading state |
| 82 | + if (!Object.keys(transactionsByYear).length && !loading && !initialLoad) { |
76 | 83 | return ( |
77 | 84 | <Placeholder |
78 | 85 | icon="swapHorizontal" |
79 | 86 | title="No activity yet" |
80 | 87 | description="Your next transactions will appear here" |
81 | | - style={style} |
| 88 | + style={[styles.placeholder, style]} |
82 | 89 | /> |
83 | 90 | ); |
84 | 91 | } |
@@ -150,14 +157,14 @@ export function AccountActivity({ style }: Props) { |
150 | 157 | ))} |
151 | 158 | </View> |
152 | 159 | ))} |
153 | | - {(next || loading) && ( |
| 160 | + {(next || loading) && !refreshing && ( |
154 | 161 | <FlexView style={styles.footer} alignItems="center" justifyContent="center"> |
155 | 162 | {next && !loading && ( |
156 | 163 | <Link size="md" style={styles.loadMoreButton} onPress={handleLoadMore}> |
157 | 164 | Load more |
158 | 165 | </Link> |
159 | 166 | )} |
160 | | - {loading && !refreshing && <LoadingSpinner color="accent-100" />} |
| 167 | + {loading && <LoadingSpinner color="accent-100" />} |
161 | 168 | </FlexView> |
162 | 169 | )} |
163 | 170 | </ScrollView> |
|
0 commit comments