From 787e118e4fe7f85819c001526f2389f2aeb0e666 Mon Sep 17 00:00:00 2001 From: Julian Date: Mon, 9 Feb 2026 10:37:32 -0600 Subject: [PATCH] fix spark swap send from flow --- .../confirm_change_now_send.dart | 516 +++++++++--------- lib/pages/exchange_view/send_from_view.dart | 12 +- 2 files changed, 262 insertions(+), 266 deletions(-) diff --git a/lib/pages/exchange_view/confirm_change_now_send.dart b/lib/pages/exchange_view/confirm_change_now_send.dart index 69e77f13c1..b98e4e3b0e 100644 --- a/lib/pages/exchange_view/confirm_change_now_send.dart +++ b/lib/pages/exchange_view/confirm_change_now_send.dart @@ -179,10 +179,9 @@ class _ConfirmChangeNowSendViewState child: Text( "Ok", style: STextStyles.button(context).copyWith( - color: - Theme.of( - context, - ).extension()!.buttonTextSecondary, + color: Theme.of( + context, + ).extension()!.buttonTextSecondary, ), ), onPressed: () { @@ -203,44 +202,38 @@ class _ConfirmChangeNowSendViewState if (Util.isDesktop) { unlocked = await showDialog( context: context, - builder: - (context) => DesktopDialog( - maxWidth: 580, - maxHeight: double.infinity, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [DesktopDialogCloseButton()], - ), - Padding( - padding: const EdgeInsets.only( - left: 32, - right: 32, - bottom: 32, - ), - child: DesktopAuthSend(coin: coin), - ), - ], + builder: (context) => DesktopDialog( + maxWidth: 580, + maxHeight: double.infinity, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [DesktopDialogCloseButton()], ), - ), + Padding( + padding: const EdgeInsets.only(left: 32, right: 32, bottom: 32), + child: DesktopAuthSend(coin: coin), + ), + ], + ), + ), ); } else { unlocked = await Navigator.push( context, RouteGenerator.getRoute( shouldUseMaterialRoute: RouteGenerator.useMaterialPageRoute, - builder: - (_) => const LockscreenView( - showBackButton: true, - popOnSuccess: true, - routeOnSuccessArguments: true, - routeOnSuccess: "", - biometricsCancelButtonString: "CANCEL", - biometricsLocalizedReason: "Authenticate to send transaction", - biometricsAuthenticationTitle: "Confirm Transaction", - ), + builder: (_) => const LockscreenView( + showBackButton: true, + popOnSuccess: true, + routeOnSuccessArguments: true, + routeOnSuccess: "", + biometricsCancelButtonString: "CANCEL", + biometricsLocalizedReason: "Authenticate to send transaction", + biometricsAuthenticationTitle: "Confirm Transaction", + ), settings: const RouteSettings(name: "/confirmsendlockscreen"), ), ); @@ -276,11 +269,13 @@ class _ConfirmChangeNowSendViewState builder: (child) { return Background( child: Scaffold( - backgroundColor: - Theme.of(context).extension()!.background, + backgroundColor: Theme.of( + context, + ).extension()!.background, appBar: AppBar( - backgroundColor: - Theme.of(context).extension()!.backgroundAppBar, + backgroundColor: Theme.of( + context, + ).extension()!.backgroundAppBar, leading: AppBarBackButton( onPressed: () async { // if (FocusScope.of(context).hasFocus) { @@ -326,188 +321,167 @@ class _ConfirmChangeNowSendViewState }, child: ConditionalParent( condition: isDesktop, - builder: - (child) => DesktopDialog( - maxHeight: double.infinity, - maxWidth: 580, - child: Column( + builder: (child) => DesktopDialog( + maxHeight: double.infinity, + maxWidth: 580, + child: Column( + children: [ + Row( children: [ - Row( - children: [ - const SizedBox(width: 6), - const AppBarBackButton(isCompact: true, iconSize: 23), - const SizedBox(width: 12), - Text( - "Confirm ${ref.watch(pWalletCoin(walletId)).ticker} transaction", - style: STextStyles.desktopH3(context), - ), - ], + const SizedBox(width: 6), + const AppBarBackButton(isCompact: true, iconSize: 23), + const SizedBox(width: 12), + Text( + "Confirm ${ref.watch(pWalletCoin(walletId)).ticker} transaction", + style: STextStyles.desktopH3(context), ), - Padding( - padding: const EdgeInsets.only( - left: 32, - right: 32, - bottom: 32, + ], + ), + Padding( + padding: const EdgeInsets.only(left: 32, right: 32, bottom: 32), + child: Column( + children: [ + RoundedWhiteContainer( + padding: const EdgeInsets.all(0), + borderColor: Theme.of( + context, + ).extension()!.background, + child: child, ), - child: Column( + const SizedBox(height: 16), + Row( children: [ - RoundedWhiteContainer( - padding: const EdgeInsets.all(0), - borderColor: - Theme.of( - context, - ).extension()!.background, - child: child, - ), - const SizedBox(height: 16), - Row( - children: [ - Text( - "Transaction fee", - style: STextStyles.desktopTextExtraExtraSmall( - context, - ), - ), - ], + Text( + "Transaction fee", + style: STextStyles.desktopTextExtraExtraSmall( + context, + ), ), - const SizedBox(height: 10), - RoundedContainer( - color: - Theme.of( - context, - ).extension()!.textFieldDefaultBG, - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Text( - ref - .watch( - pAmountFormatter( - ref.watch(pWalletCoin(walletId)), - ), - ) - .format(widget.txData.fee!), - style: STextStyles.desktopTextExtraExtraSmall( + ], + ), + const SizedBox(height: 10), + RoundedContainer( + color: Theme.of( + context, + ).extension()!.textFieldDefaultBG, + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text( + ref + .watch( + pAmountFormatter( + ref.watch(pWalletCoin(walletId)), + ), + ) + .format(widget.txData.fee!), + style: + STextStyles.desktopTextExtraExtraSmall( context, ).copyWith( - color: - Theme.of( - context, - ).extension()!.textDark, + color: Theme.of( + context, + ).extension()!.textDark, ), - ), - ], ), - ), - const SizedBox(height: 16), - RoundedContainer( - color: - Theme.of( - context, - ).extension()!.snackBarBackSuccess, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Total amount", - style: STextStyles.titleBold12( - context, - ).copyWith( - color: - Theme.of(context) + ], + ), + ), + const SizedBox(height: 16), + RoundedContainer( + color: Theme.of( + context, + ).extension()!.snackBarBackSuccess, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Total amount", + style: STextStyles.titleBold12(context).copyWith( + color: Theme.of(context) + .extension()! + .textConfirmTotalAmount, + ), + ), + Builder( + builder: (context) { + final coin = ref.read(pWalletCoin(walletId)); + final fee = widget.txData.fee!; + final amount = widget.txData.amountWithoutChange!; + final total = amount + fee; + + return Text( + ref.watch(pAmountFormatter(coin)).format(total), + style: STextStyles.itemSubtitle12(context) + .copyWith( + color: Theme.of(context) .extension()! .textConfirmTotalAmount, - ), - ), - Builder( - builder: (context) { - final coin = ref.read(pWalletCoin(walletId)); - final fee = widget.txData.fee!; - final amount = - widget.txData.amountWithoutChange!; - final total = amount + fee; - - return Text( - ref - .watch(pAmountFormatter(coin)) - .format(total), - style: STextStyles.itemSubtitle12( - context, - ).copyWith( - color: - Theme.of(context) - .extension()! - .textConfirmTotalAmount, ), - textAlign: TextAlign.right, - ); - }, - ), - ], + textAlign: TextAlign.right, + ); + }, + ), + ], + ), + ), + const SizedBox(height: 16), + Row( + children: [ + Expanded( + child: SecondaryButton( + label: "Cancel", + buttonHeight: ButtonHeight.l, + onPressed: Navigator.of(context).pop, ), ), - const SizedBox(height: 16), - Row( - children: [ - Expanded( - child: SecondaryButton( - label: "Cancel", - buttonHeight: ButtonHeight.l, - onPressed: Navigator.of(context).pop, - ), - ), - const SizedBox(width: 16), - Expanded( - child: PrimaryButton( - label: "Send", - buttonHeight: isDesktop ? ButtonHeight.l : null, - onPressed: _confirmSend, - ), - ), - ], + const SizedBox(width: 16), + Expanded( + child: PrimaryButton( + label: "Send", + buttonHeight: isDesktop ? ButtonHeight.l : null, + onPressed: _confirmSend, + ), ), ], ), - ), - ], + ], + ), ), - ), + ], + ), + ), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ ConditionalParent( condition: isDesktop, - builder: - (child) => Container( - decoration: BoxDecoration( - color: - Theme.of( - context, - ).extension()!.background, - borderRadius: BorderRadius.vertical( - top: Radius.circular( - Constants.size.circularBorderRadius, - ), - ), - ), - child: Padding( - padding: const EdgeInsets.all(12), - child: Row(children: [child]), - ), + builder: (child) => Container( + decoration: BoxDecoration( + color: Theme.of(context).extension()!.background, + borderRadius: BorderRadius.vertical( + top: Radius.circular(Constants.size.circularBorderRadius), ), + ), + child: Padding( + padding: const EdgeInsets.all(12), + child: Row(children: [child]), + ), + ), child: Text( "Send ${ref.watch(pWalletCoin(walletId)).ticker}", - style: - isDesktop - ? STextStyles.desktopTextMedium(context) - : STextStyles.pageTitleH1(context), + style: isDesktop + ? STextStyles.desktopTextMedium(context) + : STextStyles.pageTitleH1(context), ), ), isDesktop ? Container( - color: Theme.of(context).extension()!.background, - height: 1, - ) + color: Theme.of( + context, + ).extension()!.background, + height: 1, + ) : const SizedBox(height: 12), RoundedWhiteContainer( child: Column( @@ -524,9 +498,11 @@ class _ConfirmChangeNowSendViewState ), isDesktop ? Container( - color: Theme.of(context).extension()!.background, - height: 1, - ) + color: Theme.of( + context, + ).extension()!.background, + height: 1, + ) : const SizedBox(height: 12), RoundedWhiteContainer( child: Column( @@ -538,7 +514,8 @@ class _ConfirmChangeNowSendViewState ), const SizedBox(height: 4), Text( - widget.txData.recipients!.first.address, + widget.txData.recipients?.first.address ?? + widget.txData.sparkRecipients!.first.address, style: STextStyles.itemSubtitle12(context), ), ], @@ -546,9 +523,11 @@ class _ConfirmChangeNowSendViewState ), isDesktop ? Container( - color: Theme.of(context).extension()!.background, - height: 1, - ) + color: Theme.of( + context, + ).extension()!.background, + height: 1, + ) : const SizedBox(height: 12), RoundedWhiteContainer( child: Row( @@ -557,63 +536,65 @@ class _ConfirmChangeNowSendViewState Text("Amount", style: STextStyles.smallMed12(context)), ConditionalParent( condition: isDesktop, - builder: - (child) => Row( - children: [ - child, - Builder( - builder: (context) { - final coin = ref.watch(pWalletCoin(walletId)); - final price = ref.watch( - priceAnd24hChangeNotifierProvider.select( - (value) => value.getPrice(coin), - ), - ); - final String extra; - if (price == null) { - extra = ""; - } else { - final amountWithoutChange = - widget.txData.amountWithoutChange!; - final value = (price.value * - amountWithoutChange.decimal) + builder: (child) => Row( + children: [ + child, + Builder( + builder: (context) { + final coin = ref.watch(pWalletCoin(walletId)); + final price = ref.watch( + priceAnd24hChangeNotifierProvider.select( + (value) => value.getPrice(coin), + ), + ); + final String extra; + if (price == null) { + extra = ""; + } else { + final amountWithoutChange = + widget.txData.amountWithoutChange!; + final value = + (price.value * amountWithoutChange.decimal) .toAmount(fractionDigits: 2); - final currency = ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.currency, - ), - ); - final locale = ref.watch( - localeServiceChangeNotifierProvider.select( - (value) => value.locale, - ), - ); + final currency = ref.watch( + prefsChangeNotifierProvider.select( + (value) => value.currency, + ), + ); + final locale = ref.watch( + localeServiceChangeNotifierProvider.select( + (value) => value.locale, + ), + ); - extra = - " | ${value.fiatString(locale: locale)} $currency"; - } + extra = + " | ${value.fiatString(locale: locale)} $currency"; + } - return Text( - extra, - style: STextStyles.desktopTextExtraExtraSmall( + return Text( + extra, + style: + STextStyles.desktopTextExtraExtraSmall( context, ).copyWith( - color: - Theme.of(context) - .extension()! - .textSubtitle2, + color: Theme.of( + context, + ).extension()!.textSubtitle2, ), - ); - }, - ), - ], + ); + }, ), + ], + ), child: Text( ref .watch( pAmountFormatter(ref.watch(pWalletCoin(walletId))), ) - .format((widget.txData.amountWithoutChange!)), + .format( + (widget.txData.amountWithoutChange ?? + widget.txData.amountSparkWithoutChange!), + ), style: STextStyles.itemSubtitle12(context), textAlign: TextAlign.right, ), @@ -623,9 +604,11 @@ class _ConfirmChangeNowSendViewState ), isDesktop ? Container( - color: Theme.of(context).extension()!.background, - height: 1, - ) + color: Theme.of( + context, + ).extension()!.background, + height: 1, + ) : const SizedBox(height: 12), RoundedWhiteContainer( child: Row( @@ -649,9 +632,11 @@ class _ConfirmChangeNowSendViewState ), isDesktop ? Container( - color: Theme.of(context).extension()!.background, - height: 1, - ) + color: Theme.of( + context, + ).extension()!.background, + height: 1, + ) : const SizedBox(height: 12), RoundedWhiteContainer( child: Column( @@ -668,9 +653,11 @@ class _ConfirmChangeNowSendViewState ), isDesktop ? Container( - color: Theme.of(context).extension()!.background, - height: 1, - ) + color: Theme.of( + context, + ).extension()!.background, + height: 1, + ) : const SizedBox(height: 12), RoundedWhiteContainer( child: Row( @@ -688,36 +675,35 @@ class _ConfirmChangeNowSendViewState if (!isDesktop) const SizedBox(height: 12), if (!isDesktop) RoundedContainer( - color: - Theme.of( - context, - ).extension()!.snackBarBackSuccess, + color: Theme.of( + context, + ).extension()!.snackBarBackSuccess, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( "Total amount", style: STextStyles.titleBold12(context).copyWith( - color: - Theme.of( - context, - ).extension()!.textConfirmTotalAmount, + color: Theme.of( + context, + ).extension()!.textConfirmTotalAmount, ), ), Builder( builder: (context) { final coin = ref.watch(pWalletCoin(walletId)); final fee = widget.txData.fee!; - final amount = widget.txData.amountWithoutChange!; + final amount = + widget.txData.amountWithoutChange ?? + widget.txData.amountSparkWithoutChange!; final total = amount + fee; return Text( ref.watch(pAmountFormatter(coin)).format(total), style: STextStyles.itemSubtitle12(context).copyWith( - color: - Theme.of(context) - .extension()! - .textConfirmTotalAmount, + color: Theme.of( + context, + ).extension()!.textConfirmTotalAmount, ), textAlign: TextAlign.right, ); diff --git a/lib/pages/exchange_view/send_from_view.dart b/lib/pages/exchange_view/send_from_view.dart index 4811b65061..dcde13ed1f 100644 --- a/lib/pages/exchange_view/send_from_view.dart +++ b/lib/pages/exchange_view/send_from_view.dart @@ -305,7 +305,17 @@ class _SendFromCardState extends ConsumerState { } else { txDataFuture = firoWallet.prepareSendSpark( txData: TxData( - recipients: [recipient], + recipients: recipient.addressType == .spark ? null : [recipient], + sparkRecipients: recipient.addressType == .spark + ? [ + ( + address: recipient.address, + amount: recipient.amount, + memo: "", + isChange: false, + ), + ] + : null, // feeRateType: FeeRateType.average, ), );