2021-12-24 12:52:08 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
|
|
|
|
import 'package:cw_core/balance.dart';
|
|
|
|
|
|
|
|
class ElectrumBalance extends Balance {
|
2024-03-11 12:46:20 +00:00
|
|
|
ElectrumBalance({
|
|
|
|
required this.confirmed,
|
|
|
|
required this.unconfirmed,
|
|
|
|
required this.frozen,
|
|
|
|
}) : super(confirmed, unconfirmed);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
static ElectrumBalance? fromJSON(String? jsonSource) {
|
2021-12-24 12:52:08 +00:00
|
|
|
if (jsonSource == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final decoded = json.decode(jsonSource) as Map;
|
|
|
|
|
|
|
|
return ElectrumBalance(
|
2022-10-12 17:09:57 +00:00
|
|
|
confirmed: decoded['confirmed'] as int? ?? 0,
|
2023-04-20 13:46:41 +00:00
|
|
|
unconfirmed: decoded['unconfirmed'] as int? ?? 0,
|
|
|
|
frozen: decoded['frozen'] as int? ?? 0);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 12:46:20 +00:00
|
|
|
int confirmed;
|
2024-04-17 19:35:11 +00:00
|
|
|
int unconfirmed;
|
2023-04-20 13:46:41 +00:00
|
|
|
final int frozen;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@override
|
2024-01-08 14:03:46 +00:00
|
|
|
String get formattedAvailableBalance => bitcoinAmountToString(amount: confirmed - frozen);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@override
|
2024-01-08 14:03:46 +00:00
|
|
|
String get formattedAdditionalBalance => bitcoinAmountToString(amount: unconfirmed);
|
2023-04-20 13:46:41 +00:00
|
|
|
|
2023-12-13 14:43:26 +00:00
|
|
|
@override
|
|
|
|
String get formattedUnAvailableBalance {
|
2023-04-20 13:46:41 +00:00
|
|
|
final frozenFormatted = bitcoinAmountToString(amount: frozen);
|
|
|
|
return frozenFormatted == '0.0' ? '' : frozenFormatted;
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2024-01-08 14:03:46 +00:00
|
|
|
String toJSON() =>
|
|
|
|
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed, 'frozen': frozen});
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|