2021-12-24 12:52:08 +00:00
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 ' ;
2022-10-12 17:09:57 +00:00
// import 'package:cake_wallet/core/amount_converter.dart';
2022-01-17 15:46:49 +00:00
2021-12-24 12:52:08 +00:00
import ' package:cw_core/pending_transaction.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 ) ;
final PendingTransactionDescription pendingTransactionDescription ;
@ override
String get id = > pendingTransactionDescription . hash ;
2022-07-28 17:03:16 +00:00
@ override
String get hex = > pendingTransactionDescription . hex ;
String get txKey = > pendingTransactionDescription . txKey ;
2022-10-12 17:09:57 +00:00
// FIX-ME: AmountConverter
2021-12-24 12:52:08 +00:00
@ override
2022-10-12 17:09:57 +00:00
String get amountFormatted = > ' ' ;
// AmountConverter.amountIntToString(
// CryptoCurrency.xmr, pendingTransactionDescription.amount);
2021-12-24 12:52:08 +00:00
2022-10-12 17:09:57 +00:00
// FIX-ME: AmountConverter
2021-12-24 12:52:08 +00:00
@ override
2022-10-12 17:09:57 +00:00
String get feeFormatted = > ' ' ;
// AmountConverter.amountIntToString(
// CryptoCurrency.xmr, pendingTransactionDescription.fee);
2021-12-24 12:52:08 +00:00
@ override
Future < void > commit ( ) async {
try {
monero_transaction_history . commitTransactionFromPointerAddress (
address: pendingTransactionDescription . pointerAddress ) ;
} catch ( e ) {
final message = e . toString ( ) ;
if ( message . contains ( ' Reason: double spend ' ) ) {
throw DoubleSpendException ( ) ;
}
rethrow ;
}
}
}