mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-31 15:06:04 +00:00
fix sending with mweb amounts
This commit is contained in:
parent
245f4d665d
commit
3a969acc6d
8 changed files with 38 additions and 20 deletions
|
@ -7,8 +7,8 @@ class ElectrumBalance extends Balance {
|
||||||
required this.confirmed,
|
required this.confirmed,
|
||||||
required this.unconfirmed,
|
required this.unconfirmed,
|
||||||
required this.frozen,
|
required this.frozen,
|
||||||
this.secondConfirmed,
|
this.secondConfirmed = 0,
|
||||||
this.secondUnconfirmed,
|
this.secondUnconfirmed = 0,
|
||||||
}) : super(
|
}) : super(
|
||||||
confirmed,
|
confirmed,
|
||||||
unconfirmed,
|
unconfirmed,
|
||||||
|
@ -32,8 +32,8 @@ class ElectrumBalance extends Balance {
|
||||||
int confirmed;
|
int confirmed;
|
||||||
int unconfirmed;
|
int unconfirmed;
|
||||||
final int frozen;
|
final int frozen;
|
||||||
int? secondConfirmed;
|
int secondConfirmed = 0;
|
||||||
int? secondUnconfirmed;
|
int secondUnconfirmed = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get formattedAvailableBalance => bitcoinAmountToString(amount: confirmed - frozen);
|
String get formattedAvailableBalance => bitcoinAmountToString(amount: confirmed - frozen);
|
||||||
|
@ -51,7 +51,12 @@ class ElectrumBalance extends Balance {
|
||||||
String get formattedSecondAvailableBalance => bitcoinAmountToString(amount: secondConfirmed ?? 0);
|
String get formattedSecondAvailableBalance => bitcoinAmountToString(amount: secondConfirmed ?? 0);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get formattedSecondAdditionalBalance => bitcoinAmountToString(amount: secondUnconfirmed ?? 0);
|
String get formattedSecondAdditionalBalance =>
|
||||||
|
bitcoinAmountToString(amount: secondUnconfirmed ?? 0);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get formattedFullAvailableBalance =>
|
||||||
|
bitcoinAmountToString(amount: confirmed + (secondConfirmed ?? 0) - frozen);
|
||||||
|
|
||||||
String toJSON() => json.encode({
|
String toJSON() => json.encode({
|
||||||
'confirmed': confirmed,
|
'confirmed': confirmed,
|
||||||
|
|
|
@ -869,7 +869,7 @@ abstract class ElectrumWalletBase
|
||||||
|
|
||||||
final totalAmount = amount + fee;
|
final totalAmount = amount + fee;
|
||||||
|
|
||||||
if (totalAmount > balance[currency]!.confirmed) {
|
if (totalAmount > (balance[currency]!.confirmed + balance[currency]!.secondConfirmed)) {
|
||||||
throw BitcoinTransactionWrongBalanceException();
|
throw BitcoinTransactionWrongBalanceException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -676,8 +676,10 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
try {
|
try {
|
||||||
mwebUtxosBox.values.forEach((utxo) {
|
mwebUtxosBox.values.forEach((utxo) {
|
||||||
if (utxo.height > 0) {
|
if (utxo.height > 0) {
|
||||||
|
// confirmed += utxo.value.toInt();
|
||||||
confirmedMweb += utxo.value.toInt();
|
confirmedMweb += utxo.value.toInt();
|
||||||
} else {
|
} else {
|
||||||
|
// unconfirmed += utxo.value.toInt();
|
||||||
unconfirmedMweb += utxo.value.toInt();
|
unconfirmedMweb += utxo.value.toInt();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -122,6 +122,10 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
||||||
Future<String> getChangeAddress({List<BitcoinOutput>? outputs, UtxoDetails? utxoDetails}) async {
|
Future<String> getChangeAddress({List<BitcoinOutput>? outputs, UtxoDetails? utxoDetails}) async {
|
||||||
// use regular change address on peg in, otherwise use mweb for change address:
|
// use regular change address on peg in, otherwise use mweb for change address:
|
||||||
|
|
||||||
|
if (!mwebEnabled) {
|
||||||
|
return super.getChangeAddress();
|
||||||
|
}
|
||||||
|
|
||||||
if (outputs != null && utxoDetails != null) {
|
if (outputs != null && utxoDetails != null) {
|
||||||
// check if this is a PEGIN:
|
// check if this is a PEGIN:
|
||||||
bool outputsToMweb = false;
|
bool outputsToMweb = false;
|
||||||
|
@ -134,6 +138,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
||||||
outputsToMweb = true;
|
outputsToMweb = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: this doesn't respect coin control because it doesn't know which available inputs are selected
|
||||||
utxoDetails.availableInputs.forEach((element) {
|
utxoDetails.availableInputs.forEach((element) {
|
||||||
if (element.address.contains("mweb")) {
|
if (element.address.contains("mweb")) {
|
||||||
comesFromMweb = true;
|
comesFromMweb = true;
|
||||||
|
@ -144,6 +149,11 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
||||||
if (isPegIn && mwebEnabled) {
|
if (isPegIn && mwebEnabled) {
|
||||||
return super.getChangeAddress();
|
return super.getChangeAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use regular change address if it's not an mweb tx:
|
||||||
|
if (!comesFromMweb && !outputsToMweb) {
|
||||||
|
return super.getChangeAddress();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mwebEnabled) {
|
if (mwebEnabled) {
|
||||||
|
|
|
@ -13,4 +13,6 @@ abstract class Balance {
|
||||||
String get formattedUnAvailableBalance => '';
|
String get formattedUnAvailableBalance => '';
|
||||||
String get formattedSecondAvailableBalance => '';
|
String get formattedSecondAvailableBalance => '';
|
||||||
String get formattedSecondAdditionalBalance => '';
|
String get formattedSecondAdditionalBalance => '';
|
||||||
|
String get formattedFullAvailableBalance => '';
|
||||||
|
String get formattedFullUnAvailableBalance => '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:cake_wallet/di.dart';
|
import 'package:cake_wallet/di.dart';
|
||||||
import 'package:cake_wallet/generated/i18n.dart';
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:cake_wallet/routes.dart';
|
import 'package:cake_wallet/routes.dart';
|
||||||
|
@ -35,7 +38,7 @@ class AddressList extends StatelessWidget {
|
||||||
separatorBuilder: (context, _) => const HorizontalSectionDivider(),
|
separatorBuilder: (context, _) => const HorizontalSectionDivider(),
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: NeverScrollableScrollPhysics(),
|
physics: NeverScrollableScrollPhysics(),
|
||||||
itemCount: addressListViewModel.items.length,
|
itemCount: min(addressListViewModel.items.length, 100),// TODO: don't show all 1000 mweb addresses
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final item = addressListViewModel.items[index];
|
final item = addressListViewModel.items[index];
|
||||||
Widget cell = Container();
|
Widget cell = Container();
|
||||||
|
|
|
@ -369,21 +369,17 @@ abstract class BalanceViewModelBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _hasSecondAdditionalBalanceForWalletType(WalletType type) {
|
bool _hasSecondAdditionalBalanceForWalletType(WalletType type) {
|
||||||
// return _walletBalance.secondAdditional != null && _walletBalance.secondAdditional! != 0;
|
if (wallet.type == WalletType.litecoin /*&& settingsStore.mwebEnabled*/) {
|
||||||
// if (wallet.type == WalletType.litecoin && settingsStore.mwebEnabled) {
|
return true;
|
||||||
// return true;
|
}
|
||||||
// }
|
return false;
|
||||||
// return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _hasSecondAvailableBalanceForWalletType(WalletType type) {
|
bool _hasSecondAvailableBalanceForWalletType(WalletType type) {
|
||||||
// return _walletBalance.secondAdditional != null && _walletBalance.secondAdditional! != 0;
|
if (wallet.type == WalletType.litecoin /*&& settingsStore.mwebEnabled*/) {
|
||||||
// if (wallet.type == WalletType.litecoin && settingsStore.mwebEnabled) {
|
return true;
|
||||||
// return true;
|
}
|
||||||
// }
|
return false;
|
||||||
// return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
|
|
|
@ -217,7 +217,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
||||||
PendingTransaction? pendingTransaction;
|
PendingTransaction? pendingTransaction;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
String get balance => wallet.balance[selectedCryptoCurrency]!.formattedAvailableBalance;
|
String get balance => wallet.balance[selectedCryptoCurrency]!.formattedFullAvailableBalance;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
bool get isFiatDisabled => balanceViewModel.isFiatDisabled;
|
bool get isFiatDisabled => balanceViewModel.isFiatDisabled;
|
||||||
|
|
Loading…
Reference in a new issue