Skip to content

Commit

Permalink
gai: Move chain selector do account dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
patniemeyer committed Mar 1, 2024
1 parent afcfcae commit ae9c494
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 72 deletions.
128 changes: 66 additions & 62 deletions gai-frontend/lib/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,51 +187,72 @@ class _ChatViewState extends State<ChatView> {
// 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),
);
}),
),
);
}
Expand Down Expand Up @@ -301,7 +322,7 @@ class _ChatViewState extends State<ChatView> {

@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(
Expand Down Expand Up @@ -367,23 +388,6 @@ class _ChatViewState extends State<ChatView> {
children: <Widget>[
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',
Expand Down
20 changes: 12 additions & 8 deletions gui-orchid/lib/orchid/menu/orchid_chain_selector_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ class OrchidChainSelectorMenu extends StatelessWidget {
final List<Chain> 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) {
Expand All @@ -44,6 +47,7 @@ class OrchidChainSelectorMenu extends StatelessWidget {
width: width,
// support testing
highlightSelected: selected?.isKnown ?? true,
backgroundColor: backgroundColor,
);
}
}
8 changes: 6 additions & 2 deletions gui-orchid/lib/orchid/menu/orchid_selector_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ class OrchidSelectorMenu<T> 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,
Expand All @@ -42,6 +43,7 @@ class OrchidSelectorMenu<T> extends StatefulWidget {
this.iconForItem,
required this.titleForItem,
this.highlightSelected = true,
this.backgroundColor,
}) : super(key: key);

@override
Expand All @@ -58,6 +60,7 @@ class _OrchidSelectorMenuState<T> extends State<OrchidSelectorMenu<T>> {
Widget build(BuildContext context) {
return OrchidPopupMenuButton<T>(
// disabledAppearance: !widget.enabled,
backgroundColor: widget.backgroundColor,
width: _width,
height: 40,
selected: _menuOpen,
Expand All @@ -84,12 +87,13 @@ class _OrchidSelectorMenuState<T> extends State<OrchidSelectorMenu<T>> {
}

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,
Expand Down

0 comments on commit ae9c494

Please sign in to comment.