mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-02-02 19:26:37 +00:00
spark transaction sent to self fixes
This commit is contained in:
parent
7bbc235b92
commit
48ad3db84c
4 changed files with 45 additions and 9 deletions
|
@ -68,6 +68,12 @@ class TransactionV2 {
|
|||
}
|
||||
|
||||
Amount getFee({required Coin coin}) {
|
||||
// try anon fee first
|
||||
final fee = _getAnonFee();
|
||||
if (fee != null) {
|
||||
return fee;
|
||||
}
|
||||
|
||||
final inSum =
|
||||
inputs.map((e) => e.value).reduce((value, element) => value += element);
|
||||
final outSum = outputs
|
||||
|
@ -99,7 +105,7 @@ class TransactionV2 {
|
|||
.where((e) => e.walletOwns)
|
||||
.fold(BigInt.zero, (p, e) => p + e.value);
|
||||
|
||||
return Amount(
|
||||
final amount = Amount(
|
||||
rawValue: inSum,
|
||||
fractionDigits: coin.decimals,
|
||||
) -
|
||||
|
@ -107,6 +113,8 @@ class TransactionV2 {
|
|||
coin: coin,
|
||||
) -
|
||||
getFee(coin: coin);
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
Set<String> associatedAddresses() => {
|
||||
|
@ -114,7 +122,7 @@ class TransactionV2 {
|
|||
...outputs.map((e) => e.addresses).expand((e) => e),
|
||||
};
|
||||
|
||||
Amount? getAnonFee() {
|
||||
Amount? _getAnonFee() {
|
||||
try {
|
||||
final map = jsonDecode(otherData!) as Map;
|
||||
return Amount.fromSerializedJsonString(map["anonFees"] as String);
|
||||
|
|
|
@ -96,12 +96,7 @@ class _TransactionV2DetailsViewState
|
|||
minConfirms =
|
||||
ref.read(pWallets).getWallet(walletId).cryptoCurrency.minConfirms;
|
||||
|
||||
if (_transaction.subType == TransactionSubType.join ||
|
||||
_transaction.subType == TransactionSubType.sparkSpend) {
|
||||
fee = _transaction.getAnonFee()!;
|
||||
} else {
|
||||
fee = _transaction.getFee(coin: coin);
|
||||
}
|
||||
fee = _transaction.getFee(coin: coin);
|
||||
|
||||
if (_transaction.subType == TransactionSubType.cashFusion ||
|
||||
_transaction.type == TransactionType.sentToSelf) {
|
||||
|
|
|
@ -139,6 +139,14 @@ class _SparkCoinsViewState extends ConsumerState<SparkCoinsView> {
|
|||
textAlign: TextAlign.left,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 9,
|
||||
child: Text(
|
||||
"Address",
|
||||
style: STextStyles.itemSubtitle(context),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Text(
|
||||
|
@ -213,6 +221,13 @@ class _SparkCoinsViewState extends ConsumerState<SparkCoinsView> {
|
|||
style: STextStyles.itemSubtitle12(context),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 9,
|
||||
child: SelectableText(
|
||||
_coins[index].address,
|
||||
style: STextStyles.itemSubtitle12(context),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: SelectableText(
|
||||
|
|
|
@ -435,6 +435,16 @@ class FiroWallet extends Bip39HDWallet
|
|||
inputs.add(input);
|
||||
}
|
||||
|
||||
final totalSpentFromWallet = inputs
|
||||
.where((e) => e.walletOwns)
|
||||
.map((e) => e.value)
|
||||
.fold(BigInt.zero, (value, element) => value + element);
|
||||
|
||||
final totalReceivedInWallet = outputs
|
||||
.where((e) => e.walletOwns)
|
||||
.map((e) => e.value)
|
||||
.fold(BigInt.zero, (value, element) => value + element);
|
||||
|
||||
final totalOut = outputs
|
||||
.map((e) => e.value)
|
||||
.fold(BigInt.zero, (value, element) => value + element);
|
||||
|
@ -458,7 +468,15 @@ class FiroWallet extends Bip39HDWallet
|
|||
type = TransactionType.outgoing;
|
||||
|
||||
if (wasReceivedInThisWallet) {
|
||||
if (changeAmountReceivedInThisWallet + amountReceivedInThisWallet ==
|
||||
if (isSparkSpend) {
|
||||
if (totalSpentFromWallet -
|
||||
(totalReceivedInWallet + anonFees!.raw) ==
|
||||
BigInt.zero) {
|
||||
// definitely sent all to self
|
||||
type = TransactionType.sentToSelf;
|
||||
}
|
||||
} else if (changeAmountReceivedInThisWallet +
|
||||
amountReceivedInThisWallet ==
|
||||
totalOut) {
|
||||
// definitely sent all to self
|
||||
type = TransactionType.sentToSelf;
|
||||
|
|
Loading…
Reference in a new issue