Skip to content

Commit 9b5b70e

Browse files
committed
fix(cw_monero): call store() directly after commiting tx to make sure that tx key is written to cache
also, store it in TransactionDescription hive box
1 parent b0edf1f commit 9b5b70e

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

cw_monero/lib/api/structs/pending_transaction.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ class PendingTransactionDescription {
55
required this.fee,
66
required this.hash,
77
required this.hex,
8-
required this.txKey,
98
required this.pointerAddress});
109

1110
final int amount;
1211
final int fee;
1312
final String hash;
1413
final String hex;
15-
final String txKey;
1614
final int pointerAddress;
1715
}

cw_monero/lib/api/transaction_history.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:ffi';
23
import 'dart:isolate';
34

@@ -194,14 +195,12 @@ Future<PendingTransactionDescription> createTransactionSync(
194195
final rFee = pendingTx.fee();
195196
final rHash = pendingTx.txid('');
196197
final rHex = pendingTx.hex('');
197-
final rTxKey = rHash;
198198

199199
return PendingTransactionDescription(
200200
amount: rAmt,
201201
fee: rFee,
202202
hash: rHash,
203203
hex: rHex,
204-
txKey: rTxKey,
205204
pointerAddress: pendingTx.ffiAddress(),
206205
);
207206
}
@@ -246,7 +245,6 @@ Future<PendingTransactionDescription> createTransactionMultDest(
246245
fee: tx.fee(),
247246
hash: tx.txid(''),
248247
hex: tx.hex(''),
249-
txKey: tx.txid(''),
250248
pointerAddress: tx.ffiAddress(),
251249
);
252250
}
@@ -263,6 +261,7 @@ Future<String?> commitTransaction({required Wallet2PendingTransaction tx, requir
263261
filename: '',
264262
overwrite: false,
265263
);
264+
return null;
266265
});
267266

268267
String? error = (() {
@@ -285,11 +284,12 @@ Future<String?> commitTransaction({required Wallet2PendingTransaction tx, requir
285284
if (error != null && error != "no tx keys found for this txid") {
286285
throw CreationTransactionException(message: error);
287286
}
288-
if (useUR) {
289-
return Future.value(txCommit as String?);
290-
} else {
291-
return Future.value(null);
292-
}
287+
unawaited(() async {
288+
storeSync(force: true);
289+
await Future.delayed(Duration(seconds: 5));
290+
storeSync(force: true);
291+
}());
292+
return Future.value(txCommit);
293293
}
294294

295295
class Transaction {

cw_monero/lib/pending_monero_transaction.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class PendingMoneroTransaction with PendingTransaction {
3131
@override
3232
String get hex => pendingTransactionDescription.hex;
3333

34-
String get txKey => pendingTransactionDescription.txKey;
35-
3634
@override
3735
String get amountFormatted => AmountConverter.amountIntToString(
3836
CryptoCurrency.xmr, pendingTransactionDescription.amount);

lib/entities/transaction_description.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ part 'transaction_description.g.dart';
55

66
@HiveType(typeId: TransactionDescription.typeId)
77
class TransactionDescription extends HiveObject {
8-
TransactionDescription({required this.id, this.recipientAddress, this.transactionNote});
8+
TransactionDescription({required this.id, this.recipientAddress, this.transactionNote, this.transactionKey});
99

1010
static const typeId = TRANSACTION_TYPE_ID;
1111
static const boxName = 'TransactionDescriptions';
@@ -20,19 +20,24 @@ class TransactionDescription extends HiveObject {
2020
@HiveField(2)
2121
String? transactionNote;
2222

23+
@HiveField(3)
24+
String? transactionKey;
25+
2326
String get note => transactionNote ?? '';
2427

2528
Map<String, dynamic> toJson() => {
2629
'id': id,
2730
'recipientAddress': recipientAddress,
2831
'transactionNote': transactionNote,
32+
'transactionKey': transactionKey,
2933
};
3034

3135
factory TransactionDescription.fromJson(Map<String, dynamic> json) {
3236
return TransactionDescription(
3337
id: json['id'] as String,
3438
recipientAddress: json['recipientAddress'] as String?,
3539
transactionNote: json['transactionNote'] as String?,
40+
transactionKey: json['transactionKey'] as String?,
3641
);
3742
}
3843
}

lib/monero/cw_monero.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class CWMonero extends Monero {
365365
@override
366366
Map<String, String> pendingTransactionInfo(Object transaction) {
367367
final ptx = transaction as PendingMoneroTransaction;
368-
return {'id': ptx.id, 'hex': ptx.hex, 'key': ptx.txKey};
368+
return {'id': ptx.id, 'hex': ptx.hex};
369369
}
370370

371371
@override

lib/view_model/send/send_view_model.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,16 +590,25 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
590590
}
591591

592592
if (pendingTransaction!.id.isNotEmpty) {
593+
TransactionInfo? tx;
594+
if (walletType == WalletType.monero) {
595+
await Future.delayed(Duration(milliseconds: 450));
596+
await wallet.fetchTransactions();
597+
final txhistory = monero!.getTransactionHistory(wallet);
598+
tx = txhistory.transactions[txhistory.transactions.keys.toList()[txhistory.transactions.keys.length - 1]];
599+
}
593600
final descriptionKey = '${pendingTransaction!.id}_${wallet.walletAddresses.primaryAddress}';
594601
_settingsStore.shouldSaveRecipientAddress
595602
? await transactionDescriptionBox.add(TransactionDescription(
596603
id: descriptionKey,
597604
recipientAddress: address,
598605
transactionNote: note,
606+
transactionKey: tx?.additionalInfo["key"] as String?,
599607
))
600608
: await transactionDescriptionBox.add(TransactionDescription(
601609
id: descriptionKey,
602610
transactionNote: note,
611+
transactionKey: tx?.additionalInfo["key"] as String?,
603612
));
604613
}
605614
final sharedPreferences = await SharedPreferences.getInstance();

lib/view_model/transaction_details_view_model.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,13 @@ abstract class TransactionDetailsViewModelBase with Store {
233233
}
234234

235235
void _addMoneroListItems(TransactionInfo tx, DateFormat dateFormat) {
236-
final key = tx.additionalInfo['key'] as String?;
236+
final descriptionKey = '${transactionInfo.txHash}_${wallet.walletAddresses.primaryAddress}';
237+
final description = transactionDescriptionBox.values.firstWhere(
238+
(val) => val.id == descriptionKey || val.id == transactionInfo.txHash,
239+
orElse: () => TransactionDescription(id: descriptionKey));
240+
241+
242+
final key = tx.additionalInfo['key'] as String? ?? description.transactionKey;
237243
final accountIndex = tx.additionalInfo['accountIndex'] as int;
238244
final addressIndex = tx.additionalInfo['addressIndex'] as int;
239245
final feeFormatted = tx.feeFormatted();

0 commit comments

Comments
 (0)