2024-07-19 19:26:15 +00:00
|
|
|
import 'dart:math';
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_core/transaction_info.dart';
|
2022-03-30 15:57:04 +00:00
|
|
|
import 'package:cw_core/monero_amount_format.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_monero/api/structs/transaction_info_row.dart';
|
|
|
|
import 'package:cw_core/parseBoolFromString.dart';
|
|
|
|
import 'package:cw_core/transaction_direction.dart';
|
|
|
|
import 'package:cw_core/format_amount.dart';
|
|
|
|
import 'package:cw_monero/api/transaction_history.dart';
|
|
|
|
|
|
|
|
class MoneroTransactionInfo extends TransactionInfo {
|
2024-07-19 19:26:15 +00:00
|
|
|
MoneroTransactionInfo(this.txhash, this.height, this.direction, this.date,
|
2023-02-08 16:47:12 +00:00
|
|
|
this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee,
|
2024-07-19 19:26:15 +00:00
|
|
|
this.confirmations) :
|
|
|
|
id = "${txhash}_${amount}_${accountIndex}_${addressIndex}";
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
MoneroTransactionInfo.fromMap(Map<String, Object?> map)
|
2024-07-19 19:26:15 +00:00
|
|
|
: id = "${map['hash']}_${map['amount']}_${map['accountIndex']}_${map['addressIndex']}",
|
|
|
|
txhash = map['hash'] as String,
|
2021-12-24 12:52:08 +00:00
|
|
|
height = (map['height'] ?? 0) as int,
|
2023-08-04 17:01:49 +00:00
|
|
|
direction = map['direction'] != null
|
|
|
|
? parseTransactionDirectionFromNumber(map['direction'] as String)
|
|
|
|
: TransactionDirection.incoming,
|
2021-12-24 12:52:08 +00:00
|
|
|
date = DateTime.fromMillisecondsSinceEpoch(
|
2023-08-04 17:01:49 +00:00
|
|
|
(int.tryParse(map['timestamp'] as String? ?? '') ?? 0) * 1000),
|
2021-12-24 12:52:08 +00:00
|
|
|
isPending = parseBoolFromString(map['isPending'] as String),
|
|
|
|
amount = map['amount'] as int,
|
|
|
|
accountIndex = int.parse(map['accountIndex'] as String),
|
|
|
|
addressIndex = map['addressIndex'] as int,
|
2023-02-08 16:47:12 +00:00
|
|
|
confirmations = map['confirmations'] as int,
|
2021-12-24 12:52:08 +00:00
|
|
|
key = getTxKey((map['hash'] ?? '') as String),
|
2023-08-04 17:01:49 +00:00
|
|
|
fee = map['fee'] as int? ?? 0 {
|
2022-10-12 17:09:57 +00:00
|
|
|
additionalInfo = <String, dynamic>{
|
2022-01-31 12:08:38 +00:00
|
|
|
'key': key,
|
|
|
|
'accountIndex': accountIndex,
|
|
|
|
'addressIndex': addressIndex
|
|
|
|
};
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
MoneroTransactionInfo.fromRow(TransactionInfoRow row)
|
2024-07-19 19:26:15 +00:00
|
|
|
: id = "${row.getHash()}_${row.getAmount()}_${row.subaddrAccount}_${row.subaddrIndex}",
|
|
|
|
txhash = row.getHash(),
|
2021-12-24 12:52:08 +00:00
|
|
|
height = row.blockHeight,
|
2023-08-04 17:01:49 +00:00
|
|
|
direction = parseTransactionDirectionFromInt(row.direction),
|
2021-12-24 12:52:08 +00:00
|
|
|
date = DateTime.fromMillisecondsSinceEpoch(row.getDatetime() * 1000),
|
|
|
|
isPending = row.isPending != 0,
|
|
|
|
amount = row.getAmount(),
|
|
|
|
accountIndex = row.subaddrAccount,
|
|
|
|
addressIndex = row.subaddrIndex,
|
2023-02-08 16:47:12 +00:00
|
|
|
confirmations = row.confirmations,
|
2021-12-24 12:52:08 +00:00
|
|
|
key = getTxKey(row.getHash()),
|
2022-01-31 12:08:38 +00:00
|
|
|
fee = row.fee {
|
2022-10-12 17:09:57 +00:00
|
|
|
additionalInfo = <String, dynamic>{
|
2022-01-31 12:08:38 +00:00
|
|
|
'key': key,
|
|
|
|
'accountIndex': accountIndex,
|
|
|
|
'addressIndex': addressIndex
|
|
|
|
};
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
final String id;
|
2024-07-19 19:26:15 +00:00
|
|
|
final String txhash;
|
2021-12-24 12:52:08 +00:00
|
|
|
final int height;
|
|
|
|
final TransactionDirection direction;
|
|
|
|
final DateTime date;
|
|
|
|
final int accountIndex;
|
|
|
|
final bool isPending;
|
|
|
|
final int amount;
|
|
|
|
final int fee;
|
|
|
|
final int addressIndex;
|
2023-02-08 16:47:12 +00:00
|
|
|
final int confirmations;
|
2022-10-12 17:09:57 +00:00
|
|
|
String? recipientAddress;
|
|
|
|
String? key;
|
|
|
|
String? _fiatAmount;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String amountFormatted() =>
|
|
|
|
'${formatAmount(moneroAmountToString(amount: amount))} XMR';
|
|
|
|
|
|
|
|
@override
|
|
|
|
String fiatAmount() => _fiatAmount ?? '';
|
|
|
|
|
|
|
|
@override
|
|
|
|
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
|
|
|
|
|
|
|
|
@override
|
|
|
|
String feeFormatted() =>
|
|
|
|
'${formatAmount(moneroAmountToString(amount: fee))} XMR';
|
|
|
|
}
|