Skip to content
Snippets Groups Projects
Commit 897a0d3a authored by vjrj's avatar vjrj
Browse files

Fix transactions refresh

parent 406e3963
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ part 'transactions_state.dart'; ...@@ -11,7 +11,7 @@ part 'transactions_state.dart';
class TransactionsBloc { class TransactionsBloc {
TransactionsBloc() { TransactionsBloc() {
_onPageRequest.stream _onPageRequest.stream
.flatMap(_fetchCharacterSummaryList) .flatMap(_fetchTransactionsList)
.listen(_onNewListingStateController.add) .listen(_onNewListingStateController.add)
.addTo(_subscriptions); .addTo(_subscriptions);
...@@ -50,7 +50,7 @@ class TransactionsBloc { ...@@ -50,7 +50,7 @@ class TransactionsBloc {
Stream<TransactionsState> _resetSearch() async* { Stream<TransactionsState> _resetSearch() async* {
yield TransactionsState(); yield TransactionsState();
yield* _fetchCharacterSummaryList(null); yield* _fetchTransactionsList(null);
} }
void init(TransactionCubit transCubit, NodeListCubit nodeListCubit) { void init(TransactionCubit transCubit, NodeListCubit nodeListCubit) {
...@@ -58,7 +58,7 @@ class TransactionsBloc { ...@@ -58,7 +58,7 @@ class TransactionsBloc {
this.nodeListCubit = nodeListCubit; this.nodeListCubit = nodeListCubit;
} }
Stream<TransactionsState> _fetchCharacterSummaryList(String? pageKey) async* { Stream<TransactionsState> _fetchTransactionsList(String? pageKey) async* {
final TransactionsState lastListingState = final TransactionsState lastListingState =
_onNewListingStateController.value; _onNewListingStateController.value;
try { try {
...@@ -68,22 +68,24 @@ class TransactionsBloc { ...@@ -68,22 +68,24 @@ class TransactionsBloc {
searchTerm: _searchInputValue, searchTerm: _searchInputValue,
); );
*/ */
final List<Transaction> newItems = await transCubit.fetchTransactions( final List<Transaction> fetchedItems = await transCubit.fetchTransactions(
nodeListCubit, nodeListCubit,
cursor: pageKey, cursor: pageKey,
pageSize: _pageSize); pageSize: _pageSize);
final bool isLastPage = newItems.length < _pageSize; final bool isLastPage = fetchedItems.length < _pageSize;
final String? nextPageKey = final String? nextPageKey =
isLastPage ? null : transCubit.state.endCursor; isLastPage ? null : transCubit.state.endCursor;
yield TransactionsState( yield TransactionsState(
// error: null, // error: null,
nextPageKey: nextPageKey, nextPageKey: nextPageKey,
itemList: <Transaction>[ itemList: pageKey == null
...lastListingState.itemList ?? <Transaction>[], ? fetchedItems
...newItems : <Transaction>[
], ...lastListingState.itemList ?? <Transaction>[],
...fetchedItems
],
); );
} catch (e) { } catch (e) {
yield TransactionsState( yield TransactionsState(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment