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

Notifications state

parent 27a4d929
No related branches found
No related tags found
No related merge requests found
...@@ -67,20 +67,32 @@ class Transaction extends Equatable { ...@@ -67,20 +67,32 @@ class Transaction extends Equatable {
@JsonSerializable() @JsonSerializable()
@CopyWith() @CopyWith()
class TransactionsAndBalanceState extends Equatable { class TransactionsAndBalanceState extends Equatable {
const TransactionsAndBalanceState({ const TransactionsAndBalanceState(
required this.transactions, {required this.transactions,
required this.balance, required this.balance,
required this.lastChecked, required this.lastChecked,
}); this.lastSent,
this.lastReceived,
this.lastReceivedNotif});
factory TransactionsAndBalanceState.fromJson(Map<String, dynamic> json) => factory TransactionsAndBalanceState.fromJson(Map<String, dynamic> json) =>
_$TransactionsAndBalanceStateFromJson(json); _$TransactionsAndBalanceStateFromJson(json);
final List<Transaction> transactions; final List<Transaction> transactions;
final double balance; final double balance;
final DateTime lastChecked; final DateTime lastChecked;
final DateTime? lastSent;
final DateTime? lastReceived;
final DateTime? lastReceivedNotif;
Map<String, dynamic> toJson() => _$TransactionsAndBalanceStateToJson(this); Map<String, dynamic> toJson() => _$TransactionsAndBalanceStateToJson(this);
@override @override
List<Object?> get props => <dynamic>[transactions, balance, lastChecked]; List<Object?> get props => <dynamic>[
transactions,
balance,
lastChecked,
lastSent,
lastReceived,
lastReceivedNotif
];
} }
...@@ -161,6 +161,12 @@ abstract class _$TransactionsAndBalanceStateCWProxy { ...@@ -161,6 +161,12 @@ abstract class _$TransactionsAndBalanceStateCWProxy {
TransactionsAndBalanceState lastChecked(DateTime lastChecked); TransactionsAndBalanceState lastChecked(DateTime lastChecked);
TransactionsAndBalanceState lastSent(DateTime? lastSent);
TransactionsAndBalanceState lastReceived(DateTime? lastReceived);
TransactionsAndBalanceState lastReceivedNotif(DateTime? lastReceivedNotif);
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TransactionsAndBalanceState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TransactionsAndBalanceState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
/// ///
/// Usage /// Usage
...@@ -171,6 +177,9 @@ abstract class _$TransactionsAndBalanceStateCWProxy { ...@@ -171,6 +177,9 @@ abstract class _$TransactionsAndBalanceStateCWProxy {
List<Transaction>? transactions, List<Transaction>? transactions,
double? balance, double? balance,
DateTime? lastChecked, DateTime? lastChecked,
DateTime? lastSent,
DateTime? lastReceived,
DateTime? lastReceivedNotif,
}); });
} }
...@@ -192,6 +201,18 @@ class _$TransactionsAndBalanceStateCWProxyImpl ...@@ -192,6 +201,18 @@ class _$TransactionsAndBalanceStateCWProxyImpl
TransactionsAndBalanceState lastChecked(DateTime lastChecked) => TransactionsAndBalanceState lastChecked(DateTime lastChecked) =>
this(lastChecked: lastChecked); this(lastChecked: lastChecked);
@override
TransactionsAndBalanceState lastSent(DateTime? lastSent) =>
this(lastSent: lastSent);
@override
TransactionsAndBalanceState lastReceived(DateTime? lastReceived) =>
this(lastReceived: lastReceived);
@override
TransactionsAndBalanceState lastReceivedNotif(DateTime? lastReceivedNotif) =>
this(lastReceivedNotif: lastReceivedNotif);
@override @override
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TransactionsAndBalanceState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TransactionsAndBalanceState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
...@@ -204,6 +225,9 @@ class _$TransactionsAndBalanceStateCWProxyImpl ...@@ -204,6 +225,9 @@ class _$TransactionsAndBalanceStateCWProxyImpl
Object? transactions = const $CopyWithPlaceholder(), Object? transactions = const $CopyWithPlaceholder(),
Object? balance = const $CopyWithPlaceholder(), Object? balance = const $CopyWithPlaceholder(),
Object? lastChecked = const $CopyWithPlaceholder(), Object? lastChecked = const $CopyWithPlaceholder(),
Object? lastSent = const $CopyWithPlaceholder(),
Object? lastReceived = const $CopyWithPlaceholder(),
Object? lastReceivedNotif = const $CopyWithPlaceholder(),
}) { }) {
return TransactionsAndBalanceState( return TransactionsAndBalanceState(
transactions: transactions:
...@@ -220,6 +244,18 @@ class _$TransactionsAndBalanceStateCWProxyImpl ...@@ -220,6 +244,18 @@ class _$TransactionsAndBalanceStateCWProxyImpl
? _value.lastChecked ? _value.lastChecked
// ignore: cast_nullable_to_non_nullable // ignore: cast_nullable_to_non_nullable
: lastChecked as DateTime, : lastChecked as DateTime,
lastSent: lastSent == const $CopyWithPlaceholder()
? _value.lastSent
// ignore: cast_nullable_to_non_nullable
: lastSent as DateTime?,
lastReceived: lastReceived == const $CopyWithPlaceholder()
? _value.lastReceived
// ignore: cast_nullable_to_non_nullable
: lastReceived as DateTime?,
lastReceivedNotif: lastReceivedNotif == const $CopyWithPlaceholder()
? _value.lastReceivedNotif
// ignore: cast_nullable_to_non_nullable
: lastReceivedNotif as DateTime?,
); );
} }
} }
...@@ -278,6 +314,15 @@ TransactionsAndBalanceState _$TransactionsAndBalanceStateFromJson( ...@@ -278,6 +314,15 @@ TransactionsAndBalanceState _$TransactionsAndBalanceStateFromJson(
.toList(), .toList(),
balance: (json['balance'] as num).toDouble(), balance: (json['balance'] as num).toDouble(),
lastChecked: DateTime.parse(json['lastChecked'] as String), lastChecked: DateTime.parse(json['lastChecked'] as String),
lastSent: json['lastSent'] == null
? null
: DateTime.parse(json['lastSent'] as String),
lastReceived: json['lastReceived'] == null
? null
: DateTime.parse(json['lastReceived'] as String),
lastReceivedNotif: json['lastReceivedNotif'] == null
? null
: DateTime.parse(json['lastReceivedNotif'] as String),
); );
Map<String, dynamic> _$TransactionsAndBalanceStateToJson( Map<String, dynamic> _$TransactionsAndBalanceStateToJson(
...@@ -286,4 +331,7 @@ Map<String, dynamic> _$TransactionsAndBalanceStateToJson( ...@@ -286,4 +331,7 @@ Map<String, dynamic> _$TransactionsAndBalanceStateToJson(
'transactions': instance.transactions, 'transactions': instance.transactions,
'balance': instance.balance, 'balance': instance.balance,
'lastChecked': instance.lastChecked.toIso8601String(), 'lastChecked': instance.lastChecked.toIso8601String(),
'lastSent': instance.lastSent?.toIso8601String(),
'lastReceived': instance.lastReceived?.toIso8601String(),
'lastReceivedNotif': instance.lastReceivedNotif?.toIso8601String(),
}; };
...@@ -2,6 +2,7 @@ import 'package:hydrated_bloc/hydrated_bloc.dart'; ...@@ -2,6 +2,7 @@ import 'package:hydrated_bloc/hydrated_bloc.dart';
import '../../../g1/api.dart'; import '../../../g1/api.dart';
import '../../../g1/transaction_parser.dart'; import '../../../g1/transaction_parser.dart';
import '../../notification_controller.dart';
import '../../shared_prefs.dart'; import '../../shared_prefs.dart';
import '../../ui/logger.dart'; import '../../ui/logger.dart';
import 'node_list_cubit.dart'; import 'node_list_cubit.dart';
...@@ -41,6 +42,16 @@ class TransactionsCubit extends HydratedCubit<TransactionsAndBalanceState> { ...@@ -41,6 +42,16 @@ class TransactionsCubit extends HydratedCubit<TransactionsAndBalanceState> {
transactions: state.transactions, transactions: state.transactions,
balance: state.balance, balance: state.balance,
lastChecked: state.lastChecked)); lastChecked: state.lastChecked));
final DateTime? lastReceived = state.lastReceived;
final DateTime lastReceivedNotification =
state.lastReceivedNotif ?? DateTime(1970);
// final DateTime? lastSent = transBalanceState.lastSent;
if (lastReceived != null &&
lastReceivedNotification.compareTo(lastReceived) == 1) {
// Notify
NotificationController.createNewNotification(
lastReceived.millisecondsSinceEpoch.toString());
}
} }
@override @override
......
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