cake_wallet/cw_bitcoin/lib/electrum_balance.dart
Serhii faf151a4dc
CW-531-Bitcoin-Fees-issue (#1218)
* SegWit transaction size

* [skip ci] fix electrum balances layout

* fix tapping area
2023-12-13 16:43:26 +02:00

46 lines
1.3 KiB
Dart

import 'dart:convert';
import 'package:flutter/foundation.dart';
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 - unconfirmed.abs() - 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});
}