close exchange step 4 back to wallet or exchange home view

This commit is contained in:
julian 2023-02-09 07:31:31 -06:00
parent e78fc3ef9e
commit 86ca402401
3 changed files with 561 additions and 515 deletions

View file

@ -15,6 +15,7 @@ class IncompleteExchangeModel extends ChangeNotifier {
final ExchangeRateType rateType; final ExchangeRateType rateType;
final bool reversed; final bool reversed;
final bool walletInitiated;
String? _recipientAddress; String? _recipientAddress;
@ -68,6 +69,7 @@ class IncompleteExchangeModel extends ChangeNotifier {
required this.receiveAmount, required this.receiveAmount,
required this.rateType, required this.rateType,
required this.reversed, required this.reversed,
required this.walletInitiated,
String? rateId, String? rateId,
}) : _rateId = rateId; }) : _rateId = rateId;
} }

View file

@ -558,6 +558,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
rateType: rateType, rateType: rateType,
rateId: estimate.rateId, rateId: estimate.rateId,
reversed: estimate.reversed, reversed: estimate.reversed,
walletInitiated: walletInitiated,
); );
if (mounted) { if (mounted) {

View file

@ -12,6 +12,7 @@ import 'package:stackwallet/pages/exchange_view/send_from_view.dart';
import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart'; import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart';
import 'package:stackwallet/pages/home_view/home_view.dart'; import 'package:stackwallet/pages/home_view/home_view.dart';
import 'package:stackwallet/pages/send_view/sub_widgets/building_transaction_dialog.dart'; import 'package:stackwallet/pages/send_view/sub_widgets/building_transaction_dialog.dart';
import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/route_generator.dart'; import 'package:stackwallet/route_generator.dart';
import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/assets.dart';
@ -105,24 +106,50 @@ class _Step4ViewState extends ConsumerState<Step4View> {
super.dispose(); super.dispose();
} }
@override Future<void> _close() async {
Widget build(BuildContext context) {
final bool isWalletCoin =
_isWalletCoinAndHasWallet(model.trade!.payInCurrency, ref);
return Background(
child: Scaffold(
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () async {
if (FocusScope.of(context).hasFocus) { if (FocusScope.of(context).hasFocus) {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
await Future<void>.delayed(const Duration(milliseconds: 75)); await Future<void>.delayed(const Duration(milliseconds: 75));
} }
if (mounted) { if (mounted) {
Navigator.of(context).pop(); Navigator.of(context).popUntil(
ModalRoute.withName(
model.walletInitiated ? WalletView.routeName : HomeView.routeName,
),
);
} }
}
@override
Widget build(BuildContext context) {
final bool isWalletCoin =
_isWalletCoinAndHasWallet(model.trade!.payInCurrency, ref);
return WillPopScope(
onWillPop: () async {
await _close();
return false;
}, },
child: Background(
child: Scaffold(
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
leading: Padding(
padding: const EdgeInsets.all(10),
child: AppBarIconButton(
size: 32,
color: Theme.of(context).extension<StackColors>()!.background,
shadows: const [],
icon: SvgPicture.asset(
Assets.svg.x,
width: 24,
height: 24,
color: Theme.of(context)
.extension<StackColors>()!
.topNavIconPrimary,
),
onPressed: _close,
),
), ),
title: Text( title: Text(
"Exchange", "Exchange",
@ -184,7 +211,8 @@ class _Step4ViewState extends ConsumerState<Step4View> {
TextSpan( TextSpan(
text: text:
"If you send less than ${model.sendAmount.toString()} ${model.sendTicker}, your transaction may not be converted and it may not be refunded.", "If you send less than ${model.sendAmount.toString()} ${model.sendTicker}, your transaction may not be converted and it may not be refunded.",
style: STextStyles.label(context).copyWith( style:
STextStyles.label(context).copyWith(
color: Theme.of(context) color: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.warningForeground, .warningForeground,
@ -207,12 +235,14 @@ class _Step4ViewState extends ConsumerState<Step4View> {
children: [ children: [
Text( Text(
"Amount", "Amount",
style: STextStyles.itemSubtitle(context), style:
STextStyles.itemSubtitle(context),
), ),
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
final data = ClipboardData( final data = ClipboardData(
text: model.sendAmount.toString()); text:
model.sendAmount.toString());
await clipboard.setData(data); await clipboard.setData(data);
unawaited(showFloatingFlushBar( unawaited(showFloatingFlushBar(
type: FlushBarType.info, type: FlushBarType.info,
@ -264,7 +294,8 @@ class _Step4ViewState extends ConsumerState<Step4View> {
children: [ children: [
Text( Text(
"Send ${model.sendTicker.toUpperCase()} to this address", "Send ${model.sendTicker.toUpperCase()} to this address",
style: STextStyles.itemSubtitle(context), style:
STextStyles.itemSubtitle(context),
), ),
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
@ -358,7 +389,8 @@ class _Step4ViewState extends ConsumerState<Step4View> {
), ),
RoundedWhiteContainer( RoundedWhiteContainer(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
"Status", "Status",
@ -425,7 +457,8 @@ class _Step4ViewState extends ConsumerState<Step4View> {
Expanded( Expanded(
child: TextButton( child: TextButton(
onPressed: () => onPressed: () =>
Navigator.of(context).pop(), Navigator.of(context)
.pop(),
style: Theme.of(context) style: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.getSecondaryEnabledButtonStyle( .getSecondaryEnabledButtonStyle(
@ -469,7 +502,8 @@ class _Step4ViewState extends ConsumerState<Step4View> {
String buttonTitle = "Send from Stack Wallet"; String buttonTitle = "Send from Stack Wallet";
final tuple = ref final tuple = ref
.read(exchangeSendFromWalletIdStateProvider .read(
exchangeSendFromWalletIdStateProvider
.state) .state)
.state; .state;
if (tuple != null && if (tuple != null &&
@ -511,7 +545,8 @@ class _Step4ViewState extends ConsumerState<Step4View> {
onCancel: () { onCancel: () {
wasCancelled = true; wasCancelled = true;
Navigator.of(context).pop(); Navigator.of(context)
.pop();
}, },
); );
}, },
@ -522,7 +557,8 @@ class _Step4ViewState extends ConsumerState<Step4View> {
address: address, address: address,
satoshiAmount: amount, satoshiAmount: amount,
args: { args: {
"feeRate": FeeRateType.average, "feeRate":
FeeRateType.average,
// ref.read(feeRateTypeStateProvider) // ref.read(feeRateTypeStateProvider)
}, },
); );
@ -540,7 +576,8 @@ class _Step4ViewState extends ConsumerState<Step4View> {
if (mounted) { if (mounted) {
unawaited( unawaited(
Navigator.of(context).push( Navigator.of(context)
.push(
RouteGenerator.getRoute( RouteGenerator.getRoute(
shouldUseMaterialRoute: shouldUseMaterialRoute:
RouteGenerator RouteGenerator
@ -584,10 +621,12 @@ class _Step4ViewState extends ConsumerState<Step4View> {
context), context),
child: Text( child: Text(
"Ok", "Ok",
style: STextStyles.button( style:
STextStyles.button(
context) context)
.copyWith( .copyWith(
color: Theme.of(context) color: Theme.of(
context)
.extension< .extension<
StackColors>()! StackColors>()!
.buttonTextSecondary, .buttonTextSecondary,
@ -610,15 +649,16 @@ class _Step4ViewState extends ConsumerState<Step4View> {
shouldUseMaterialRoute: shouldUseMaterialRoute:
RouteGenerator RouteGenerator
.useMaterialPageRoute, .useMaterialPageRoute,
builder: (BuildContext context) { builder:
(BuildContext context) {
return SendFromView( return SendFromView(
coin: coin:
coinFromTickerCaseInsensitive( coinFromTickerCaseInsensitive(
model.trade! model.trade!
.payInCurrency), .payInCurrency),
amount: model.sendAmount, amount: model.sendAmount,
address: address: model
model.trade!.payInAddress, .trade!.payInAddress,
trade: model.trade!, trade: model.trade!,
); );
}, },
@ -630,10 +670,12 @@ class _Step4ViewState extends ConsumerState<Step4View> {
}, },
style: Theme.of(context) style: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.getSecondaryEnabledButtonStyle(context), .getSecondaryEnabledButtonStyle(
context),
child: Text( child: Text(
buttonTitle, buttonTitle,
style: STextStyles.button(context).copyWith( style:
STextStyles.button(context).copyWith(
color: Theme.of(context) color: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.buttonTextSecondary, .buttonTextSecondary,
@ -652,6 +694,7 @@ class _Step4ViewState extends ConsumerState<Step4View> {
}, },
), ),
), ),
),
); );
} }
} }