cake_wallet/lib/bitcoin/bitcoin_balance.dart

36 lines
1 KiB
Dart
Raw Normal View History

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-06-20 07:10:00 +00:00
const BitcoinBalance({@required this.confirmed, @required this.unconfirmed}) : super();
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
2020-05-12 12:04:54 +00:00
int get total => confirmed + unconfirmed;
2020-06-20 07:10:00 +00:00
2020-05-12 12:04:54 +00:00
String get confirmedFormatted => bitcoinAmountToString(amount: confirmed);
2020-06-20 07:10:00 +00:00
2020-05-12 12:04:54 +00:00
String get unconfirmedFormatted => bitcoinAmountToString(amount: unconfirmed);
2020-06-20 07:10:00 +00:00
2020-05-12 12:04:54 +00:00
String get totalFormatted => bitcoinAmountToString(amount: total);
2020-06-20 07:10:00 +00:00
String toJSON() =>
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed});
2020-05-12 12:04:54 +00:00
}