don't show change in amount total

This commit is contained in:
julian 2024-01-05 13:45:42 -06:00
parent 8ff9227e48
commit 7bbc235b92
17 changed files with 192 additions and 61 deletions

View file

@ -421,7 +421,7 @@ class _ConfirmChangeNowSendViewState
builder: (context) {
final coin = ref.read(pWalletCoin(walletId));
final fee = widget.txData.fee!;
final amount = widget.txData.amount!;
final amount = widget.txData.amountWithoutChange!;
final total = amount + fee;
return Text(
@ -580,9 +580,11 @@ class _ConfirmChangeNowSendViewState
final price = ref.watch(
priceAnd24hChangeNotifierProvider
.select((value) => value.getPrice(coin)));
final amount = widget.txData.amount!;
final value = (price.item1 * amount.decimal)
.toAmount(fractionDigits: 2);
final amountWithoutChange =
widget.txData.amountWithoutChange!;
final value =
(price.item1 * amountWithoutChange.decimal)
.toAmount(fractionDigits: 2);
final currency = ref.watch(prefsChangeNotifierProvider
.select((value) => value.currency));
final locale = ref.watch(
@ -608,7 +610,7 @@ class _ConfirmChangeNowSendViewState
ref
.watch(pAmountFormatter(
ref.watch(pWalletCoin(walletId))))
.format((widget.txData.amount!)),
.format((widget.txData.amountWithoutChange!)),
style: STextStyles.itemSubtitle12(context),
textAlign: TextAlign.right,
),
@ -722,7 +724,7 @@ class _ConfirmChangeNowSendViewState
builder: (context) {
final coin = ref.watch(pWalletCoin(walletId));
final fee = widget.txData.fee!;
final amount = widget.txData.amount!;
final amount = widget.txData.amountWithoutChange!;
final total = amount + fee;
return Text(

View file

@ -241,10 +241,18 @@ class _Step4ViewState extends ConsumerState<Step4View> {
Future<TxData> txDataFuture;
// TODO: [prio=high] Firo spark
if (wallet is FiroWallet && !firoPublicSend) {
txDataFuture = wallet.prepareSendLelantus(
txData: TxData(
recipients: [(address: address, amount: amount)],
recipients: [
(
address: address,
amount: amount,
isChange: false,
)
],
note: "${model.trade!.payInCurrency.toUpperCase()}/"
"${model.trade!.payOutCurrency.toUpperCase()} exchange",
),
@ -259,7 +267,11 @@ class _Step4ViewState extends ConsumerState<Step4View> {
txDataFuture = wallet.prepareSend(
txData: TxData(
recipients: [
(address: address, amount: amount),
(
address: address,
amount: amount,
isChange: false,
),
],
memo: memo,
feeRateType: FeeRateType.average,

View file

@ -287,7 +287,7 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
recipients: [
(
address: address,
amount: amount,
amount: amount, isChange: false,
),
],
memo: memo,
@ -303,7 +303,7 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
recipients: [
(
address: address,
amount: amount,
amount: amount, isChange: false,
),
],
feeRateType: FeeRateType.average,
@ -315,7 +315,7 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
recipients: [
(
address: address,
amount: amount,
amount: amount, isChange: false,
),
],
// feeRateType: FeeRateType.average,

View file

@ -351,7 +351,7 @@ class _ConfirmTransactionViewState
}
final Amount? fee;
final Amount amount;
final Amount amountWithoutChange;
final wallet = ref.watch(pWallets).getWallet(walletId);
@ -362,33 +362,33 @@ class _ConfirmTransactionViewState
fee = widget.txData.sparkMints!
.map((e) => e.fee!)
.reduce((value, element) => value += element);
amount = widget.txData.sparkMints!
amountWithoutChange = widget.txData.sparkMints!
.map((e) => e.amountSpark!)
.reduce((value, element) => value += element);
} else {
fee = widget.txData.fee;
amount = widget.txData.amount!;
amountWithoutChange = widget.txData.amountWithoutChange!;
}
break;
case FiroType.lelantus:
fee = widget.txData.fee;
amount = widget.txData.amount!;
amountWithoutChange = widget.txData.amountWithoutChange!;
break;
case FiroType.spark:
fee = widget.txData.fee;
amount = (widget.txData.amount ??
amountWithoutChange = (widget.txData.amountWithoutChange ??
Amount.zeroWith(
fractionDigits: wallet.cryptoCurrency.fractionDigits)) +
(widget.txData.amountSpark ??
(widget.txData.amountSparkWithoutChange ??
Amount.zeroWith(
fractionDigits: wallet.cryptoCurrency.fractionDigits));
break;
}
} else {
fee = widget.txData.fee;
amount = widget.txData.amount!;
amountWithoutChange = widget.txData.amountWithoutChange!;
}
return ConditionalParent(
@ -516,7 +516,7 @@ class _ConfirmTransactionViewState
),
SelectableText(
ref.watch(pAmountFormatter(coin)).format(
amount,
amountWithoutChange,
ethContract: ref
.watch(tokenServiceProvider)
?.tokenContract,
@ -719,14 +719,15 @@ class _ConfirmTransactionViewState
.getPrice(coin)
.item1;
if (price > Decimal.zero) {
fiatAmount = (amount.decimal * price)
.toAmount(fractionDigits: 2)
.fiatString(
locale: ref
.read(
localeServiceChangeNotifierProvider)
.locale,
);
fiatAmount =
(amountWithoutChange.decimal * price)
.toAmount(fractionDigits: 2)
.fiatString(
locale: ref
.read(
localeServiceChangeNotifierProvider)
.locale,
);
}
}
@ -734,7 +735,7 @@ class _ConfirmTransactionViewState
children: [
SelectableText(
ref.watch(pAmountFormatter(coin)).format(
amount,
amountWithoutChange,
ethContract: ref
.read(tokenServiceProvider)
?.tokenContract),
@ -1128,7 +1129,9 @@ class _ConfirmTransactionViewState
),
),
SelectableText(
ref.watch(pAmountFormatter(coin)).format(amount + fee!),
ref
.watch(pAmountFormatter(coin))
.format(amountWithoutChange + fee!),
style: isDesktop
? STextStyles.desktopTextExtraExtraSmall(context)
.copyWith(

View file

@ -644,6 +644,7 @@ class _SendViewState extends ConsumerState<SendView> {
(
address: widget.accountLite!.code,
amount: amount,
isChange: false,
)
],
satsPerVByte: isCustomFee ? customFeeRate : null,
@ -666,6 +667,7 @@ class _SendViewState extends ConsumerState<SendView> {
address: _address!,
amount: amount,
memo: memoController.text,
isChange: false,
)
],
feeRateType: ref.read(feeRateTypeStateProvider),
@ -680,7 +682,13 @@ class _SendViewState extends ConsumerState<SendView> {
} else {
txDataFuture = wallet.prepareSend(
txData: TxData(
recipients: [(address: _address!, amount: amount)],
recipients: [
(
address: _address!,
amount: amount,
isChange: false,
)
],
feeRateType: ref.read(feeRateTypeStateProvider),
satsPerVByte: isCustomFee ? customFeeRate : null,
utxos: (wallet is CoinControlInterface &&
@ -696,7 +704,13 @@ class _SendViewState extends ConsumerState<SendView> {
case FiroType.lelantus:
txDataFuture = wallet.prepareSendLelantus(
txData: TxData(
recipients: [(address: _address!, amount: amount)],
recipients: [
(
address: _address!,
amount: amount,
isChange: false,
)
],
),
);
break;
@ -706,13 +720,20 @@ class _SendViewState extends ConsumerState<SendView> {
txData: TxData(
recipients: ref.read(pValidSparkSendToAddress)
? null
: [(address: _address!, amount: amount)],
: [
(
address: _address!,
amount: amount,
isChange: false,
)
],
sparkRecipients: ref.read(pValidSparkSendToAddress)
? [
(
address: _address!,
amount: amount,
memo: memoController.text,
isChange: false,
)
]
: null,
@ -726,7 +747,13 @@ class _SendViewState extends ConsumerState<SendView> {
: null;
txDataFuture = wallet.prepareSend(
txData: TxData(
recipients: [(address: _address!, amount: amount)],
recipients: [
(
address: _address!,
amount: amount,
isChange: false,
)
],
memo: memo,
feeRateType: ref.read(feeRateTypeStateProvider),
satsPerVByte: isCustomFee ? customFeeRate : null,

View file

@ -482,6 +482,7 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
(
address: _address!,
amount: amount,
isChange: false,
)
],
feeRateType: ref.read(feeRateTypeStateProvider),

View file

@ -304,6 +304,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
(
address: widget.accountLite!.code,
amount: amount,
isChange: false,
)
],
satsPerVByte: isCustomFee ? customFeeRate : null,
@ -326,6 +327,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
address: _address!,
amount: amount,
memo: memoController.text,
isChange: false,
)
],
feeRateType: ref.read(feeRateTypeStateProvider),
@ -340,7 +342,13 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
} else {
txDataFuture = wallet.prepareSend(
txData: TxData(
recipients: [(address: _address!, amount: amount)],
recipients: [
(
address: _address!,
amount: amount,
isChange: false,
)
],
feeRateType: ref.read(feeRateTypeStateProvider),
satsPerVByte: isCustomFee ? customFeeRate : null,
utxos: (wallet is CoinControlInterface &&
@ -356,7 +364,13 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
case FiroType.lelantus:
txDataFuture = wallet.prepareSendLelantus(
txData: TxData(
recipients: [(address: _address!, amount: amount)],
recipients: [
(
address: _address!,
amount: amount,
isChange: false,
)
],
),
);
break;
@ -366,13 +380,20 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
txData: TxData(
recipients: ref.read(pValidSparkSendToAddress)
? null
: [(address: _address!, amount: amount)],
: [
(
address: _address!,
amount: amount,
isChange: false,
)
],
sparkRecipients: ref.read(pValidSparkSendToAddress)
? [
(
address: _address!,
amount: amount,
memo: memoController.text,
isChange: false,
)
]
: null,
@ -384,7 +405,13 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
final memo = isStellar ? memoController.text : null;
txDataFuture = wallet.prepareSend(
txData: TxData(
recipients: [(address: _address!, amount: amount)],
recipients: [
(
address: _address!,
amount: amount,
isChange: false,
)
],
memo: memo,
feeRateType: ref.read(feeRateTypeStateProvider),
satsPerVByte: isCustomFee ? customFeeRate : null,

View file

@ -243,6 +243,7 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
(
address: _address!,
amount: amount,
isChange: false,
)
],
feeRateType: ref.read(feeRateTypeStateProvider),

View file

@ -17,4 +17,4 @@ enum FiroType {
}
final publicPrivateBalanceStateProvider =
StateProvider<FiroType>((_) => FiroType.lelantus);
StateProvider<FiroType>((_) => FiroType.spark);

View file

@ -300,6 +300,7 @@ abstract final class LelantusFfiWrapper {
}) arg) async {
final spendAmount = arg.txData.recipients!.first.amount.raw.toInt();
final address = arg.txData.recipients!.first.address;
final isChange = arg.txData.recipients!.first.isChange;
final estimateJoinSplitFee = await _estimateJoinSplitFee(
(
@ -465,7 +466,9 @@ abstract final class LelantusFfiWrapper {
return arg.txData.copyWith(
txid: txId,
raw: txHex,
recipients: [(address: address, amount: amountAmount)],
recipients: [
(address: address, amount: amountAmount, isChange: isChange)
],
fee: Amount(
rawValue: BigInt.from(fee),
fractionDigits: arg.cryptoCurrency.fractionDigits,

View file

@ -25,7 +25,7 @@ class TxData {
final String? memo;
final List<({String address, Amount amount})>? recipients;
final List<({String address, Amount amount, bool isChange})>? recipients;
final Set<UTXO>? utxos;
final List<UTXO>? usedUTXOs;
@ -62,6 +62,7 @@ class TxData {
String address,
Amount amount,
String memo,
bool isChange,
})>? sparkRecipients;
final List<TxData>? sparkMints;
@ -115,6 +116,22 @@ class TxData {
.reduce((total, amount) => total += amount)
: null;
Amount? get amountWithoutChange =>
recipients != null && recipients!.isNotEmpty
? recipients!
.where((e) => !e.isChange)
.map((e) => e.amount)
.reduce((total, amount) => total += amount)
: null;
Amount? get amountSparkWithoutChange =>
sparkRecipients != null && sparkRecipients!.isNotEmpty
? sparkRecipients!
.where((e) => !e.isChange)
.map((e) => e.amount)
.reduce((total, amount) => total += amount)
: null;
int? get estimatedSatsPerVByte => fee != null && vSize != null
? (fee!.raw ~/ BigInt.from(vSize!)).toInt()
: null;
@ -133,7 +150,13 @@ class TxData {
String? memo,
Set<UTXO>? utxos,
List<UTXO>? usedUTXOs,
List<({String address, Amount amount})>? recipients,
List<
({
String address,
Amount amount,
bool isChange,
})>?
recipients,
String? frostMSConfig,
String? changeAddress,
PaynymAccountLite? paynymAccountLite,
@ -154,6 +177,7 @@ class TxData {
String address,
Amount amount,
String memo,
bool isChange,
})>?
sparkRecipients,
List<TxData>? sparkMints,

View file

@ -237,6 +237,7 @@ class TezosWallet extends Bip39Wallet<Tezos> {
(
amount: sendAmount,
address: txData.recipients!.first.address,
isChange: txData.recipients!.first.isChange,
)
],
// fee: fee,

View file

@ -111,6 +111,7 @@ class WowneroWallet extends CryptonoteWallet with MultiAddressInterface {
address:
"WW3iVcnoAY6K9zNdU4qmdvZELefx6xZz4PMpTwUifRkvMQckyadhSPYMVPJhBdYE8P9c27fg9RPmVaWNFx1cDaj61HnetqBiy",
amount: amount,
isChange: false,
),
],
feeRateType: feeRateType,

View file

@ -35,18 +35,30 @@ mixin ElectrumXInterface on Bip39HDWallet {
(_serverVersion != null && _serverVersion! >= 1.6) ||
cryptoCurrency is Firo;
List<({String address, Amount amount})> _helperRecipientsConvert(
List<String> addrs, List<int> satValues) {
final List<({String address, Amount amount})> results = [];
Future<List<({String address, Amount amount, bool isChange})>>
_helperRecipientsConvert(List<String> addrs, List<int> satValues) async {
final List<({String address, Amount amount, bool isChange})> results = [];
for (int i = 0; i < addrs.length; i++) {
results.add((
address: addrs[i],
amount: Amount(
rawValue: BigInt.from(satValues[i]),
fractionDigits: cryptoCurrency.fractionDigits,
results.add(
(
address: addrs[i],
amount: Amount(
rawValue: BigInt.from(satValues[i]),
fractionDigits: cryptoCurrency.fractionDigits,
),
isChange: (await mainDB.isar.addresses
.where()
.walletIdEqualTo(walletId)
.filter()
.subTypeEqualTo(AddressSubType.change)
.and()
.valueEqualTo(addrs[i])
.valueProperty()
.findFirst()) !=
null
),
));
);
}
return results;
@ -178,7 +190,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
final int vSizeForOneOutput = (await buildTransaction(
utxoSigningData: utxoSigningData,
txData: txData.copyWith(
recipients: _helperRecipientsConvert(
recipients: await _helperRecipientsConvert(
[recipientAddress],
[satoshisBeingUsed - 1],
),
@ -206,7 +218,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
final int amount = satoshiAmountToSend - feeForOneOutput;
final data = await buildTransaction(
txData: txData.copyWith(
recipients: _helperRecipientsConvert(
recipients: await _helperRecipientsConvert(
[recipientAddress],
[amount],
),
@ -228,7 +240,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
vSizeForOneOutput = (await buildTransaction(
utxoSigningData: utxoSigningData,
txData: txData.copyWith(
recipients: _helperRecipientsConvert(
recipients: await _helperRecipientsConvert(
[recipientAddress],
[satoshisBeingUsed - 1],
),
@ -245,7 +257,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
vSizeForTwoOutPuts = (await buildTransaction(
utxoSigningData: utxoSigningData,
txData: txData.copyWith(
recipients: _helperRecipientsConvert(
recipients: await _helperRecipientsConvert(
[recipientAddress, (await getCurrentChangeAddress())!.value],
[
satoshiAmountToSend,
@ -321,7 +333,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
var txn = await buildTransaction(
utxoSigningData: utxoSigningData,
txData: txData.copyWith(
recipients: _helperRecipientsConvert(
recipients: await _helperRecipientsConvert(
recipientsArray,
recipientsAmtArray,
),
@ -352,7 +364,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
txn = await buildTransaction(
utxoSigningData: utxoSigningData,
txData: txData.copyWith(
recipients: _helperRecipientsConvert(
recipients: await _helperRecipientsConvert(
recipientsArray,
recipientsAmtArray,
),
@ -383,7 +395,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
final txn = await buildTransaction(
utxoSigningData: utxoSigningData,
txData: txData.copyWith(
recipients: _helperRecipientsConvert(
recipients: await _helperRecipientsConvert(
recipientsArray,
recipientsAmtArray,
),
@ -415,7 +427,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
final txn = await buildTransaction(
utxoSigningData: utxoSigningData,
txData: txData.copyWith(
recipients: _helperRecipientsConvert(
recipients: await _helperRecipientsConvert(
recipientsArray,
recipientsAmtArray,
),
@ -447,7 +459,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
final txn = await buildTransaction(
utxoSigningData: utxoSigningData,
txData: txData.copyWith(
recipients: _helperRecipientsConvert(
recipients: await _helperRecipientsConvert(
recipientsArray,
recipientsAmtArray,
),

View file

@ -800,6 +800,7 @@ mixin LelantusInterface on Bip39HDWallet, ElectrumXInterface {
fractionDigits: cryptoCurrency.fractionDigits,
),
address: "no address for lelantus mints",
isChange: false,
)
],
vSize: builtHex.virtualSize(),

View file

@ -370,6 +370,7 @@ mixin PaynymInterface on Bip39HDWallet, ElectrumXInterface {
(
address: sendToAddress.value,
amount: txData.recipients!.first.amount,
isChange: false,
),
],
),
@ -582,7 +583,11 @@ mixin PaynymInterface on Bip39HDWallet, ElectrumXInterface {
final txData = TxData(
raw: txn.item1,
recipients: [
(address: targetPaymentCodeString, amount: amountToSend)
(
address: targetPaymentCodeString,
amount: amountToSend,
isChange: false,
),
],
fee: Amount(
rawValue: feeBeingPaid,
@ -610,6 +615,7 @@ mixin PaynymInterface on Bip39HDWallet, ElectrumXInterface {
(
address: targetPaymentCodeString,
amount: amountToSend,
isChange: false,
)
],
fee: Amount(
@ -639,6 +645,7 @@ mixin PaynymInterface on Bip39HDWallet, ElectrumXInterface {
(
address: targetPaymentCodeString,
amount: amountToSend,
isChange: false,
)
],
fee: Amount(

View file

@ -283,12 +283,18 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
txb.setLockTime(await chainHeight);
txb.setVersion(3 | (9 << 16));
List<({String address, Amount amount})>? recipientsWithFeeSubtracted;
List<
({
String address,
Amount amount,
bool isChange,
})>? recipientsWithFeeSubtracted;
List<
({
String address,
Amount amount,
String memo,
bool isChange,
})>? sparkRecipientsWithFeeSubtracted;
final recipientCount = (txData.recipients
?.where(
@ -330,6 +336,7 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
fractionDigits: cryptoCurrency.fractionDigits,
),
memo: txData.sparkRecipients![i].memo,
isChange: sparkChangeAddress == txData.sparkRecipients![i].address,
),
);
}
@ -350,6 +357,7 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
(estimatedFee ~/ BigInt.from(totalRecipientCount)),
fractionDigits: cryptoCurrency.fractionDigits,
),
isChange: txData.recipients![i].isChange,
),
);
@ -1157,6 +1165,7 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
rawValue: BigInt.from(e.$2),
fractionDigits: cryptoCurrency.fractionDigits,
),
isChange: false, // ok?
),
)
.toList(),