2021-12-24 12:52:08 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
|
|
|
|
import 'package:cw_core/balance.dart';
|
|
|
|
|
|
|
|
class ElectrumBalance extends Balance {
|
2022-10-12 17:09:57 +00:00
|
|
|
const ElectrumBalance({required this.confirmed, required this.unconfirmed})
|
2021-12-24 12:52:08 +00:00
|
|
|
: super(confirmed, unconfirmed);
|
|
|
|
|
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,
|
|
|
|
unconfirmed: decoded['unconfirmed'] as int? ?? 0);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final int confirmed;
|
|
|
|
final int unconfirmed;
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get formattedAvailableBalance =>
|
|
|
|
bitcoinAmountToString(amount: confirmed);
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get formattedAdditionalBalance =>
|
|
|
|
bitcoinAmountToString(amount: unconfirmed);
|
|
|
|
|
|
|
|
String toJSON() =>
|
|
|
|
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed});
|
|
|
|
}
|