tx status and icon fixes

This commit is contained in:
julian 2023-12-29 10:30:37 -06:00
parent f697aeb043
commit 202ca59410
5 changed files with 119 additions and 159 deletions

View file

@ -7,6 +7,8 @@ import 'package:stackwallet/models/isar/models/blockchain_data/v2/input_v2.dart'
import 'package:stackwallet/models/isar/models/blockchain_data/v2/output_v2.dart';
import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/extensions/extensions.dart';
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
part 'transaction_v2.g.dart';
@ -75,7 +77,7 @@ class TransactionV2 {
return Amount(rawValue: inSum - outSum, fractionDigits: coin.decimals);
}
Amount getAmountReceivedThisWallet({required Coin coin}) {
Amount getAmountReceivedInThisWallet({required Coin coin}) {
final outSum = outputs
.where((e) => e.walletOwns)
.fold(BigInt.zero, (p, e) => p + e.value);
@ -83,6 +85,15 @@ class TransactionV2 {
return Amount(rawValue: outSum, fractionDigits: coin.decimals);
}
Amount getAmountSparkSelfMinted({required Coin coin}) {
final outSum = outputs.where((e) {
final op = e.scriptPubKeyHex.substring(0, 2).toUint8ListFromHex.first;
return e.walletOwns && (op == OP_SPARKMINT);
}).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)
@ -92,7 +103,7 @@ class TransactionV2 {
rawValue: inSum,
fractionDigits: coin.decimals,
) -
getAmountReceivedThisWallet(
getAmountReceivedInThisWallet(
coin: coin,
) -
getFee(coin: coin);
@ -112,6 +123,73 @@ class TransactionV2 {
}
}
String statusLabel({
required int currentChainHeight,
required int minConfirms,
}) {
if (subType == TransactionSubType.cashFusion ||
subType == TransactionSubType.mint ||
(subType == TransactionSubType.sparkMint &&
type == TransactionType.sentToSelf)) {
if (isConfirmed(currentChainHeight, minConfirms)) {
return "Anonymized";
} else {
return "Anonymizing";
}
}
// if (coin == Coin.epicCash) {
// if (_transaction.isCancelled) {
// return "Cancelled";
// } else if (type == TransactionType.incoming) {
// if (isConfirmed(height, minConfirms)) {
// return "Received";
// } else {
// if (_transaction.numberOfMessages == 1) {
// return "Receiving (waiting for sender)";
// } else if ((_transaction.numberOfMessages ?? 0) > 1) {
// return "Receiving (waiting for confirmations)"; // TODO test if the sender still has to open again after the receiver has 2 messages present, ie. sender->receiver->sender->node (yes) vs. sender->receiver->node (no)
// } else {
// return "Receiving";
// }
// }
// } else if (type == TransactionType.outgoing) {
// if (isConfirmed(height, minConfirms)) {
// return "Sent (confirmed)";
// } else {
// if (_transaction.numberOfMessages == 1) {
// return "Sending (waiting for receiver)";
// } else if ((_transaction.numberOfMessages ?? 0) > 1) {
// return "Sending (waiting for confirmations)";
// } else {
// return "Sending";
// }
// }
// }
// }
if (type == TransactionType.incoming) {
// if (_transaction.isMinting) {
// return "Minting";
// } else
if (isConfirmed(currentChainHeight, minConfirms)) {
return "Received";
} else {
return "Receiving";
}
} else if (type == TransactionType.outgoing) {
if (isConfirmed(currentChainHeight, minConfirms)) {
return "Sent";
} else {
return "Sending";
}
} else if (type == TransactionType.sentToSelf) {
return "Sent to self";
} else {
return type.name;
}
}
@override
String toString() {
return 'TransactionV2(\n'

View file

@ -40,24 +40,16 @@ class TxIcon extends ConsumerWidget {
bool isReceived,
bool isPending,
TransactionSubType subType,
TransactionType type,
IThemeAssets assets,
) {
if (subType == TransactionSubType.cashFusion) {
return Assets.svg.txCashFusion;
}
if (!isReceived && subType == TransactionSubType.mint) {
if (isCancelled) {
return Assets.svg.anonymizeFailed;
}
if (isPending) {
return Assets.svg.anonymizePending;
}
return Assets.svg.anonymize;
}
if (subType == TransactionSubType.mint ||
subType == TransactionSubType.sparkMint) {
if ((!isReceived && subType == TransactionSubType.mint) ||
(subType == TransactionSubType.sparkMint &&
type == TransactionType.sentToSelf)) {
if (isCancelled) {
return Assets.svg.anonymizeFailed;
}
@ -102,6 +94,7 @@ class TxIcon extends ConsumerWidget {
ref.watch(pWallets).getWallet(tx.walletId).cryptoCurrency.minConfirms,
),
tx.subType,
tx.type,
ref.watch(themeAssetsProvider),
);
} else if (transaction is TransactionV2) {
@ -115,6 +108,7 @@ class TxIcon extends ConsumerWidget {
ref.watch(pWallets).getWallet(tx.walletId).cryptoCurrency.minConfirms,
),
tx.subType,
tx.type,
ref.watch(themeAssetsProvider),
);
} else {

View file

@ -31,7 +31,6 @@ import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/format.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart';
@ -843,34 +842,10 @@ class _DesktopTransactionCardRowState
late final String walletId;
late final int minConfirms;
String whatIsIt(TransactionType type, Coin coin, int height) {
if (_transaction.subType == TransactionSubType.mint ||
_transaction.subType == TransactionSubType.cashFusion) {
if (_transaction.isConfirmed(height, minConfirms)) {
return "Anonymized";
} else {
return "Anonymizing";
}
}
if (type == TransactionType.incoming) {
if (_transaction.isConfirmed(height, minConfirms)) {
return "Received";
} else {
return "Receiving";
}
} else if (type == TransactionType.outgoing) {
if (_transaction.isConfirmed(height, minConfirms)) {
return "Sent";
} else {
return "Sending";
}
} else if (type == TransactionType.sentToSelf) {
return "Sent to self";
} else {
return type.name;
}
}
String whatIsIt(TransactionV2 tx, int height) => tx.statusLabel(
currentChainHeight: height,
minConfirms: minConfirms,
);
@override
void initState() {
@ -917,7 +892,7 @@ class _DesktopTransactionCardRowState
final Amount amount;
if (_transaction.subType == TransactionSubType.cashFusion) {
amount = _transaction.getAmountReceivedThisWallet(coin: coin);
amount = _transaction.getAmountReceivedInThisWallet(coin: coin);
} else {
switch (_transaction.type) {
case TransactionType.outgoing:
@ -926,7 +901,11 @@ class _DesktopTransactionCardRowState
case TransactionType.incoming:
case TransactionType.sentToSelf:
amount = _transaction.getAmountReceivedThisWallet(coin: coin);
if (_transaction.subType == TransactionSubType.sparkMint) {
amount = _transaction.getAmountSparkSelfMinted(coin: coin);
} else {
amount = _transaction.getAmountReceivedInThisWallet(coin: coin);
}
break;
case TransactionType.unknown:
@ -994,8 +973,7 @@ class _DesktopTransactionCardRowState
flex: 3,
child: Text(
whatIsIt(
_transaction.type,
coin,
_transaction,
currentHeight,
),
style:

View file

@ -44,43 +44,12 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
String whatIsIt(
Coin coin,
int currentHeight,
) {
final confirmedStatus = _transaction.isConfirmed(
currentHeight,
ref.read(pWallets).getWallet(walletId).cryptoCurrency.minConfirms,
);
if (_transaction.subType == TransactionSubType.cashFusion ||
_transaction.subType == TransactionSubType.sparkMint ||
_transaction.subType == TransactionSubType.mint) {
if (confirmedStatus) {
return "Anonymized";
} else {
return "Anonymizing";
}
}
if (_transaction.type == TransactionType.incoming) {
// if (_transaction.isMinting) {
// return "Minting";
// } else
if (confirmedStatus) {
return "Received";
} else {
return "Receiving";
}
} else if (_transaction.type == TransactionType.outgoing) {
if (confirmedStatus) {
return "Sent";
} else {
return "Sending";
}
} else if (_transaction.type == TransactionType.sentToSelf) {
return "Sent to self";
} else {
return _transaction.type.name;
}
}
) =>
_transaction.statusLabel(
currentChainHeight: currentHeight,
minConfirms:
ref.read(pWallets).getWallet(walletId).cryptoCurrency.minConfirms,
);
@override
void initState() {
@ -123,7 +92,7 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
final Amount amount;
if (_transaction.subType == TransactionSubType.cashFusion) {
amount = _transaction.getAmountReceivedThisWallet(coin: coin);
amount = _transaction.getAmountReceivedInThisWallet(coin: coin);
} else {
switch (_transaction.type) {
case TransactionType.outgoing:
@ -132,7 +101,11 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
case TransactionType.incoming:
case TransactionType.sentToSelf:
amount = _transaction.getAmountReceivedThisWallet(coin: coin);
if (_transaction.subType == TransactionSubType.sparkMint) {
amount = _transaction.getAmountSparkSelfMinted(coin: coin);
} else {
amount = _transaction.getAmountReceivedInThisWallet(coin: coin);
}
break;
case TransactionType.unknown:

View file

@ -112,7 +112,7 @@ class _TransactionV2DetailsViewState
unit = coin.ticker;
if (_transaction.subType == TransactionSubType.cashFusion) {
amount = _transaction.getAmountReceivedThisWallet(coin: coin);
amount = _transaction.getAmountReceivedInThisWallet(coin: coin);
data = _transaction.outputs
.where((e) => e.walletOwns)
.map((e) => (
@ -136,7 +136,11 @@ class _TransactionV2DetailsViewState
case TransactionType.incoming:
case TransactionType.sentToSelf:
amount = _transaction.getAmountReceivedThisWallet(coin: coin);
if (_transaction.subType == TransactionSubType.sparkMint) {
amount = _transaction.getAmountSparkSelfMinted(coin: coin);
} else {
amount = _transaction.getAmountReceivedInThisWallet(coin: coin);
}
data = _transaction.outputs
.where((e) => e.walletOwns)
.map((e) => (
@ -169,77 +173,10 @@ class _TransactionV2DetailsViewState
super.dispose();
}
String whatIsIt(TransactionV2 tx, int height) {
final type = tx.type;
if (coin == Coin.firo || coin == Coin.firoTestNet) {
if (tx.subType == TransactionSubType.mint) {
if (tx.isConfirmed(height, minConfirms)) {
return "Minted";
} else {
return "Minting";
}
}
}
// if (coin == Coin.epicCash) {
// if (_transaction.isCancelled) {
// return "Cancelled";
// } else if (type == TransactionType.incoming) {
// if (tx.isConfirmed(height, minConfirms)) {
// return "Received";
// } else {
// if (_transaction.numberOfMessages == 1) {
// return "Receiving (waiting for sender)";
// } else if ((_transaction.numberOfMessages ?? 0) > 1) {
// return "Receiving (waiting for confirmations)"; // TODO test if the sender still has to open again after the receiver has 2 messages present, ie. sender->receiver->sender->node (yes) vs. sender->receiver->node (no)
// } else {
// return "Receiving";
// }
// }
// } else if (type == TransactionType.outgoing) {
// if (tx.isConfirmed(height, minConfirms)) {
// return "Sent (confirmed)";
// } else {
// if (_transaction.numberOfMessages == 1) {
// return "Sending (waiting for receiver)";
// } else if ((_transaction.numberOfMessages ?? 0) > 1) {
// return "Sending (waiting for confirmations)";
// } else {
// return "Sending";
// }
// }
// }
// }
if (tx.subType == TransactionSubType.cashFusion) {
if (tx.isConfirmed(height, minConfirms)) {
return "Anonymized";
} else {
return "Anonymizing";
}
}
if (type == TransactionType.incoming) {
// if (_transaction.isMinting) {
// return "Minting";
// } else
if (tx.isConfirmed(height, minConfirms)) {
return "Received";
} else {
return "Receiving";
}
} else if (type == TransactionType.outgoing) {
if (tx.isConfirmed(height, minConfirms)) {
return "Sent";
} else {
return "Sending";
}
} else if (type == TransactionType.sentToSelf) {
return "Sent to self";
} else {
return type.name;
}
}
String whatIsIt(TransactionV2 tx, int height) => tx.statusLabel(
currentChainHeight: height,
minConfirms: minConfirms,
);
Future<String> fetchContactNameFor(String address) async {
if (address.isEmpty) {