diff --git a/lib/electrumx_rpc/electrumx.dart b/lib/electrumx_rpc/electrumx.dart index a2326345d..6667c3de5 100644 --- a/lib/electrumx_rpc/electrumx.dart +++ b/lib/electrumx_rpc/electrumx.dart @@ -137,7 +137,9 @@ class ElectrumX { .toString() .contains("No such mempool or blockchain transaction")) { throw NoSuchTransactionException( - "No such mempool or blockchain transaction: ${args.first}"); + "No such mempool or blockchain transaction", + args.first.toString(), + ); } throw Exception( diff --git a/lib/exceptions/electrumx/no_such_transaction.dart b/lib/exceptions/electrumx/no_such_transaction.dart index a2bea262b..0c7bedeae 100644 --- a/lib/exceptions/electrumx/no_such_transaction.dart +++ b/lib/exceptions/electrumx/no_such_transaction.dart @@ -1,5 +1,7 @@ import 'package:stackwallet/exceptions/sw_exception.dart'; class NoSuchTransactionException extends SWException { - NoSuchTransactionException(super.message); + final String txid; + + NoSuchTransactionException(super.message, this.txid); } diff --git a/lib/services/coins/dogecoin/dogecoin_wallet.dart b/lib/services/coins/dogecoin/dogecoin_wallet.dart index 8d675dba9..073d050c9 100644 --- a/lib/services/coins/dogecoin/dogecoin_wallet.dart +++ b/lib/services/coins/dogecoin/dogecoin_wallet.dart @@ -14,6 +14,7 @@ import 'package:isar/isar.dart'; import 'package:stackwallet/db/main_db.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart'; +import 'package:stackwallet/exceptions/electrumx/no_such_transaction.dart'; import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models; import 'package:stackwallet/models/paymint/fee_object_model.dart'; @@ -611,6 +612,13 @@ class DogecoinWallet extends CoinServiceAPI } } return needsRefresh; + } on NoSuchTransactionException catch (e) { + // TODO: move direct transactions elsewhere + await db.isar.writeTxn(() async { + await db.isar.transactions.deleteByTxidWalletId(e.txid, walletId); + }); + await txTracker.deleteTransaction(e.txid); + return true; } catch (e, s) { Logging.instance.log( "Exception caught in refreshIfThereIsNewData: $e\n$s", diff --git a/lib/services/notifications_service.dart b/lib/services/notifications_service.dart index 2368adeab..2bfe0e12f 100644 --- a/lib/services/notifications_service.dart +++ b/lib/services/notifications_service.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart'; +import 'package:stackwallet/exceptions/electrumx/no_such_transaction.dart'; import 'package:stackwallet/hive/db.dart'; import 'package:stackwallet/models/exchange/response_objects/trade.dart'; import 'package:stackwallet/models/notification_model.dart'; @@ -169,12 +170,14 @@ class NotificationsService extends ChangeNotifier { } // replaces the current notification with the updated one - add(updatedNotification, true); + await add(updatedNotification, true); } } else { // TODO: check non electrumx coins } } + } on NoSuchTransactionException catch (e, s) { + await _deleteWatchedTxNotification(notification); } catch (e, s) { Logging.instance.log("$e $s", level: LogLevel.Error); } diff --git a/lib/services/transaction_notification_tracker.dart b/lib/services/transaction_notification_tracker.dart index 696465e85..6a2cce2c7 100644 --- a/lib/services/transaction_notification_tracker.dart +++ b/lib/services/transaction_notification_tracker.dart @@ -54,4 +54,25 @@ class TransactionNotificationTracker { key: "notifiedConfirmedTransactions", value: notifiedConfirmedTransactions); } + + Future deleteTransaction(String txid) async { + final notifiedPendingTransactions = DB.instance.get( + boxName: walletId, key: "notifiedPendingTransactions") as Map? ?? + {}; + final notifiedConfirmedTransactions = DB.instance.get( + boxName: walletId, key: "notifiedConfirmedTransactions") as Map? ?? + {}; + + notifiedPendingTransactions.remove(txid); + notifiedConfirmedTransactions.remove(txid); + + await DB.instance.put( + boxName: walletId, + key: "notifiedConfirmedTransactions", + value: notifiedConfirmedTransactions); + await DB.instance.put( + boxName: walletId, + key: "notifiedPendingTransactions", + value: notifiedPendingTransactions); + } }