2020-06-20 07:10:00 +00:00
|
|
|
import 'dart:convert';
|
2020-05-12 12:04:54 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/balance.dart';
|
2020-05-12 12:04:54 +00:00
|
|
|
|
2021-05-07 07:36:38 +00:00
|
|
|
class ElectrumBalance extends Balance {
|
|
|
|
const ElectrumBalance({@required this.confirmed, @required this.unconfirmed})
|
2021-01-11 17:15:27 +00:00
|
|
|
: super(confirmed, unconfirmed);
|
2020-06-20 07:10:00 +00:00
|
|
|
|
2021-05-07 07:36:38 +00:00
|
|
|
factory ElectrumBalance.fromJSON(String jsonSource) {
|
2020-06-20 07:10:00 +00:00
|
|
|
if (jsonSource == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final decoded = json.decode(jsonSource) as Map;
|
|
|
|
|
2021-05-07 07:36:38 +00:00
|
|
|
return ElectrumBalance(
|
2020-06-20 07:10:00 +00:00
|
|
|
confirmed: decoded['confirmed'] as int ?? 0,
|
|
|
|
unconfirmed: decoded['unconfirmed'] as int ?? 0);
|
|
|
|
}
|
2020-05-12 12:04:54 +00:00
|
|
|
|
|
|
|
final int confirmed;
|
|
|
|
final int unconfirmed;
|
2020-06-20 07:10:00 +00:00
|
|
|
|
2021-01-11 17:15:27 +00:00
|
|
|
@override
|
2021-05-07 07:36:38 +00:00
|
|
|
String get formattedAvailableBalance =>
|
|
|
|
bitcoinAmountToString(amount: confirmed);
|
2020-12-18 15:49:10 +00:00
|
|
|
|
2020-12-15 16:29:10 +00:00
|
|
|
@override
|
2021-01-11 17:15:27 +00:00
|
|
|
String get formattedAdditionalBalance =>
|
|
|
|
bitcoinAmountToString(amount: unconfirmed);
|
2020-12-15 16:29:10 +00:00
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
String toJSON() =>
|
|
|
|
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed});
|
2020-05-12 12:04:54 +00:00
|
|
|
}
|