mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
fix tx amounts shown
This commit is contained in:
parent
8cd7f3fa7f
commit
6e258db344
3 changed files with 40 additions and 12 deletions
|
@ -71,14 +71,22 @@ class TransactionV2 {
|
||||||
return Amount(rawValue: inSum - outSum, fractionDigits: coin.decimals);
|
return Amount(rawValue: inSum - outSum, fractionDigits: coin.decimals);
|
||||||
}
|
}
|
||||||
|
|
||||||
Amount getAmount({required Coin coin}) {
|
Amount getAmountReceivedThisWallet({required Coin coin}) {
|
||||||
final outSum = outputs
|
final outSum = outputs
|
||||||
.map((e) => e.value)
|
.where((e) => e.walletOwns)
|
||||||
.reduce((value, element) => value += element);
|
.fold(BigInt.zero, (p, e) => p + e.value);
|
||||||
|
|
||||||
return Amount(rawValue: outSum, fractionDigits: coin.decimals);
|
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
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'TransactionV2(\n'
|
return 'TransactionV2(\n'
|
||||||
|
|
|
@ -411,7 +411,8 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
|
||||||
walletId = _transaction.walletId;
|
walletId = _transaction.walletId;
|
||||||
|
|
||||||
if (Util.isDesktop) {
|
if (Util.isDesktop) {
|
||||||
if (_transaction.type == TransactionType.outgoing) {
|
if (_transaction.type == TransactionType.outgoing &&
|
||||||
|
_transaction.subType != TransactionSubType.cashFusion) {
|
||||||
prefix = "-";
|
prefix = "-";
|
||||||
} else if (_transaction.type == TransactionType.incoming) {
|
} else if (_transaction.type == TransactionType.incoming) {
|
||||||
prefix = "+";
|
prefix = "+";
|
||||||
|
@ -443,7 +444,26 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
|
||||||
final currentHeight = ref.watch(walletsChangeNotifierProvider
|
final currentHeight = ref.watch(walletsChangeNotifierProvider
|
||||||
.select((value) => value.getManager(walletId).currentHeight));
|
.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(
|
return Material(
|
||||||
color: Theme.of(context).extension<StackColors>()!.popupBG,
|
color: Theme.of(context).extension<StackColors>()!.popupBG,
|
||||||
|
|
|
@ -2110,7 +2110,7 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
addresses.addAll(prevOut.addresses);
|
addresses.addAll(prevOut.addresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
final input = InputV2.isarCantDoRequiredInDefaultConstructor(
|
InputV2 input = InputV2.isarCantDoRequiredInDefaultConstructor(
|
||||||
scriptSigHex: map["scriptSig"]?["hex"] as String?,
|
scriptSigHex: map["scriptSig"]?["hex"] as String?,
|
||||||
sequence: map["sequence"] as int?,
|
sequence: map["sequence"] as int?,
|
||||||
outpoint: outpoint,
|
outpoint: outpoint,
|
||||||
|
@ -2126,16 +2126,16 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
if (allAddressesSet.intersection(input.addresses.toSet()).isNotEmpty) {
|
if (allAddressesSet.intersection(input.addresses.toSet()).isNotEmpty) {
|
||||||
wasSentFromThisWallet = true;
|
wasSentFromThisWallet = true;
|
||||||
amountSentFromThisWallet += input.value;
|
amountSentFromThisWallet += input.value;
|
||||||
|
input = input.copyWith(walletOwns: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
inputs.add(
|
inputs.add(input);
|
||||||
wasSentFromThisWallet ? input.copyWith(walletOwns: true) : input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse outputs
|
// parse outputs
|
||||||
final List<OutputV2> outputs = [];
|
final List<OutputV2> outputs = [];
|
||||||
for (final outputJson in txData["vout"] as List) {
|
for (final outputJson in txData["vout"] as List) {
|
||||||
final output = OutputV2.fromElectrumXJson(
|
OutputV2 output = OutputV2.fromElectrumXJson(
|
||||||
Map<String, dynamic>.from(outputJson as Map),
|
Map<String, dynamic>.from(outputJson as Map),
|
||||||
decimalPlaces: coin.decimals,
|
decimalPlaces: coin.decimals,
|
||||||
// don't know yet if wallet owns. Need addresses first
|
// don't know yet if wallet owns. Need addresses first
|
||||||
|
@ -2148,16 +2148,16 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
.isNotEmpty) {
|
.isNotEmpty) {
|
||||||
wasReceivedInThisWallet = true;
|
wasReceivedInThisWallet = true;
|
||||||
amountReceivedInThisWallet += output.value;
|
amountReceivedInThisWallet += output.value;
|
||||||
|
output = output.copyWith(walletOwns: true);
|
||||||
} else if (changeAddresses
|
} else if (changeAddresses
|
||||||
.intersection(output.addresses.toSet())
|
.intersection(output.addresses.toSet())
|
||||||
.isNotEmpty) {
|
.isNotEmpty) {
|
||||||
wasReceivedInThisWallet = true;
|
wasReceivedInThisWallet = true;
|
||||||
changeAmountReceivedInThisWallet += output.value;
|
changeAmountReceivedInThisWallet += output.value;
|
||||||
|
output = output.copyWith(walletOwns: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
outputs.add(wasReceivedInThisWallet
|
outputs.add(output);
|
||||||
? output.copyWith(walletOwns: true)
|
|
||||||
: output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final totalIn = inputs
|
final totalIn = inputs
|
||||||
|
|
Loading…
Reference in a new issue