add coin as arg to BuyInWalletView->BuyView->BuyForm

This commit is contained in:
sneurlax 2023-01-27 13:47:41 -06:00
parent 79e1bbf13b
commit 6b6ef179cc
5 changed files with 38 additions and 7 deletions

View file

@ -48,10 +48,13 @@ import 'package:stackwallet/widgets/textfield_icon_button.dart';
class BuyForm extends ConsumerStatefulWidget { class BuyForm extends ConsumerStatefulWidget {
const BuyForm({ const BuyForm({
Key? key, Key? key,
this.coin,
this.clipboard = const ClipboardWrapper(), this.clipboard = const ClipboardWrapper(),
this.scanner = const BarcodeScannerWrapper(), this.scanner = const BarcodeScannerWrapper(),
}) : super(key: key); }) : super(key: key);
final Coin? coin;
final ClipboardInterface clipboard; final ClipboardInterface clipboard;
final BarcodeScannerInterface scanner; final BarcodeScannerInterface scanner;
@ -60,6 +63,8 @@ class BuyForm extends ConsumerStatefulWidget {
} }
class _BuyFormState extends ConsumerState<BuyForm> { class _BuyFormState extends ConsumerState<BuyForm> {
late final Coin? coin;
late final ClipboardInterface clipboard; late final ClipboardInterface clipboard;
late final BarcodeScannerInterface scanner; late final BarcodeScannerInterface scanner;
@ -701,7 +706,10 @@ class _BuyFormState extends ConsumerState<BuyForm> {
// TODO set defaults better; should probably explicitly enumerate the coins & fiats used and pull the specific ones we need rather than generating them as defaults here // TODO set defaults better; should probably explicitly enumerate the coins & fiats used and pull the specific ones we need rather than generating them as defaults here
selectedFiat = selectedFiat =
Fiat.fromJson({'ticker': 'USD', 'name': 'United States Dollar'}); Fiat.fromJson({'ticker': 'USD', 'name': 'United States Dollar'});
selectedCrypto = Crypto.fromJson({'ticker': 'BTC', 'name': 'Bitcoin'}); selectedCrypto = Crypto.fromJson({
'ticker': widget.coin?.ticker ?? 'BTC',
'name': widget.coin?.prettyName ?? 'Bitcoin'
});
// TODO set initial crypto to open wallet if a wallet is open // TODO set initial crypto to open wallet if a wallet is open

View file

@ -1,20 +1,28 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:stackwallet/pages/buy_view/buy_view.dart'; import 'package:stackwallet/pages/buy_view/buy_view.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
class BuyInWalletView extends StatefulWidget { class BuyInWalletView extends StatefulWidget {
const BuyInWalletView({Key? key}) : super(key: key); const BuyInWalletView({
Key? key,
required this.coin,
}) : super(key: key);
static const String routeName = "/stackBuyInWalletView"; static const String routeName = "/stackBuyInWalletView";
final Coin? coin;
@override @override
State<BuyInWalletView> createState() => _BuyInWalletViewState(); State<BuyInWalletView> createState() => _BuyInWalletViewState();
} }
class _BuyInWalletViewState extends State<BuyInWalletView> { class _BuyInWalletViewState extends State<BuyInWalletView> {
late final Coin? coin;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType"); debugPrint("BUILD: $runtimeType");
@ -33,7 +41,7 @@ class _BuyInWalletViewState extends State<BuyInWalletView> {
style: STextStyles.navBarTitle(context), style: STextStyles.navBarTitle(context),
), ),
), ),
body: const BuyView(), body: BuyView(coin: widget.coin),
), ),
); );
} }

View file

@ -1,16 +1,24 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:stackwallet/pages/buy_view/buy_form.dart'; import 'package:stackwallet/pages/buy_view/buy_form.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
class BuyView extends StatefulWidget { class BuyView extends StatefulWidget {
const BuyView({Key? key}) : super(key: key); const BuyView({
Key? key,
this.coin,
}) : super(key: key);
static const String routeName = "/stackBuyView"; static const String routeName = "/stackBuyView";
final Coin? coin;
@override @override
State<BuyView> createState() => _BuyViewState(); State<BuyView> createState() => _BuyViewState();
} }
class _BuyViewState extends State<BuyView> { class _BuyViewState extends State<BuyView> {
late final Coin? coin;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType"); debugPrint("BUILD: $runtimeType");

View file

@ -779,6 +779,7 @@ class _WalletViewState extends ConsumerState<WalletView> {
unawaited(Navigator.of(context).pushNamed( unawaited(Navigator.of(context).pushNamed(
BuyInWalletView.routeName, BuyInWalletView.routeName,
arguments: coin,
)); ));
}, },
), ),

View file

@ -1134,10 +1134,16 @@ class RouteGenerator {
settings: RouteSettings(name: settings.name)); settings: RouteSettings(name: settings.name));
case BuyInWalletView.routeName: case BuyInWalletView.routeName:
if (args is Coin) {
return getRoute( return getRoute(
shouldUseMaterialRoute: useMaterialPageRoute, shouldUseMaterialRoute: useMaterialPageRoute,
builder: (_) => const BuyInWalletView(), builder: (_) => BuyInWalletView(coin: args),
settings: RouteSettings(name: settings.name)); settings: RouteSettings(
name: settings.name,
),
);
}
return _routeError("${settings.name} invalid args: ${args.toString()}");
case DesktopBuyView.routeName: case DesktopBuyView.routeName:
return getRoute( return getRoute(