cake_wallet/lib/monero/monero_transaction_info.dart

66 lines
2.3 KiB
Dart
Raw Normal View History

2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/entities/transaction_info.dart';
import 'package:cake_wallet/monero/monero_amount_format.dart';
2020-05-12 12:04:54 +00:00
import 'package:cw_monero/structs/transaction_info_row.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/entities/parseBoolFromString.dart';
import 'package:cake_wallet/entities/transaction_direction.dart';
import 'package:cake_wallet/entities/format_amount.dart';
2020-09-24 15:11:29 +00:00
import 'package:cw_monero/transaction_history.dart';
2020-05-12 12:04:54 +00:00
class MoneroTransactionInfo extends TransactionInfo {
MoneroTransactionInfo(this.id, this.height, this.direction, this.date,
2020-11-10 22:24:50 +00:00
this.isPending, this.amount, this.accountIndex, this.fee);
2020-05-12 12:04:54 +00:00
MoneroTransactionInfo.fromMap(Map map)
: id = (map['hash'] ?? '') as String,
height = (map['height'] ?? 0) as int,
direction =
parseTransactionDirectionFromNumber(map['direction'] as String) ??
TransactionDirection.incoming,
date = DateTime.fromMillisecondsSinceEpoch(
(int.parse(map['timestamp'] as String) ?? 0) * 1000),
isPending = parseBoolFromString(map['isPending'] as String),
amount = map['amount'] as int,
2020-09-24 15:11:29 +00:00
accountIndex = int.parse(map['accountIndex'] as String),
2020-11-10 22:24:50 +00:00
key = getTxKey((map['hash'] ?? '') as String),
fee = map['fee'] as int ?? 0;
2020-05-12 12:04:54 +00:00
MoneroTransactionInfo.fromRow(TransactionInfoRow row)
: id = row.getHash(),
height = row.blockHeight,
direction = parseTransactionDirectionFromInt(row.direction) ??
TransactionDirection.incoming,
date = DateTime.fromMillisecondsSinceEpoch(row.getDatetime() * 1000),
isPending = row.isPending != 0,
amount = row.getAmount(),
2020-09-24 15:11:29 +00:00
accountIndex = row.subaddrAccount,
2020-11-10 22:24:50 +00:00
key = getTxKey(row.getHash()),
fee = row.fee;
2020-05-12 12:04:54 +00:00
final String id;
final int height;
final TransactionDirection direction;
final DateTime date;
final int accountIndex;
final bool isPending;
final int amount;
2020-11-10 22:24:50 +00:00
final int fee;
2020-05-12 12:04:54 +00:00
String recipientAddress;
2020-09-24 15:11:29 +00:00
String key;
2020-05-12 12:04:54 +00:00
String _fiatAmount;
2020-09-24 15:11:29 +00:00
@override
2020-11-10 22:24:50 +00:00
String amountFormatted() =>
'${formatAmount(moneroAmountToString(amount: amount))} XMR';
2020-05-12 12:04:54 +00:00
2020-09-24 15:11:29 +00:00
@override
2020-05-12 12:04:54 +00:00
String fiatAmount() => _fiatAmount ?? '';
2020-11-06 18:54:00 +00:00
@override
2020-05-12 12:04:54 +00:00
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
2020-11-10 22:24:50 +00:00
@override
2020-11-10 22:24:50 +00:00
String feeFormatted() =>
'${formatAmount(moneroAmountToString(amount: fee))} XMR';
2020-05-12 12:04:54 +00:00
}