From b8105215e2942357689fa3ecf30f797db27e655f Mon Sep 17 00:00:00 2001 From: sneurlax Date: Sun, 29 Dec 2024 18:45:10 -0600 Subject: [PATCH] chore: pass walletId to views --- .../multisig_coordinator_view.dart | 93 ++++++++++++++++++- .../multisig_setup_view.dart | 3 + lib/route_generator.dart | 20 ++-- 3 files changed, 106 insertions(+), 10 deletions(-) diff --git a/lib/pages/wallet_view/multisig_coordinator_view/multisig_coordinator_view.dart b/lib/pages/wallet_view/multisig_coordinator_view/multisig_coordinator_view.dart index 41470a7fd..c6e2f51de 100644 --- a/lib/pages/wallet_view/multisig_coordinator_view/multisig_coordinator_view.dart +++ b/lib/pages/wallet_view/multisig_coordinator_view/multisig_coordinator_view.dart @@ -108,10 +108,12 @@ class MultisigCoordinatorState extends StateNotifier { class MultisigCoordinatorView extends ConsumerStatefulWidget { const MultisigCoordinatorView({ super.key, + required this.walletId, required this.totalCosigners, required this.threshold, }); + final String walletId; final int totalCosigners; final int threshold; @@ -254,13 +256,100 @@ class _MultisigSetupViewState extends ConsumerState { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - "Enter the extended public key (xpub) for each cosigner. " + "This is your extended public key (xpub) for each cosigner. " + "Share it with each participant.", + style: STextStyles.itemSubtitle(context), + ), + const SizedBox(height: 24), + + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "Your xpub", + style: STextStyles.w500_14(context).copyWith( + color: Theme.of(context) + .extension()! + .textDark3, + ), + ), + const SizedBox(height: 8), + Row( + children: [ + Expanded( + child: TextField( + controller: xpubControllers[0], + enabled: + false, // Make field non-interactive + decoration: InputDecoration( + hintText: "xpub...", + hintStyle: + STextStyles.fieldLabel(context), + filled: + true, // Add background to show disabled state + fillColor: Theme.of(context) + .extension()! + .textFieldDefaultBG, + ), + ), + ), + const SizedBox(width: 8), + SecondaryButton( + width: 44, + buttonHeight: ButtonHeight.xl, + icon: QrCodeIcon( + width: 20, + height: 20, + color: Theme.of(context) + .extension()! + .buttonTextSecondary, + ), + onPressed: () { + // TODO: Implement QR code scanning + }, + ), + const SizedBox(width: 8), + SecondaryButton( + width: 44, + buttonHeight: ButtonHeight.xl, + icon: CopyIcon( + width: 20, + height: 20, + color: Theme.of(context) + .extension()! + .buttonTextSecondary, + ), + onPressed: () async { + final data = await Clipboard.getData( + 'text/plain'); + if (data?.text != null) { + xpubControllers[0].text = data!.text!; + ref + .read( + multisigCoordinatorStateProvider + .notifier) + .addCosignerXpub(data.text!); + setState( + () {}); // Trigger rebuild to update button state. + } + }, + ), + ], + ), + ], + ), + ), + + Text( + "Enter the extended public key (xpub) for each cosigner. " "These can be obtained from each participant's wallet.", style: STextStyles.itemSubtitle(context), ), const SizedBox(height: 24), - // Generate input fields for each cosigner + // Generate input fields for each cosigner. for (int i = 0; i < widget.totalCosigners; i++) Padding( padding: const EdgeInsets.only(bottom: 16), diff --git a/lib/pages/wallet_view/multisig_coordinator_view/multisig_setup_view.dart b/lib/pages/wallet_view/multisig_coordinator_view/multisig_setup_view.dart index d60e0c810..ece7cf249 100644 --- a/lib/pages/wallet_view/multisig_coordinator_view/multisig_setup_view.dart +++ b/lib/pages/wallet_view/multisig_coordinator_view/multisig_setup_view.dart @@ -111,10 +111,12 @@ class MultisigSetupState extends StateNotifier { class MultisigSetupView extends ConsumerStatefulWidget { const MultisigSetupView({ super.key, + required this.walletId, this.totalCosigners, this.threshold, }); + final String walletId; final int? totalCosigners; final int? threshold; @@ -528,6 +530,7 @@ class _MultisigSetupViewState extends ConsumerState { await Navigator.of(context).push( MaterialPageRoute( builder: (context) => MultisigCoordinatorView( + walletId: widget.walletId, totalCosigners: int.parse(_participantsController.text), threshold: int.parse(_thresholdController.text), diff --git a/lib/route_generator.dart b/lib/route_generator.dart index af82121b2..bb6bfa7f3 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -2158,21 +2158,24 @@ class RouteGenerator { return _routeError("${settings.name} invalid args: ${args.toString()}"); case MultisigSetupView.routeName: - if (args is Tuple2) { + if (args is Tuple3) { return getRoute( shouldUseMaterialRoute: useMaterialPageRoute, builder: (_) => MultisigSetupView( - totalCosigners: args.item1, - threshold: args.item2, + walletId: args.item1, + totalCosigners: args.item2, + threshold: args.item3, ), settings: RouteSettings( name: settings.name, ), ); - } else { + } else if (args is String) { return getRoute( shouldUseMaterialRoute: useMaterialPageRoute, - builder: (_) => const MultisigSetupView(), + builder: (_) => MultisigSetupView( + walletId: args, + ), settings: RouteSettings( name: settings.name, ), @@ -2181,12 +2184,13 @@ class RouteGenerator { return _routeError("${settings.name} invalid args: ${args.toString()}"); case MultisigCoordinatorView.routeName: - if (args is Tuple2) { + if (args is Tuple3) { return getRoute( shouldUseMaterialRoute: useMaterialPageRoute, builder: (_) => MultisigCoordinatorView( - totalCosigners: args.item1, - threshold: args.item2, + walletId: args.item1, + totalCosigners: args.item2, + threshold: args.item3, ), settings: RouteSettings( name: settings.name,