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
|
|
|
|
|
|
|
class BitcoinBalance extends Balance {
|
2020-12-15 16:29:10 +00:00
|
|
|
const BitcoinBalance({@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
|
|
|
|
|
|
|
factory BitcoinBalance.fromJSON(String jsonSource) {
|
|
|
|
if (jsonSource == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final decoded = json.decode(jsonSource) as Map;
|
|
|
|
|
|
|
|
return BitcoinBalance(
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|