-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Justin Enerio <[email protected]> Co-authored-by: ookami-kb <[email protected]> Co-authored-by: Vlad Sumin <[email protected]>
- Loading branch information
1 parent
7809e99
commit 3bf600a
Showing
20 changed files
with
1,210 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/espressocash_app/lib/features/activities/services/token_activities_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'package:fast_immutable_collections/fast_immutable_collections.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
|
||
import '../data/transaction_repository.dart'; | ||
import '../models/transaction.dart'; | ||
|
||
@injectable | ||
class TokenActivitiesRepository { | ||
const TokenActivitiesRepository(this._repository); | ||
|
||
final TransactionRepository _repository; | ||
|
||
Stream<List<ActivityGroup>> watchTokenActivities(String tokenAddress) => | ||
_repository.watchGroupedByDate(tokenAddress).map(_prepareActivityGroups); | ||
|
||
List<ActivityGroup> _prepareActivityGroups( | ||
Map<String, IList<TxCommon>> data, | ||
) { | ||
final sortedDates = data.keys.toList()..sort((a, b) => b.compareTo(a)); | ||
|
||
return sortedDates.map((date) { | ||
final transactions = data[date] ?? IList<TxCommon>(); | ||
|
||
final sortedTxs = transactions.sort((a, b) { | ||
final aCreated = a.created; | ||
final bCreated = b.created; | ||
|
||
return (aCreated != null && bCreated != null) | ||
? bCreated.compareTo(aCreated) | ||
: 0; | ||
}); | ||
|
||
return ActivityGroup(date: date, transactions: sortedTxs); | ||
}).toList(); | ||
} | ||
} | ||
|
||
class ActivityGroup { | ||
const ActivityGroup({ | ||
required this.date, | ||
required this.transactions, | ||
}); | ||
|
||
final String date; | ||
final IList<TxCommon> transactions; | ||
} |
Oops, something went wrong.