mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
Fixes for update fiat rate after change of current wallet type. Fixes for change amount for btc transactions. Changed displaying of balance for btc wallet. General fixes.
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
|
||||
import 'package:cake_wallet/entities/balance.dart';
|
||||
|
||||
class BitcoinBalance extends Balance {
|
||||
const BitcoinBalance({@required this.confirmed, @required this.unconfirmed}) : super();
|
||||
const BitcoinBalance({@required this.confirmed, @required this.unconfirmed})
|
||||
: super(const [BalanceDisplayMode.availableBalance]);
|
||||
|
||||
factory BitcoinBalance.fromJSON(String jsonSource) {
|
||||
if (jsonSource == null) {
|
||||
@@ -30,6 +32,18 @@ class BitcoinBalance extends Balance {
|
||||
|
||||
String get totalFormatted => bitcoinAmountToString(amount: total);
|
||||
|
||||
@override
|
||||
String formattedBalance(BalanceDisplayMode mode) {
|
||||
switch (mode) {
|
||||
case BalanceDisplayMode.fullBalance:
|
||||
return totalFormatted;
|
||||
case BalanceDisplayMode.availableBalance:
|
||||
return totalFormatted;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String toJSON() =>
|
||||
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed});
|
||||
}
|
||||
|
||||
@@ -262,9 +262,8 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
|
||||
final utxs = await unptsFutures;
|
||||
|
||||
for (final utx in utxs) {
|
||||
final inAmount = utx.value > totalAmount ? totalAmount : utx.value;
|
||||
leftAmount = leftAmount - inAmount;
|
||||
totalInputAmount += inAmount;
|
||||
leftAmount = leftAmount - utx.value;
|
||||
totalInputAmount += utx.value;
|
||||
inputs.add(utx);
|
||||
|
||||
if (leftAmount <= 0) {
|
||||
@@ -348,6 +347,11 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
|
||||
// FIXME: Unimplemented
|
||||
}
|
||||
|
||||
@override
|
||||
void close() {
|
||||
|
||||
}
|
||||
|
||||
void _subscribeForUpdates() {
|
||||
scriptHashes.forEach((sh) async {
|
||||
await _scripthashesUpdateSubject[sh]?.close();
|
||||
|
||||
@@ -75,7 +75,7 @@ class ElectrumClient {
|
||||
try {
|
||||
final jsoned =
|
||||
json.decode(utf8.decode(event.toList())) as Map<String, Object>;
|
||||
print(jsoned);
|
||||
// print(jsoned);
|
||||
final method = jsoned['method'];
|
||||
final id = jsoned['id'] as String;
|
||||
final result = jsoned['result'];
|
||||
@@ -92,7 +92,9 @@ class ElectrumClient {
|
||||
}, onError: (Object error) {
|
||||
print(error.toString());
|
||||
_setIsConnected(false);
|
||||
}, onDone: () => _setIsConnected(false));
|
||||
}, onDone: () {
|
||||
_setIsConnected(false);
|
||||
});
|
||||
keepAlive();
|
||||
}
|
||||
|
||||
@@ -103,7 +105,7 @@ class ElectrumClient {
|
||||
|
||||
Future<void> ping() async {
|
||||
try {
|
||||
// await callWithTimeout(method: 'server.ping');
|
||||
await callWithTimeout(method: 'server.ping');
|
||||
_setIsConnected(true);
|
||||
} on RequestFailedTimeoutException catch (_) {
|
||||
_setIsConnected(false);
|
||||
|
||||
Reference in New Issue
Block a user