From ae9c494bc017534bbdfd4f99bc20181f00766751 Mon Sep 17 00:00:00 2001 From: Patrick Niemeyer Date: Fri, 1 Mar 2024 09:50:51 -0600 Subject: [PATCH] gai: Move chain selector do account dialog. --- gai-frontend/lib/chat/chat.dart | 128 +++++++++--------- .../menu/orchid_chain_selector_menu.dart | 20 +-- .../lib/orchid/menu/orchid_selector_menu.dart | 8 +- 3 files changed, 84 insertions(+), 72 deletions(-) diff --git a/gai-frontend/lib/chat/chat.dart b/gai-frontend/lib/chat/chat.dart index bc760b7cb..ac827bf8b 100644 --- a/gai-frontend/lib/chat/chat.dart +++ b/gai-frontend/lib/chat/chat.dart @@ -187,51 +187,72 @@ class _ChatViewState extends State { // Width here is effectively a max width and prevents dialog resizing width: 500, child: IntrinsicHeight( - child: OrchidTitledPanel( - highlight: false, - opaque: true, - titleText: "Set your Orchid account", - onDismiss: () { - Navigator.pop(context); - }, - body: Column( - children: [ - // Funder field - OrchidLabeledAddressField( - label: 'Funder Address', - onChange: (EthereumAddress? s) { - setState(() { - _funder = s; - }); - _accountChanged(); - }, - controller: _funderFieldController, - ), - // Signer field - OrchidLabeledTextField( - label: 'Signer Key', - controller: _signerFieldController, - hintText: '0x...', - onChanged: (String s) { - setState(() { - try { - _signerKey = BigInt.parse(s); - } catch (e) { - _signerKey = null; - } - }); - _accountChanged(); + child: ListenableBuilder( + listenable: _accountDetailNotifier, + builder: (context, child) { + return OrchidTitledPanel( + highlight: false, + opaque: true, + titleText: "Set your Orchid account", + onDismiss: () { + Navigator.pop(context); }, - ).top(16), - // Account card - ListenableBuilder( - listenable: _accountDetailNotifier, - builder: (context, child) { - return AccountCard(accountDetail: _accountDetail).top(20); - }), - ], - ).pad(24), - ), + body: Column( + children: [ + // Chain selector + Row( + children: [ + SizedBox( + height: 40, + width: 190, + child: OrchidChainSelectorMenu( + backgroundColor: OrchidColors.new_purple, + selected: _selectedChain, + onSelection: (chain) { + setState(() { + _selectedChain = chain; + }); + _accountChanged(); + }, + enabled: true, + ), + ), + ], + ), + + // Funder field + OrchidLabeledAddressField( + label: 'Funder Address', + onChange: (EthereumAddress? s) { + setState(() { + _funder = s; + }); + _accountChanged(); + }, + controller: _funderFieldController, + ).top(16), + // Signer field + OrchidLabeledTextField( + label: 'Signer Key', + controller: _signerFieldController, + hintText: '0x...', + onChanged: (String s) { + setState(() { + try { + _signerKey = BigInt.parse(s); + } catch (e) { + _signerKey = null; + } + }); + _accountChanged(); + }, + ).top(16), + // Account card + AccountCard(accountDetail: _accountDetail).top(20), + ], + ).pad(24), + ); + }), ), ); } @@ -301,7 +322,7 @@ class _ChatViewState extends State { @override Widget build(BuildContext context) { - const minWidth = 550.0; + const minWidth = 500.0; var showIcons = AppSize(context).narrowerThanWidth(700); var showMinWidth = AppSize(context).narrowerThanWidth(minWidth); return Scaffold( @@ -367,23 +388,6 @@ class _ChatViewState extends State { children: [ SizedBox(height: 40, child: OrchidAsset.image.logo), const Spacer(), - // Chain selector - SizedBox( - height: 40, - width: showIcons ? 40 : 190, - child: OrchidChainSelectorMenu( - iconOnly: showIcons, - selected: _selectedChain, - onSelection: (chain) { - setState(() { - _selectedChain = chain; - }); - _accountChanged(); - }, - enabled: true, - ), - ).left(8), - // Connect button ChatButton( text: _connected ? 'Reroll' : 'Connect', diff --git a/gui-orchid/lib/orchid/menu/orchid_chain_selector_menu.dart b/gui-orchid/lib/orchid/menu/orchid_chain_selector_menu.dart index ea6919cd0..945c9ac55 100644 --- a/gui-orchid/lib/orchid/menu/orchid_chain_selector_menu.dart +++ b/gui-orchid/lib/orchid/menu/orchid_chain_selector_menu.dart @@ -17,14 +17,17 @@ class OrchidChainSelectorMenu extends StatelessWidget { final List chains = Chains.map.values.where((e) => e != Chains.GanacheTest).toList(); - OrchidChainSelectorMenu({ - Key? key, - this.selected, - required this.onSelection, - this.iconOnly = false, - this.enabled = true, - this.width = OrchidSelectorMenu.DEFAULT_WIDTH - }) : super(key: key); + final Color? backgroundColor; + + OrchidChainSelectorMenu( + {Key? key, + this.selected, + required this.onSelection, + this.iconOnly = false, + this.enabled = true, + this.width = OrchidSelectorMenu.DEFAULT_WIDTH, + this.backgroundColor}) + : super(key: key); @override Widget build(BuildContext context) { @@ -44,6 +47,7 @@ class OrchidChainSelectorMenu extends StatelessWidget { width: width, // support testing highlightSelected: selected?.isKnown ?? true, + backgroundColor: backgroundColor, ); } } diff --git a/gui-orchid/lib/orchid/menu/orchid_selector_menu.dart b/gui-orchid/lib/orchid/menu/orchid_selector_menu.dart index 5d23400e1..a18ac6974 100644 --- a/gui-orchid/lib/orchid/menu/orchid_selector_menu.dart +++ b/gui-orchid/lib/orchid/menu/orchid_selector_menu.dart @@ -26,10 +26,11 @@ class OrchidSelectorMenu extends StatefulWidget { // highlight the selected item in the menu final bool highlightSelected; + final Color? backgroundColor; static const double DEFAULT_WIDTH = 273.0; - OrchidSelectorMenu({ + const OrchidSelectorMenu({ Key? key, this.selected, this.onSelection, @@ -42,6 +43,7 @@ class OrchidSelectorMenu extends StatefulWidget { this.iconForItem, required this.titleForItem, this.highlightSelected = true, + this.backgroundColor, }) : super(key: key); @override @@ -58,6 +60,7 @@ class _OrchidSelectorMenuState extends State> { Widget build(BuildContext context) { return OrchidPopupMenuButton( // disabledAppearance: !widget.enabled, + backgroundColor: widget.backgroundColor, width: _width, height: 40, selected: _menuOpen, @@ -84,12 +87,13 @@ class _OrchidSelectorMenuState extends State> { } Widget _buildTitleUnselected(BuildContext context) { - if (widget.titleIconOnly) + if (widget.titleIconOnly) { return FittedBox( fit: BoxFit.scaleDown, child: SizedBox.square(dimension: 25, child: widget.titleIconUnselected), ); + } return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,