diff --git a/lib/component/auth_dialog/auth_app_connect_dialog.dart b/lib/component/auth_dialog/auth_app_connect_dialog.dart new file mode 100644 index 0000000..a390ce3 --- /dev/null +++ b/lib/component/auth_dialog/auth_app_connect_dialog.dart @@ -0,0 +1,78 @@ +import 'package:flutter/material.dart'; +import 'package:nowser/component/auth_dialog/auth_dialog_base_componnet.dart'; +import 'package:nowser/const/connect_type.dart'; + +import '../../const/base.dart'; + +class AuthAppConnectDialog extends StatefulWidget { + static void show(BuildContext context) { + showDialog( + context: context, + builder: (context) { + return AuthAppConnectDialog(); + }, + ); + } + + @override + State createState() { + return _AuthAppConnectDialog(); + } +} + +class _AuthAppConnectDialog extends State { + int connectType = ConnectType.REASONABLE; + + bool showDetail = false; + + @override + Widget build(BuildContext context) { + var themeData = Theme.of(context); + var baseMargin = EdgeInsets.only( + top: Base.BASE_PADDING_HALF, + bottom: Base.BASE_PADDING_HALF, + ); + var hintColor = themeData.hintColor; + + List list = []; + + list.add(RadioListTile( + value: ConnectType.FULLY_TRUST, + groupValue: connectType, + onChanged: onConnectTypeChange, + title: Text("I fully trust it"), + subtitle: Text("Auto-sign all requests (except payments)"), + )); + + list.add(RadioListTile( + value: ConnectType.REASONABLE, + groupValue: connectType, + onChanged: onConnectTypeChange, + title: Text("Let's be reasonable"), + subtitle: Text("Auto-approve most common requests"), + )); + + list.add(RadioListTile( + value: ConnectType.ALWAY_REJECT, + groupValue: connectType, + onChanged: onConnectTypeChange, + title: Text("I'm a bit paranoid"), + subtitle: Text("Do not sign anything without asking me!"), + )); + + var child = Column( + mainAxisSize: MainAxisSize.min, + children: list, + ); + + return AuthDialogBaseComponnet(title: "App Connect", child: child); + } + + void onConnectTypeChange(int? value) { + if (value != null) { + setState(() { + connectType = value; + }); + } + } +} diff --git a/lib/component/auth_dialog/auth_dialog.dart b/lib/component/auth_dialog/auth_dialog.dart index 566b828..6cf3ab7 100644 --- a/lib/component/auth_dialog/auth_dialog.dart +++ b/lib/component/auth_dialog/auth_dialog.dart @@ -1,8 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:nowser/const/base.dart'; +import 'package:nowser/component/auth_dialog/auth_dialog_base_componnet.dart'; -import '../logo_component.dart'; -import 'auth_app_info_component.dart'; +import '../../const/base.dart'; class AuthDialog extends StatefulWidget { static void show(BuildContext context) { @@ -33,56 +32,6 @@ class _AuthDialog extends State { var hintColor = themeData.hintColor; List list = []; - - var topWidget = Container( - child: Row( - children: [ - Container( - margin: EdgeInsets.only( - left: Base.BASE_PADDING, - right: Base.BASE_PADDING, - top: Base.BASE_PADDING_HALF, - bottom: Base.BASE_PADDING_HALF, - ), - child: LogoComponent(), - ), - Expanded( - child: Container( - margin: EdgeInsets.only(right: Base.BASE_PADDING_HALF), - alignment: Alignment.centerRight, - child: DropdownButton( - items: [ - DropdownMenuItem( - child: Text("npubxxxxxx"), - value: "npubxxxxxx", - ) - ], - onChanged: (Object? value) {}, - value: "npubxxxxxx", - ), - ), - ), - ], - ), - ); - - list.add(Container( - alignment: Alignment.center, - margin: baseMargin, - child: Text( - "Action Title", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: themeData.textTheme.bodyLarge!.fontSize, - ), - ), - )); - - list.add(Container( - margin: baseMargin, - child: AuthAppInfoComponent(), - )); - list.add(Container( margin: baseMargin, child: Text( @@ -136,58 +85,11 @@ class _AuthDialog extends State { ), )); - list.add(Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - // FilledButton(onPressed: () {}, child: Text("Cancel")), - // OutlinedButton( - // onPressed: () {}, - // child: Text( - // "Cancel", - // style: TextStyle( - // color: Colors.red, - // ), - // ), - // style: , - // ), - FilledButton( - onPressed: () {}, - child: Text("Cancel"), - style: ButtonStyle( - backgroundColor: WidgetStateProperty.all(Colors.red), - ), - ), - Container( - margin: EdgeInsets.only( - left: Base.BASE_PADDING_HALF, - ), - child: FilledButton(onPressed: () {}, child: Text("Confirm")), - ) - ], - ), - )); - - return Dialog( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - padding: const EdgeInsets.all(Base.BASE_PADDING), - decoration: BoxDecoration( - border: Border( - bottom: BorderSide(color: hintColor.withOpacity(0.3)))), - child: topWidget, - ), - Container( - padding: EdgeInsets.all(Base.BASE_PADDING), - child: Column( - mainAxisSize: MainAxisSize.min, - children: list, - ), - ), - ], - ), + var child = Column( + mainAxisSize: MainAxisSize.min, + children: list, ); + + return AuthDialogBaseComponnet(title: "Sign Event", child: child); } } diff --git a/lib/component/auth_dialog/auth_dialog_base_componnet.dart b/lib/component/auth_dialog/auth_dialog_base_componnet.dart new file mode 100644 index 0000000..ccf2123 --- /dev/null +++ b/lib/component/auth_dialog/auth_dialog_base_componnet.dart @@ -0,0 +1,143 @@ +import 'package:flutter/material.dart'; +import 'package:nowser/const/base.dart'; +import 'package:nowser/util/router_util.dart'; + +import '../logo_component.dart'; +import 'auth_app_info_component.dart'; + +class AuthDialogBaseComponnet extends StatefulWidget { + String title; + + Widget child; + + AuthDialogBaseComponnet({required this.title, required this.child}); + + @override + State createState() { + return _AuthDialog(); + } +} + +class _AuthDialog extends State { + @override + Widget build(BuildContext context) { + var themeData = Theme.of(context); + var baseMargin = EdgeInsets.only( + top: Base.BASE_PADDING_HALF, + bottom: Base.BASE_PADDING_HALF, + ); + var hintColor = themeData.hintColor; + + List list = []; + + var topWidget = Container( + child: Row( + children: [ + Container( + margin: EdgeInsets.only( + left: Base.BASE_PADDING, + right: Base.BASE_PADDING, + top: Base.BASE_PADDING_HALF, + bottom: Base.BASE_PADDING_HALF, + ), + child: LogoComponent(), + ), + Expanded( + child: Container( + margin: EdgeInsets.only(right: Base.BASE_PADDING_HALF), + alignment: Alignment.centerRight, + child: DropdownButton( + items: [ + DropdownMenuItem( + child: Text("npubxxxxxx"), + value: "npubxxxxxx", + ) + ], + onChanged: (Object? value) {}, + value: "npubxxxxxx", + ), + ), + ), + ], + ), + ); + + list.add(Container( + alignment: Alignment.center, + margin: baseMargin, + child: Text( + widget.title, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: themeData.textTheme.bodyLarge!.fontSize, + ), + ), + )); + + list.add(Container( + margin: baseMargin, + child: AuthAppInfoComponent(), + )); + + list.add(Container( + margin: baseMargin, + child: widget.child, + )); + + list.add(Container( + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + // FilledButton(onPressed: () {}, child: Text("Cancel")), + // OutlinedButton( + // onPressed: () {}, + // child: Text( + // "Cancel", + // style: TextStyle( + // color: Colors.red, + // ), + // ), + // style: , + // ), + FilledButton( + onPressed: () { + RouterUtil.back(context); + }, + child: Text("Cancel"), + style: ButtonStyle( + backgroundColor: WidgetStateProperty.all(Colors.red), + ), + ), + Container( + margin: EdgeInsets.only( + left: Base.BASE_PADDING_HALF, + ), + child: FilledButton(onPressed: () {}, child: Text("Confirm")), + ) + ], + ), + )); + + return Dialog( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + padding: const EdgeInsets.all(Base.BASE_PADDING), + decoration: BoxDecoration( + border: Border( + bottom: BorderSide(color: hintColor.withOpacity(0.3)))), + child: topWidget, + ), + Container( + padding: EdgeInsets.all(Base.BASE_PADDING), + child: Column( + mainAxisSize: MainAxisSize.min, + children: list, + ), + ), + ], + ), + ); + } +} diff --git a/lib/component/webview/web_home_component.dart b/lib/component/webview/web_home_component.dart index d5f95f2..b747f82 100644 --- a/lib/component/webview/web_home_component.dart +++ b/lib/component/webview/web_home_component.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:nowser/component/auth_dialog/auth_app_connect_dialog.dart'; import 'package:nowser/component/auth_dialog/auth_dialog.dart'; +import 'package:nowser/component/auth_dialog/auth_dialog_base_componnet.dart'; import 'package:nowser/component/webview/web_info.dart'; import 'package:nowser/const/base.dart'; import 'package:nowser/main.dart'; @@ -63,6 +65,7 @@ class _WebHomeComponent extends State { }), wrapBottomBtn(const Icon(Icons.space_dashboard), onTap: () { AuthDialog.show(context); + // AuthAppConnectDialog.show(context); }), wrapBottomBtn(const Icon(Icons.segment), onTap: () { // AuthDialog.show(context); diff --git a/lib/const/connect_type.dart b/lib/const/connect_type.dart new file mode 100644 index 0000000..abb114e --- /dev/null +++ b/lib/const/connect_type.dart @@ -0,0 +1,7 @@ +class ConnectType { + static const int FULLY_TRUST = 1; + + static const int REASONABLE = 2; + + static const int ALWAY_REJECT = 3; +}