cake_wallet/cw_lightning/lib/lightning_transaction_info.dart

58 lines
1.8 KiB
Dart
Raw Normal View History

2024-02-22 03:03:19 +00:00
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
2024-03-04 18:34:46 +00:00
import 'package:cw_bitcoin/electrum_transaction_info.dart';
2024-02-22 03:03:19 +00:00
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/format_amount.dart';
import 'package:cw_core/wallet_type.dart';
2024-03-04 18:34:46 +00:00
class LightningTransactionInfo extends ElectrumTransactionInfo {
LightningTransactionInfo({
2024-03-01 17:55:44 +00:00
required String id,
required int amount,
int? fee,
required TransactionDirection direction,
required bool isPending,
required DateTime date,
2024-03-04 18:34:46 +00:00
}) : super(
WalletType.lightning,
amount: amount,
fee: fee,
direction: direction,
date: date,
isPending: isPending,
id: id,
confirmations: 0,
height: 0,
) {}
2024-02-22 03:03:19 +00:00
@override
String amountFormatted() =>
2024-03-01 16:13:59 +00:00
'${formatAmount(bitcoinAmountToLightningString(amount: amount))} ${walletTypeToCryptoCurrency(type).title}';
2024-02-22 03:03:19 +00:00
@override
String? feeFormatted() => fee != null
2024-03-01 16:13:59 +00:00
? '${formatAmount(bitcoinAmountToLightningString(amount: fee!))} ${walletTypeToCryptoCurrency(type).title}'
2024-02-22 03:03:19 +00:00
: '';
2024-03-04 18:34:46 +00:00
factory LightningTransactionInfo.fromJson(Map<String, dynamic> data, WalletType type) {
2024-03-01 17:55:44 +00:00
return LightningTransactionInfo(
2024-03-04 18:34:46 +00:00
id: data['id'] as String,
amount: data['amount'] as int,
fee: data['fee'] as int,
direction: parseTransactionDirectionFromInt(data['direction'] as int),
date: DateTime.fromMillisecondsSinceEpoch(data['date'] as int),
isPending: data['isPending'] as bool,
2024-03-01 17:55:44 +00:00
);
2024-02-22 03:03:19 +00:00
}
Map<String, dynamic> toJson() {
final m = <String, dynamic>{};
m['id'] = id;
m['amount'] = amount;
m['direction'] = direction.index;
m['date'] = date.millisecondsSinceEpoch;
m['isPending'] = isPending;
m['fee'] = fee;
return m;
}
}