-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/send-token
# Conflicts: # packages/espressocash_app/lib/features/activities/services/tx_updater.dart # packages/espressocash_app/lib/features/activities/widgets/recent_token_activity.dart # packages/espressocash_app/lib/features/token_details/screens/token_details_screen.dart # packages/espressocash_app/lib/l10n/intl_en.arb
- Loading branch information
Showing
21 changed files
with
313 additions
and
164 deletions.
There are no files selected for viewing
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; | ||
} |
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
Oops, something went wrong.