diff --git a/lib/models/isar/models/blockchain_data/v2/transaction_v2.dart b/lib/models/isar/models/blockchain_data/v2/transaction_v2.dart index b7ba87546..1dfe534b2 100644 --- a/lib/models/isar/models/blockchain_data/v2/transaction_v2.dart +++ b/lib/models/isar/models/blockchain_data/v2/transaction_v2.dart @@ -2,12 +2,13 @@ import 'dart:convert'; import 'dart:math'; import 'package:isar/isar.dart'; -import '../transaction.dart'; -import 'input_v2.dart'; -import 'output_v2.dart'; + import '../../../../../utilities/amount/amount.dart'; import '../../../../../utilities/extensions/extensions.dart'; import '../../../../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart'; +import '../transaction.dart'; +import 'input_v2.dart'; +import 'output_v2.dart'; part 'transaction_v2.g.dart'; diff --git a/lib/pages/wallet_view/transaction_views/tx_v2/boost_transaction_view.dart b/lib/pages/wallet_view/transaction_views/tx_v2/boost_transaction_view.dart index 4a4f40504..b9b53d21c 100644 --- a/lib/pages/wallet_view/transaction_views/tx_v2/boost_transaction_view.dart +++ b/lib/pages/wallet_view/transaction_views/tx_v2/boost_transaction_view.dart @@ -31,7 +31,6 @@ import '../../../../utilities/logger.dart'; import '../../../../utilities/text_styles.dart'; import '../../../../utilities/util.dart'; import '../../../../wallets/crypto_currency/crypto_currency.dart'; -import '../../../../wallets/crypto_currency/intermediate/nano_currency.dart'; import '../../../../wallets/isar/models/spark_coin.dart'; import '../../../../wallets/isar/providers/wallet_info_provider.dart'; import '../../../../wallets/wallet/impl/epiccash_wallet.dart'; @@ -1252,127 +1251,107 @@ class _BoostTransactionViewState extends ConsumerState { // ], // ), // ), - if (coin is! NanoCurrency) - isDesktop - ? const _Divider() - : const SizedBox( - height: 12, - ), - if (coin is! NanoCurrency) - RoundedWhiteContainer( - padding: isDesktop - ? const EdgeInsets.all(16) - : const EdgeInsets.all(12), - child: Builder( - builder: (context) { - final String feeString = showFeePending - ? _transaction.isConfirmed( - currentHeight, - minConfirms, - ) - ? ref - .watch(pAmountFormatter(coin)) - .format( - fee, - ) - : "Pending" - : ref - .watch(pAmountFormatter(coin)) - .format( - fee, - ); - - return Column( - children: [ - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - "Transaction fee", - style: isDesktop - ? STextStyles - .desktopTextExtraExtraSmall( - context, - ) - : STextStyles - .itemSubtitle( - context, - ), - ), - if (isDesktop) - const SizedBox( - height: 2, - ), - if (isDesktop) - SelectableText( - feeString, - style: isDesktop - ? STextStyles - .desktopTextExtraExtraSmall( - context, - ).copyWith( - color: Theme.of( - context) - .extension< - StackColors>()! - .textDark, - ) - : STextStyles - .itemSubtitle12( - context, - ), - ), - ], - ), - if (!isDesktop) - SelectableText( - feeString, + isDesktop + ? const _Divider() + : const SizedBox( + height: 12, + ), + RoundedWhiteContainer( + padding: isDesktop + ? const EdgeInsets.all(16) + : const EdgeInsets.all(12), + child: Builder( + builder: (context) { + final String feeString = showFeePending + ? _transaction.isConfirmed( + currentHeight, + minConfirms, + ) + ? ref + .watch(pAmountFormatter(coin)) + .format( + fee, + ) + : "Pending" + : ref + .watch(pAmountFormatter(coin)) + .format( + fee, + ); + return Column( + children: [ + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + "Transaction fee", style: isDesktop ? STextStyles .desktopTextExtraExtraSmall( context, - ).copyWith( - color: Theme.of(context) - .extension< - StackColors>()! - .textDark, ) - : STextStyles - .itemSubtitle12( + : STextStyles.itemSubtitle( context, ), ), - // if (isDesktop) - // IconCopyButton(data: feeString), - ], - ), - Padding( - padding: const EdgeInsets.only( - bottom: 12, - top: 16, + if (isDesktop) + const SizedBox( + height: 2, + ), + if (isDesktop) + SelectableText( + feeString, + style: isDesktop + ? STextStyles + .desktopTextExtraExtraSmall( + context, + ).copyWith( + color: Theme.of( + context) + .extension< + StackColors>()! + .textDark, + ) + : STextStyles + .itemSubtitle12( + context, + ), + ), + ], ), - child: BoostFeeSlider( - coin: coin, - onFeeChanged: (fee) { - customFee = fee; - }, - min: fee.raw, - max: fee.raw * BigInt.from(4), - // TODO [prio=med]: The max fee should be set to an absurd fee. - ), - ) - ], - ); - }, - ), + if (!isDesktop) + SelectableText( + feeString, + style: isDesktop + ? STextStyles + .desktopTextExtraExtraSmall( + context, + ).copyWith( + color: Theme.of(context) + .extension< + StackColors>()! + .textDark, + ) + : STextStyles.itemSubtitle12( + context, + ), + ), + // if (isDesktop) + // IconCopyButton(data: feeString), + ], + ), + ], + ); + }, ), + ), // isDesktop // ? const _Divider() // : const SizedBox( @@ -1806,6 +1785,110 @@ class _BoostTransactionViewState extends ConsumerState { : const SizedBox( height: 12, ), + + isDesktop + ? const _Divider() + : const SizedBox( + height: 12, + ), + RoundedWhiteContainer( + padding: isDesktop + ? const EdgeInsets.all(16) + : const EdgeInsets.all(12), + child: Builder( + builder: (context) { + final String feeString = showFeePending + ? _transaction.isConfirmed( + currentHeight, + minConfirms, + ) + ? ref + .watch(pAmountFormatter(coin)) + .format( + fee, + ) + : "Pending" + : ref + .watch(pAmountFormatter(coin)) + .format( + fee, + ); + return Column( + children: [ + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + "Boost fee", + style: isDesktop + ? STextStyles + .desktopTextExtraExtraSmall( + context, + ) + : STextStyles.itemSubtitle( + context, + ), + ), + ], + ), + if (!isDesktop) + SelectableText( + feeString, + style: isDesktop + ? STextStyles + .desktopTextExtraExtraSmall( + context, + ).copyWith( + color: Theme.of(context) + .extension< + StackColors>()! + .textDark, + ) + : STextStyles.itemSubtitle12( + context, + ), + ), + // if (isDesktop) + // IconCopyButton(data: feeString), + ], + ), + Padding( + padding: const EdgeInsets.only( + bottom: 12, + top: 16, + ), + child: BoostFeeSlider( + coin: coin, + onFeeChanged: (fee) { + customFee = fee; + }, + min: fee.raw, + max: fee.raw * BigInt.from(4), + // TODO [prio=med]: The max fee should be set to an absurd fee. + ), + ), + const SizedBox( + height: 36, + ), + PrimaryButton( + buttonHeight: ButtonHeight.l, + label: "Preview send", + onPressed: + /* // TODO [prio=high]: define previewSend*/ + () => null, + ), + ], + ); + }, + ), + ), ], ), ), diff --git a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart index e700d967b..2d7560247 100644 --- a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart +++ b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart @@ -1333,18 +1333,20 @@ class _TransactionV2DetailsViewState ), ), if (whatIsIt( - _transaction, - currentHeight, - ) == - "Sending") + _transaction, + currentHeight, + ) == + "Sending" && + coin is! NanoCurrency) const SizedBox( height: 8, ), if (whatIsIt( - _transaction, - currentHeight, - ) == - "Sending") + _transaction, + currentHeight, + ) == + "Sending" && + coin is! NanoCurrency) CustomTextButton( text: "Boost transaction", onTap: () async { diff --git a/lib/widgets/boost_fee_slider.dart b/lib/widgets/boost_fee_slider.dart index 2d5f7dd65..00548c5cf 100644 --- a/lib/widgets/boost_fee_slider.dart +++ b/lib/widgets/boost_fee_slider.dart @@ -13,6 +13,7 @@ class BoostFeeSlider extends ConsumerStatefulWidget { final BigInt max; BoostFeeSlider({ + super.key, required this.coin, required this.onFeeChanged, required this.min, @@ -40,13 +41,17 @@ class _BoostFeeSliderState extends ConsumerState { ), ); _textEditingController.addListener(() { - BigInt? value = - BigInt.tryParse(_textEditingController.text.replaceAll(',', '')); - if (value != null && value >= widget.min && value <= widget.max) { - setState(() { - _currentSliderValue = value.toDouble(); - widget.onFeeChanged(value); - }); + final double? value = + double.tryParse(_textEditingController.text.replaceAll(',', '')); + if (value != null) { + final BigInt bigIntValue = BigInt.from( + value * BigInt.from(10).pow(widget.coin.fractionDigits).toInt()); + if (bigIntValue >= widget.min && bigIntValue <= widget.max) { + setState(() { + _currentSliderValue = value; + widget.onFeeChanged(bigIntValue); + }); + } } }); } @@ -87,28 +92,34 @@ class _BoostFeeSliderState extends ConsumerState { }, ), ), - SizedBox(width: 16), - Container( - width: 122, + SizedBox( + width: 16 + // Left and right padding. + 122 / 8 * widget.coin.fractionDigits + // Variable width. + 8 * widget.coin.ticker.length, // End padding for ticker. child: TextField( controller: _textEditingController, - keyboardType: TextInputType.number, + keyboardType: TextInputType.numberWithOptions(decimal: true), inputFormatters: [ - FilteringTextInputFormatter.digitsOnly, + FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d*')), ], - decoration: InputDecoration( + decoration: const InputDecoration( border: OutlineInputBorder(), ), onChanged: (value) { - BigInt? newValue = - BigInt.tryParse(value.replaceAll(',', '')); - if (newValue != null && - newValue >= widget.min && - newValue <= widget.max) { - setState(() { - _currentSliderValue = newValue.toDouble(); - widget.onFeeChanged(newValue); - }); + final double? newValue = + double.tryParse(value.replaceAll(',', '')); + if (newValue != null) { + final BigInt bigIntValue = BigInt.from(newValue * + BigInt.from(10) + .pow(widget.coin.fractionDigits) + .toInt()); + if (bigIntValue >= widget.min && + bigIntValue <= widget.max) { + setState(() { + _currentSliderValue = newValue; + widget.onFeeChanged(bigIntValue); + }); + } } }, ),