From c34a45ed10dd6fe23a1838553c27b8f39f487d5f Mon Sep 17 00:00:00 2001 From: vjrj <vjrj@comunes.org> Date: Sat, 30 Dec 2023 12:54:21 +0100 Subject: [PATCH] Use ContactsCache in transaction parser --- lib/g1/transaction_parser.dart | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/g1/transaction_parser.dart b/lib/g1/transaction_parser.dart index baddc7a..f918025 100644 --- a/lib/g1/transaction_parser.dart +++ b/lib/g1/transaction_parser.dart @@ -4,6 +4,7 @@ import '../data/models/contact.dart'; import '../data/models/transaction.dart'; import '../data/models/transaction_state.dart'; import '../data/models/transaction_type.dart'; +import '../ui/contacts_cache.dart'; import 'g1_helper.dart'; final RegExp exp = RegExp(r'\((.*?)\)'); @@ -42,8 +43,8 @@ Future<TransactionState> transactionParser( logger('Timestamp: $timestamp'); logger('Fecha: $txDate'); } */ - final Contact fromC = Contact(pubKey: address2!); - final Contact toC = Contact(pubKey: address1!); + final Contact fromC = getContactCache(pubKey: address2!); + final Contact toC = getContactCache(pubKey: address1!); tx.insert( 0, @@ -62,6 +63,14 @@ Future<TransactionState> transactionParser( lastChecked: DateTime.now()); } +Contact getContactCache({required String pubKey}) { + final Contact contact = + ContactsCache().getCachedContact(pubKey, false, true) ?? + Contact(pubKey: pubKey); + assert(contact.hasAvatar == false); + return contact; +} + Future<TransactionState> transactionsGvaParser(Map<String, dynamic> txData, TransactionState state, String myPubKeyRaw) async { final String myPubKey = extractPublicKey(myPubKeyRaw); @@ -91,7 +100,7 @@ Future<TransactionState> transactionsGvaParser(Map<String, dynamic> txData, final Transaction tx = await _transactionGvaParser(edgeRaw as Map<String, dynamic>, myPubKey); if (tx.from.pubKey == myPubKey && - tx.to.pubKey == myPubKey && + tx.recipients[0].pubKey == myPubKey && tx.recipients.length == 1) { // This is a return cash back to me continue; @@ -148,7 +157,7 @@ Future<Transaction> _txGvaParse( // Extract the recipient from each output final String outputS = output as String; final String? recipient = exp.firstMatch(outputS)!.group(1); - final Contact recipientContact = Contact(pubKey: recipient!); + final Contact recipientContact = getContactCache(pubKey: recipient!); recipients.add(recipientContact); final double outputAmount = double.parse(outputS.split(':')[0]); @@ -182,7 +191,7 @@ Future<Transaction> _txGvaParse( } // Comment final String comment = tx['comment'] as String; - final Contact fromC = Contact(pubKey: from); + final Contact fromC = getContactCache(pubKey: from); return Transaction( type: type, -- GitLab