mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-28 11:34:52 +01:00
Another beautiful day changes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'package:quiver/core.dart';
|
||||
|
||||
class BitcoinAddressRecord {
|
||||
BitcoinAddressRecord(this.address, {this.index});
|
||||
@@ -10,8 +11,15 @@ class BitcoinAddressRecord {
|
||||
index: decoded['index'] as int);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object o) =>
|
||||
o is BitcoinAddressRecord && address == o.address;
|
||||
|
||||
final String address;
|
||||
int index;
|
||||
|
||||
@override
|
||||
int get hashCode => address.hashCode;
|
||||
|
||||
String toJSON() => json.encode({'address': address, 'index': index});
|
||||
}
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
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 [
|
||||
BalanceDisplayMode.availableBalance,
|
||||
BalanceDisplayMode.fullBalance
|
||||
]);
|
||||
: super(confirmed, unconfirmed);
|
||||
|
||||
factory BitcoinBalance.fromJSON(String jsonSource) {
|
||||
if (jsonSource == null) {
|
||||
@@ -27,31 +23,12 @@ class BitcoinBalance extends Balance {
|
||||
final int confirmed;
|
||||
final int unconfirmed;
|
||||
|
||||
int get total => confirmed + unconfirmed;
|
||||
|
||||
int get availableBalance =>
|
||||
(confirmed ?? 0) + (unconfirmed < 0 ? unconfirmed : 0);
|
||||
|
||||
String get confirmedFormatted => bitcoinAmountToString(amount: confirmed);
|
||||
|
||||
String get unconfirmedFormatted => bitcoinAmountToString(amount: unconfirmed);
|
||||
|
||||
String get totalFormatted => bitcoinAmountToString(amount: total);
|
||||
|
||||
String get availableBalanceFormatted =>
|
||||
bitcoinAmountToString(amount: availableBalance);
|
||||
@override
|
||||
String get formattedAvailableBalance => bitcoinAmountToString(amount: confirmed);
|
||||
|
||||
@override
|
||||
String formattedBalance(BalanceDisplayMode mode) {
|
||||
switch (mode) {
|
||||
case BalanceDisplayMode.fullBalance:
|
||||
return totalFormatted;
|
||||
case BalanceDisplayMode.availableBalance:
|
||||
return availableBalanceFormatted;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
String get formattedAdditionalBalance =>
|
||||
bitcoinAmountToString(amount: unconfirmed);
|
||||
|
||||
String toJSON() =>
|
||||
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed});
|
||||
|
||||
@@ -47,7 +47,7 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
|
||||
network: bitcoin.bitcoin)
|
||||
.derivePath("m/0'/0"),
|
||||
addresses = initialAddresses != null
|
||||
? ObservableList<BitcoinAddressRecord>.of(initialAddresses)
|
||||
? ObservableList<BitcoinAddressRecord>.of(initialAddresses.toSet())
|
||||
: ObservableList<BitcoinAddressRecord>(),
|
||||
syncStatus = NotConnectedSyncStatus(),
|
||||
_password = password,
|
||||
@@ -267,14 +267,14 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
|
||||
final fee = feeAmountForPriority(transactionCredentials.priority);
|
||||
final amount = transactionCredentials.amount != null
|
||||
? stringDoubleToBitcoinAmount(transactionCredentials.amount)
|
||||
: balance.availableBalance - fee;
|
||||
: balance.confirmed - fee;
|
||||
final totalAmount = amount + fee;
|
||||
final txb = bitcoin.TransactionBuilder(network: bitcoin.bitcoin);
|
||||
final changeAddress = address;
|
||||
var leftAmount = totalAmount;
|
||||
var totalInputAmount = 0;
|
||||
|
||||
if (totalAmount > balance.availableBalance) {
|
||||
if (totalAmount > balance.confirmed) {
|
||||
throw BitcoinTransactionWrongBalanceException();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user