loadMore method
Fetch the NEXT keyset page and append it. No-op if there is no next page or
a page is already in flight (the double-tap guard). A fault keeps the rows
we have and returns to ready so the user can retry (no blanking, no throw).
Implementation
Future<void> loadMore() async {
final current = state;
final cursor = current.nextCursor;
if (cursor == null || current.phase == WalletActivityPhase.loadingMore) {
return;
}
final session = ref.read(walletSessionProvider);
if (session == null) return;
// Bump AFTER the guards (a no-op double-tap must not invalidate the in-flight
// page). A concurrent refresh that started earlier now sees a stale generation.
final gen = ++_generation;
state = current.copyWith(phase: WalletActivityPhase.loadingMore);
try {
final page = await session
.transactions(limit: walletActivityPageSize, after: cursor)
.timeout(walletFfiWedgeTimeout);
if (_disposed || gen != _generation) return;
state = WalletActivityState(
rows: [...current.rows, ...page.rows],
nextCursor: page.nextCursor,
phase: WalletActivityPhase.ready,
);
} catch (_) {
if (_disposed || gen != _generation) return;
// Keep the rows already loaded; drop back to ready so "load more" is offered
// again (the cursor is preserved — current.nextCursor still points past them).
state = current.copyWith(phase: WalletActivityPhase.ready);
}
}