mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-10-30 00:47:48 +00:00
2a1bdf69ef
* Update inapp webview and update it's deprecated code * Add Turkish Lira Fix android in-app webview * Change FAQ url [skip ci] * Fix available balance display issue
40 lines
1.2 KiB
Dart
40 lines
1.2 KiB
Dart
import 'dart:convert';
|
|
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
|
|
import 'package:cw_core/balance.dart';
|
|
|
|
class ElectrumBalance extends Balance {
|
|
const ElectrumBalance({required this.confirmed, required this.unconfirmed, required this.frozen})
|
|
: super(confirmed, unconfirmed);
|
|
|
|
static ElectrumBalance? fromJSON(String? jsonSource) {
|
|
if (jsonSource == null) {
|
|
return null;
|
|
}
|
|
|
|
final decoded = json.decode(jsonSource) as Map;
|
|
|
|
return ElectrumBalance(
|
|
confirmed: decoded['confirmed'] as int? ?? 0,
|
|
unconfirmed: decoded['unconfirmed'] as int? ?? 0,
|
|
frozen: decoded['frozen'] as int? ?? 0);
|
|
}
|
|
|
|
final int confirmed;
|
|
final int unconfirmed;
|
|
final int frozen;
|
|
|
|
@override
|
|
String get formattedAvailableBalance => bitcoinAmountToString(amount: confirmed - frozen);
|
|
|
|
@override
|
|
String get formattedAdditionalBalance => bitcoinAmountToString(amount: unconfirmed);
|
|
|
|
@override
|
|
String get formattedUnAvailableBalance {
|
|
final frozenFormatted = bitcoinAmountToString(amount: frozen);
|
|
return frozenFormatted == '0.0' ? '' : frozenFormatted;
|
|
}
|
|
|
|
String toJSON() =>
|
|
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed, 'frozen': frozen});
|
|
}
|