fix tx amounts shown

This commit is contained in:
julian 2023-10-20 12:20:09 -06:00
parent 8cd7f3fa7f
commit 6e258db344
3 changed files with 40 additions and 12 deletions

View file

@ -71,14 +71,22 @@ class TransactionV2 {
return Amount(rawValue: inSum - outSum, fractionDigits: coin.decimals);
}
Amount getAmount({required Coin coin}) {
Amount getAmountReceivedThisWallet({required Coin coin}) {
final outSum = outputs
.map((e) => e.value)
.reduce((value, element) => value += element);
.where((e) => e.walletOwns)
.fold(BigInt.zero, (p, e) => p + e.value);
return Amount(rawValue: outSum, fractionDigits: coin.decimals);
}
Amount getAmountSentFromThisWallet({required Coin coin}) {
final inSum = inputs
.where((e) => e.walletOwns)
.fold(BigInt.zero, (p, e) => p + e.value);
return Amount(rawValue: inSum, fractionDigits: coin.decimals);
}
@override
String toString() {
return 'TransactionV2(\n'

View file

@ -411,7 +411,8 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
walletId = _transaction.walletId;
if (Util.isDesktop) {
if (_transaction.type == TransactionType.outgoing) {
if (_transaction.type == TransactionType.outgoing &&
_transaction.subType != TransactionSubType.cashFusion) {
prefix = "-";
} else if (_transaction.type == TransactionType.incoming) {
prefix = "+";
@ -443,7 +444,26 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
final currentHeight = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(walletId).currentHeight));
final amount = _transaction.getAmount(coin: coin);
final Amount amount;
if (_transaction.subType == TransactionSubType.cashFusion) {
amount = _transaction.getAmountReceivedThisWallet(coin: coin);
} else {
switch (_transaction.type) {
case TransactionType.outgoing:
amount = _transaction.getAmountSentFromThisWallet(coin: coin);
break;
case TransactionType.incoming:
case TransactionType.sentToSelf:
amount = _transaction.getAmountReceivedThisWallet(coin: coin);
break;
case TransactionType.unknown:
amount = _transaction.getAmountSentFromThisWallet(coin: coin);
break;
}
}
return Material(
color: Theme.of(context).extension<StackColors>()!.popupBG,

View file

@ -2110,7 +2110,7 @@ class BitcoinCashWallet extends CoinServiceAPI
addresses.addAll(prevOut.addresses);
}
final input = InputV2.isarCantDoRequiredInDefaultConstructor(
InputV2 input = InputV2.isarCantDoRequiredInDefaultConstructor(
scriptSigHex: map["scriptSig"]?["hex"] as String?,
sequence: map["sequence"] as int?,
outpoint: outpoint,
@ -2126,16 +2126,16 @@ class BitcoinCashWallet extends CoinServiceAPI
if (allAddressesSet.intersection(input.addresses.toSet()).isNotEmpty) {
wasSentFromThisWallet = true;
amountSentFromThisWallet += input.value;
input = input.copyWith(walletOwns: true);
}
inputs.add(
wasSentFromThisWallet ? input.copyWith(walletOwns: true) : input);
inputs.add(input);
}
// parse outputs
final List<OutputV2> outputs = [];
for (final outputJson in txData["vout"] as List) {
final output = OutputV2.fromElectrumXJson(
OutputV2 output = OutputV2.fromElectrumXJson(
Map<String, dynamic>.from(outputJson as Map),
decimalPlaces: coin.decimals,
// don't know yet if wallet owns. Need addresses first
@ -2148,16 +2148,16 @@ class BitcoinCashWallet extends CoinServiceAPI
.isNotEmpty) {
wasReceivedInThisWallet = true;
amountReceivedInThisWallet += output.value;
output = output.copyWith(walletOwns: true);
} else if (changeAddresses
.intersection(output.addresses.toSet())
.isNotEmpty) {
wasReceivedInThisWallet = true;
changeAmountReceivedInThisWallet += output.value;
output = output.copyWith(walletOwns: true);
}
outputs.add(wasReceivedInThisWallet
? output.copyWith(walletOwns: true)
: output);
outputs.add(output);
}
final totalIn = inputs