2024-02-16 20:37:08 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
|
2024-03-04 17:47:39 +00:00
|
|
|
import 'package:cw_bitcoin/electrum_balance.dart';
|
2024-02-16 20:37:08 +00:00
|
|
|
import 'package:cw_core/balance.dart';
|
|
|
|
|
2024-03-04 17:47:39 +00:00
|
|
|
class LightningBalance extends ElectrumBalance {
|
2024-02-16 20:37:08 +00:00
|
|
|
const LightningBalance({required this.confirmed, required this.unconfirmed, required this.frozen})
|
2024-03-04 17:47:39 +00:00
|
|
|
: super(
|
|
|
|
confirmed: confirmed,
|
|
|
|
unconfirmed: unconfirmed,
|
|
|
|
frozen: frozen,
|
|
|
|
);
|
2024-02-16 20:37:08 +00:00
|
|
|
|
|
|
|
static LightningBalance? fromJSON(String? jsonSource) {
|
|
|
|
if (jsonSource == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final decoded = json.decode(jsonSource) as Map;
|
|
|
|
|
|
|
|
return LightningBalance(
|
|
|
|
confirmed: decoded['confirmed'] as int? ?? 0,
|
|
|
|
unconfirmed: decoded['unconfirmed'] as int? ?? 0,
|
|
|
|
frozen: decoded['frozen'] as int? ?? 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
final int confirmed;
|
|
|
|
final int unconfirmed;
|
|
|
|
final int frozen;
|
|
|
|
|
|
|
|
@override
|
2024-02-20 17:02:52 +00:00
|
|
|
String get formattedAvailableBalance => bitcoinAmountToLightningString(amount: confirmed);
|
2024-02-16 20:37:08 +00:00
|
|
|
|
|
|
|
@override
|
2024-02-20 17:02:52 +00:00
|
|
|
String get formattedAdditionalBalance => bitcoinAmountToLightningString(amount: unconfirmed);
|
2024-02-16 20:37:08 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String get formattedUnAvailableBalance {
|
2024-03-05 17:51:20 +00:00
|
|
|
final frozenFormatted = bitcoinAmountToLightningString(amount: frozen);
|
2024-02-16 20:37:08 +00:00
|
|
|
return frozenFormatted == '0.0' ? '' : frozenFormatted;
|
|
|
|
}
|
|
|
|
|
|
|
|
String toJSON() =>
|
|
|
|
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed, 'frozen': frozen});
|
|
|
|
}
|