2023-03-01 21:52:13 +00:00
|
|
|
import 'package:stackwallet/db/hive/db.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
class TransactionNotificationTracker {
|
|
|
|
final String walletId;
|
|
|
|
|
|
|
|
TransactionNotificationTracker({required this.walletId});
|
|
|
|
|
|
|
|
List<String> get pendings {
|
|
|
|
final notifiedPendingTransactions = DB.instance.get<dynamic>(
|
|
|
|
boxName: walletId, key: "notifiedPendingTransactions") as Map? ??
|
|
|
|
{};
|
|
|
|
return List<String>.from(notifiedPendingTransactions.keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wasNotifiedPending(String txid) {
|
|
|
|
final notifiedPendingTransactions = DB.instance.get<dynamic>(
|
|
|
|
boxName: walletId, key: "notifiedPendingTransactions") as Map? ??
|
|
|
|
{};
|
|
|
|
return notifiedPendingTransactions[txid] as bool? ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> addNotifiedPending(String txid) async {
|
|
|
|
final notifiedPendingTransactions = DB.instance.get<dynamic>(
|
|
|
|
boxName: walletId, key: "notifiedPendingTransactions") as Map? ??
|
|
|
|
{};
|
|
|
|
notifiedPendingTransactions[txid] = true;
|
|
|
|
await DB.instance.put<dynamic>(
|
|
|
|
boxName: walletId,
|
|
|
|
key: "notifiedPendingTransactions",
|
|
|
|
value: notifiedPendingTransactions);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> get confirmeds {
|
|
|
|
final notifiedConfirmedTransactions = DB.instance.get<dynamic>(
|
|
|
|
boxName: walletId, key: "notifiedConfirmedTransactions") as Map? ??
|
|
|
|
{};
|
|
|
|
return List<String>.from(notifiedConfirmedTransactions.keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wasNotifiedConfirmed(String txid) {
|
|
|
|
final notifiedConfirmedTransactions = DB.instance.get<dynamic>(
|
|
|
|
boxName: walletId, key: "notifiedConfirmedTransactions") as Map? ??
|
|
|
|
{};
|
|
|
|
return notifiedConfirmedTransactions[txid] as bool? ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> addNotifiedConfirmed(String txid) async {
|
|
|
|
final notifiedConfirmedTransactions = DB.instance.get<dynamic>(
|
|
|
|
boxName: walletId, key: "notifiedConfirmedTransactions") as Map? ??
|
|
|
|
{};
|
|
|
|
notifiedConfirmedTransactions[txid] = true;
|
|
|
|
await DB.instance.put<dynamic>(
|
|
|
|
boxName: walletId,
|
|
|
|
key: "notifiedConfirmedTransactions",
|
|
|
|
value: notifiedConfirmedTransactions);
|
|
|
|
}
|
2023-01-27 18:49:25 +00:00
|
|
|
|
|
|
|
Future<void> deleteTransaction(String txid) async {
|
|
|
|
final notifiedPendingTransactions = DB.instance.get<dynamic>(
|
|
|
|
boxName: walletId, key: "notifiedPendingTransactions") as Map? ??
|
|
|
|
{};
|
|
|
|
final notifiedConfirmedTransactions = DB.instance.get<dynamic>(
|
|
|
|
boxName: walletId, key: "notifiedConfirmedTransactions") as Map? ??
|
|
|
|
{};
|
|
|
|
|
|
|
|
notifiedPendingTransactions.remove(txid);
|
|
|
|
notifiedConfirmedTransactions.remove(txid);
|
|
|
|
|
|
|
|
await DB.instance.put<dynamic>(
|
|
|
|
boxName: walletId,
|
|
|
|
key: "notifiedConfirmedTransactions",
|
|
|
|
value: notifiedConfirmedTransactions);
|
|
|
|
await DB.instance.put<dynamic>(
|
|
|
|
boxName: walletId,
|
|
|
|
key: "notifiedPendingTransactions",
|
|
|
|
value: notifiedPendingTransactions);
|
|
|
|
}
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|