From f0a8d65b3e99ad2c68f61ce6bb9efbbaf251fecc Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 2 Feb 2023 16:19:14 -0600 Subject: [PATCH] show sent tx immediately in history --- .../coins/bitcoin/bitcoin_wallet.dart | 65 +++++++------------ .../coins/bitcoincash/bitcoincash_wallet.dart | 65 +++++++------------ .../coins/dogecoin/dogecoin_wallet.dart | 65 +++++++------------ lib/services/coins/firo/firo_wallet.dart | 63 +++++++----------- .../coins/litecoin/litecoin_wallet.dart | 65 +++++++------------ lib/services/coins/manager.dart | 11 +++- .../coins/namecoin/namecoin_wallet.dart | 65 +++++++------------ .../coins/particl/particl_wallet.dart | 65 +++++++------------ 8 files changed, 184 insertions(+), 280 deletions(-) diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index 3bf151ccc..60ba85895 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -1267,46 +1267,31 @@ class BitcoinWallet extends CoinServiceAPI // transactions locally in a good way @override Future updateSentCachedTxData(Map txData) async { - // final priceData = - // await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency); - // Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero; - // final locale = - // Platform.isWindows ? "en_US" : await Devicelocale.currentLocale; - // final String worthNow = Format.localizedStringAsFixed( - // value: - // ((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) / - // Decimal.fromInt(Constants.satsPerCoin(coin))) - // .toDecimal(scaleOnInfinitePrecision: 2), - // decimalPlaces: 2, - // locale: locale!); - // - // final tx = models.Transaction( - // txid: txData["txid"] as String, - // confirmedStatus: false, - // timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, - // txType: "Sent", - // amount: txData["recipientAmt"] as int, - // worthNow: worthNow, - // worthAtBlockTimestamp: worthNow, - // fees: txData["fee"] as int, - // inputSize: 0, - // outputSize: 0, - // inputs: [], - // outputs: [], - // address: txData["address"] as String, - // height: -1, - // confirmations: 0, - // ); - // - // if (cachedTxData == null) { - // final data = await _fetchTransactionData(); - // _transactionData = Future(() => data); - // } - // - // final transactions = cachedTxData!.getAllTransactions(); - // transactions[tx.txid] = tx; - // cachedTxData = models.TransactionData.fromMap(transactions); - // _transactionData = Future(() => cachedTxData!); + final transaction = isar_models.Transaction( + walletId: walletId, + txid: txData["txid"] as String, + timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, + type: isar_models.TransactionType.outgoing, + subType: isar_models.TransactionSubType.none, + amount: txData["recipientAmt"] as int, + fee: txData["fee"] as int, + height: null, + isCancelled: false, + isLelantus: false, + otherData: null, + slateId: null, + ); + + final address = txData["address"] is String + ? await db.getAddress(walletId, txData["address"] as String) + : null; + + await db.addNewTransactionData( + [ + Tuple4(transaction, [], [], address), + ], + walletId, + ); } @override diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index 4a4ff041b..1963c89bc 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -1200,46 +1200,31 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { // transactions locally in a good way @override Future updateSentCachedTxData(Map txData) async { - // final priceData = - // await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency); - // Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero; - // final locale = - // Platform.isWindows ? "en_US" : await Devicelocale.currentLocale; - // final String worthNow = Format.localizedStringAsFixed( - // value: - // ((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) / - // Decimal.fromInt(Constants.satsPerCoin(coin))) - // .toDecimal(scaleOnInfinitePrecision: 2), - // decimalPlaces: 2, - // locale: locale!); - // - // final tx = models.Transaction( - // txid: txData["txid"] as String, - // confirmedStatus: false, - // timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, - // txType: "Sent", - // amount: txData["recipientAmt"] as int, - // worthNow: worthNow, - // worthAtBlockTimestamp: worthNow, - // fees: txData["fee"] as int, - // inputSize: 0, - // outputSize: 0, - // inputs: [], - // outputs: [], - // address: txData["address"] as String, - // height: -1, - // confirmations: 0, - // ); - // - // if (cachedTxData == null) { - // final data = await _fetchTransactionData(); - // _transactionData = Future(() => data); - // } - // - // final transactions = cachedTxData!.getAllTransactions(); - // transactions[tx.txid] = tx; - // cachedTxData = models.TransactionData.fromMap(transactions); - // _transactionData = Future(() => cachedTxData!); + final transaction = isar_models.Transaction( + walletId: walletId, + txid: txData["txid"] as String, + timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, + type: isar_models.TransactionType.outgoing, + subType: isar_models.TransactionSubType.none, + amount: txData["recipientAmt"] as int, + fee: txData["fee"] as int, + height: null, + isCancelled: false, + isLelantus: false, + otherData: null, + slateId: null, + ); + + final address = txData["address"] is String + ? await db.getAddress(walletId, txData["address"] as String) + : null; + + await db.addNewTransactionData( + [ + Tuple4(transaction, [], [], address), + ], + walletId, + ); } bool validateCashAddr(String cashAddr) { diff --git a/lib/services/coins/dogecoin/dogecoin_wallet.dart b/lib/services/coins/dogecoin/dogecoin_wallet.dart index 85a2abc81..b67054b4c 100644 --- a/lib/services/coins/dogecoin/dogecoin_wallet.dart +++ b/lib/services/coins/dogecoin/dogecoin_wallet.dart @@ -1059,46 +1059,31 @@ class DogecoinWallet extends CoinServiceAPI // transactions locally in a good way @override Future updateSentCachedTxData(Map txData) async { - // final priceData = - // await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency); - // Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero; - // final locale = - // Platform.isWindows ? "en_US" : await Devicelocale.currentLocale; - // final String worthNow = Format.localizedStringAsFixed( - // value: - // ((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) / - // Decimal.fromInt(Constants.satsPerCoin(coin))) - // .toDecimal(scaleOnInfinitePrecision: 2), - // decimalPlaces: 2, - // locale: locale!); - // - // final tx = models.Transaction( - // txid: txData["txid"] as String, - // confirmedStatus: false, - // timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, - // txType: "Sent", - // amount: txData["recipientAmt"] as int, - // worthNow: worthNow, - // worthAtBlockTimestamp: worthNow, - // fees: txData["fee"] as int, - // inputSize: 0, - // outputSize: 0, - // inputs: [], - // outputs: [], - // address: txData["address"] as String, - // height: -1, - // confirmations: 0, - // ); - // - // if (cachedTxData == null) { - // final data = await _fetchTransactionData(); - // _transactionData = Future(() => data); - // } - // - // final transactions = cachedTxData!.getAllTransactions(); - // transactions[tx.txid] = tx; - // cachedTxData = models.TransactionData.fromMap(transactions); - // _transactionData = Future(() => cachedTxData!); + final transaction = isar_models.Transaction( + walletId: walletId, + txid: txData["txid"] as String, + timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, + type: isar_models.TransactionType.outgoing, + subType: isar_models.TransactionSubType.none, + amount: txData["recipientAmt"] as int, + fee: txData["fee"] as int, + height: null, + isCancelled: false, + isLelantus: false, + otherData: null, + slateId: null, + ); + + final address = txData["address"] is String + ? await db.getAddress(walletId, txData["address"] as String) + : null; + + await db.addNewTransactionData( + [ + Tuple4(transaction, [], [], address), + ], + walletId, + ); } @override diff --git a/lib/services/coins/firo/firo_wallet.dart b/lib/services/coins/firo/firo_wallet.dart index 03e788e54..9f767dbba 100644 --- a/lib/services/coins/firo/firo_wallet.dart +++ b/lib/services/coins/firo/firo_wallet.dart @@ -818,44 +818,31 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive { // transactions locally in a good way @override Future updateSentCachedTxData(Map txData) async { - // final currentPrice = await firoPrice; - // final locale = - // Platform.isWindows ? "en_US" : await Devicelocale.currentLocale; - // final String worthNow = Format.localizedStringAsFixed( - // value: - // ((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) / - // Decimal.fromInt(Constants.satsPerCoin(coin))) - // .toDecimal(scaleOnInfinitePrecision: 2), - // decimalPlaces: 2, - // locale: locale!); - // - // final tx = models.Transaction( - // txid: txData["txid"] as String, - // confirmedStatus: false, - // timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, - // txType: "Sent", - // amount: txData["recipientAmt"] as int, - // worthNow: worthNow, - // worthAtBlockTimestamp: worthNow, - // fees: txData["fee"] as int, - // inputSize: 0, - // outputSize: 0, - // inputs: [], - // outputs: [], - // address: txData["address"] as String, - // height: -1, - // confirmations: 0, - // ); - // - // if (cachedTxData == null) { - // final data = await _fetchTransactionData(); - // _transactionData = Future(() => data); - // } - // - // final transactions = cachedTxData!.getAllTransactions(); - // transactions[tx.txid] = tx; - // cachedTxData = models.TransactionData.fromMap(transactions); - // _transactionData = Future(() => cachedTxData!); + final transaction = isar_models.Transaction( + walletId: walletId, + txid: txData["txid"] as String, + timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, + type: isar_models.TransactionType.outgoing, + subType: isar_models.TransactionSubType.none, + amount: txData["recipientAmt"] as int, + fee: txData["fee"] as int, + height: null, + isCancelled: false, + isLelantus: false, + otherData: null, + slateId: null, + ); + + final address = txData["address"] is String + ? await db.getAddress(walletId, txData["address"] as String) + : null; + + await db.addNewTransactionData( + [ + Tuple4(transaction, [], [], address), + ], + walletId, + ); } /// Holds the max fee that can be sent diff --git a/lib/services/coins/litecoin/litecoin_wallet.dart b/lib/services/coins/litecoin/litecoin_wallet.dart index ecbc9cbc0..03b569511 100644 --- a/lib/services/coins/litecoin/litecoin_wallet.dart +++ b/lib/services/coins/litecoin/litecoin_wallet.dart @@ -1214,46 +1214,31 @@ class LitecoinWallet extends CoinServiceAPI // transactions locally in a good way @override Future updateSentCachedTxData(Map txData) async { - // final priceData = - // await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency); - // Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero; - // final locale = - // Platform.isWindows ? "en_US" : await Devicelocale.currentLocale; - // final String worthNow = Format.localizedStringAsFixed( - // value: - // ((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) / - // Decimal.fromInt(Constants.satsPerCoin(coin))) - // .toDecimal(scaleOnInfinitePrecision: 2), - // decimalPlaces: 2, - // locale: locale!); - // - // final tx = models.Transaction( - // txid: txData["txid"] as String, - // confirmedStatus: false, - // timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, - // txType: "Sent", - // amount: txData["recipientAmt"] as int, - // worthNow: worthNow, - // worthAtBlockTimestamp: worthNow, - // fees: txData["fee"] as int, - // inputSize: 0, - // outputSize: 0, - // inputs: [], - // outputs: [], - // address: txData["address"] as String, - // height: -1, - // confirmations: 0, - // ); - // - // if (cachedTxData == null) { - // final data = await _refreshTransactions(); - // _transactionData = Future(() => data); - // } - // - // final transactions = cachedTxData!.getAllTransactions(); - // transactions[tx.txid] = tx; - // cachedTxData = models.TransactionData.fromMap(transactions); - // _transactionData = Future(() => cachedTxData!); + final transaction = isar_models.Transaction( + walletId: walletId, + txid: txData["txid"] as String, + timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, + type: isar_models.TransactionType.outgoing, + subType: isar_models.TransactionSubType.none, + amount: txData["recipientAmt"] as int, + fee: txData["fee"] as int, + height: null, + isCancelled: false, + isLelantus: false, + otherData: null, + slateId: null, + ); + + final address = txData["address"] is String + ? await db.getAddress(walletId, txData["address"] as String) + : null; + + await db.addNewTransactionData( + [ + Tuple4(transaction, [], [], address), + ], + walletId, + ); } @override diff --git a/lib/services/coins/manager.dart b/lib/services/coins/manager.dart index 892766cf5..203c2d05f 100644 --- a/lib/services/coins/manager.dart +++ b/lib/services/coins/manager.dart @@ -110,8 +110,15 @@ class Manager with ChangeNotifier { try { final txid = await _currentWallet.confirmSend(txData: txData); - txData["txid"] = txid; - await _currentWallet.updateSentCachedTxData(txData); + try { + txData["txid"] = txid; + await _currentWallet.updateSentCachedTxData(txData); + } catch (e, s) { + // do not rethrow as that would get handled as a send failure further up + // also this is not critical code and transaction should show up on \ + // refresh regardless + Logging.instance.log("$e\n$s", level: LogLevel.Warning); + } notifyListeners(); return txid; diff --git a/lib/services/coins/namecoin/namecoin_wallet.dart b/lib/services/coins/namecoin/namecoin_wallet.dart index 3129ed765..10852044b 100644 --- a/lib/services/coins/namecoin/namecoin_wallet.dart +++ b/lib/services/coins/namecoin/namecoin_wallet.dart @@ -1203,46 +1203,31 @@ class NamecoinWallet extends CoinServiceAPI // transactions locally in a good way @override Future updateSentCachedTxData(Map txData) async { - // final priceData = - // await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency); - // Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero; - // final locale = - // Platform.isWindows ? "en_US" : await Devicelocale.currentLocale; - // final String worthNow = Format.localizedStringAsFixed( - // value: - // ((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) / - // Decimal.fromInt(Constants.satsPerCoin(coin))) - // .toDecimal(scaleOnInfinitePrecision: 2), - // decimalPlaces: 2, - // locale: locale!); - // - // final tx = models.Transaction( - // txid: txData["txid"] as String, - // confirmedStatus: false, - // timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, - // txType: "Sent", - // amount: txData["recipientAmt"] as int, - // worthNow: worthNow, - // worthAtBlockTimestamp: worthNow, - // fees: txData["fee"] as int, - // inputSize: 0, - // outputSize: 0, - // inputs: [], - // outputs: [], - // address: txData["address"] as String, - // height: -1, - // confirmations: 0, - // ); - // - // if (cachedTxData == null) { - // final data = await _refreshTransactions(); - // _transactionData = Future(() => data); - // } - // - // final transactions = cachedTxData!.getAllTransactions(); - // transactions[tx.txid] = tx; - // cachedTxData = models.TransactionData.fromMap(transactions); - // _transactionData = Future(() => cachedTxData!); + final transaction = isar_models.Transaction( + walletId: walletId, + txid: txData["txid"] as String, + timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, + type: isar_models.TransactionType.outgoing, + subType: isar_models.TransactionSubType.none, + amount: txData["recipientAmt"] as int, + fee: txData["fee"] as int, + height: null, + isCancelled: false, + isLelantus: false, + otherData: null, + slateId: null, + ); + + final address = txData["address"] is String + ? await db.getAddress(walletId, txData["address"] as String) + : null; + + await db.addNewTransactionData( + [ + Tuple4(transaction, [], [], address), + ], + walletId, + ); } @override diff --git a/lib/services/coins/particl/particl_wallet.dart b/lib/services/coins/particl/particl_wallet.dart index 7b99eae00..1f6c7a2ea 100644 --- a/lib/services/coins/particl/particl_wallet.dart +++ b/lib/services/coins/particl/particl_wallet.dart @@ -1131,46 +1131,31 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { // transactions locally in a good way @override Future updateSentCachedTxData(Map txData) async { - // final priceData = - // await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency); - // Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero; - // final locale = - // Platform.isWindows ? "en_US" : await Devicelocale.currentLocale; - // final String worthNow = Format.localizedStringAsFixed( - // value: - // ((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) / - // Decimal.fromInt(Constants.satsPerCoin(coin))) - // .toDecimal(scaleOnInfinitePrecision: 2), - // decimalPlaces: 2, - // locale: locale!); - // - // final tx = models.Transaction( - // txid: txData["txid"] as String, - // confirmedStatus: false, - // timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, - // txType: "Sent", - // amount: txData["recipientAmt"] as int, - // worthNow: worthNow, - // worthAtBlockTimestamp: worthNow, - // fees: txData["fee"] as int, - // inputSize: 0, - // outputSize: 0, - // inputs: [], - // outputs: [], - // address: txData["address"] as String, - // height: -1, - // confirmations: 0, - // ); - // - // if (cachedTxData == null) { - // final data = await _refreshTransactions(); - // _transactionData = Future(() => data); - // } else { - // final transactions = cachedTxData!.getAllTransactions(); - // transactions[tx.txid] = tx; - // cachedTxData = models.TransactionData.fromMap(transactions); - // _transactionData = Future(() => cachedTxData!); - // } + final transaction = isar_models.Transaction( + walletId: walletId, + txid: txData["txid"] as String, + timestamp: DateTime.now().millisecondsSinceEpoch ~/ 1000, + type: isar_models.TransactionType.outgoing, + subType: isar_models.TransactionSubType.none, + amount: txData["recipientAmt"] as int, + fee: txData["fee"] as int, + height: null, + isCancelled: false, + isLelantus: false, + otherData: null, + slateId: null, + ); + + final address = txData["address"] is String + ? await db.getAddress(walletId, txData["address"] as String) + : null; + + await db.addNewTransactionData( + [ + Tuple4(transaction, [], [], address), + ], + walletId, + ); } @override