mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 01:37:40 +00:00
35 lines
1,006 B
Dart
35 lines
1,006 B
Dart
import 'dart:convert';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
|
|
import 'package:cake_wallet/entities/balance.dart';
|
|
|
|
class ElectrumBalance extends Balance {
|
|
const ElectrumBalance({@required this.confirmed, @required this.unconfirmed})
|
|
: super(confirmed, unconfirmed);
|
|
|
|
factory 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);
|
|
}
|
|
|
|
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});
|
|
}
|