mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
* 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 * Update lib/view_model/send/send_view_model.dart --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
88 lines
2.6 KiB
Dart
88 lines
2.6 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cw_monero/api/account_list.dart';
|
|
import 'package:cw_monero/api/structs/pending_transaction.dart';
|
|
import 'package:cw_monero/api/transaction_history.dart'
|
|
as monero_transaction_history;
|
|
import 'package:cw_core/crypto_currency.dart';
|
|
import 'package:cw_core/amount_converter.dart';
|
|
|
|
import 'package:cw_core/pending_transaction.dart';
|
|
import 'package:cw_monero/api/wallet.dart';
|
|
import 'package:cw_monero/monero_wallet.dart';
|
|
|
|
class DoubleSpendException implements Exception {
|
|
DoubleSpendException();
|
|
|
|
@override
|
|
String toString() =>
|
|
'This transaction cannot be committed. This can be due to many reasons including the wallet not being synced, there is not enough XMR in your available balance, or previous transactions are not yet fully processed.';
|
|
}
|
|
|
|
class PendingMoneroTransaction with PendingTransaction {
|
|
PendingMoneroTransaction(this.pendingTransactionDescription, this.wallet);
|
|
|
|
final PendingTransactionDescription pendingTransactionDescription;
|
|
final MoneroWalletBase wallet;
|
|
|
|
@override
|
|
String get id => pendingTransactionDescription.hash;
|
|
|
|
@override
|
|
String get hex => pendingTransactionDescription.hex;
|
|
|
|
@override
|
|
String get amountFormatted => AmountConverter.amountIntToString(
|
|
CryptoCurrency.xmr, pendingTransactionDescription.amount);
|
|
|
|
@override
|
|
String get feeFormatted => AmountConverter.amountIntToString(
|
|
CryptoCurrency.xmr, pendingTransactionDescription.fee);
|
|
|
|
bool shouldCommitUR() => isViewOnly;
|
|
|
|
@override
|
|
Future<void> commit() async {
|
|
try {
|
|
await monero_transaction_history.commitTransactionFromPointerAddress(
|
|
address: pendingTransactionDescription.pointerAddress,
|
|
useUR: false);
|
|
} catch (e) {
|
|
final message = e.toString();
|
|
|
|
if (message.contains('Reason: double spend')) {
|
|
throw DoubleSpendException();
|
|
}
|
|
|
|
rethrow;
|
|
}
|
|
storeSync(force: true);
|
|
unawaited(() async {
|
|
await Future.delayed(const Duration(milliseconds: 250));
|
|
await wallet.fetchTransactions();
|
|
}());
|
|
}
|
|
|
|
@override
|
|
Future<String?> commitUR() async {
|
|
try {
|
|
final ret = await monero_transaction_history.commitTransactionFromPointerAddress(
|
|
address: pendingTransactionDescription.pointerAddress,
|
|
useUR: true);
|
|
storeSync(force: true);
|
|
unawaited(() async {
|
|
await Future.delayed(const Duration(milliseconds: 250));
|
|
await wallet.fetchTransactions();
|
|
}());
|
|
return ret;
|
|
} catch (e) {
|
|
final message = e.toString();
|
|
|
|
if (message.contains('Reason: double spend')) {
|
|
throw DoubleSpendException();
|
|
}
|
|
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|