mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-18 10:04:20 +01:00
simple support for nip07
This commit is contained in:
@@ -1,15 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/component/auth_dialog/auth_dialog_base_componnet.dart';
|
||||
import 'package:nowser/const/connect_type.dart';
|
||||
import 'package:nowser/const/reasonable_permissions.dart';
|
||||
import 'package:nowser/data/app_db.dart';
|
||||
import 'package:nowser/main.dart';
|
||||
import 'package:nowser/util/router_util.dart';
|
||||
|
||||
import '../../const/base.dart';
|
||||
import '../../data/app.dart';
|
||||
|
||||
class AuthAppConnectDialog extends StatefulWidget {
|
||||
static void show(BuildContext context) {
|
||||
showDialog(
|
||||
App app;
|
||||
|
||||
AuthAppConnectDialog({required this.app});
|
||||
|
||||
static Future<App?> show(BuildContext context, App app) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AuthAppConnectDialog();
|
||||
return AuthAppConnectDialog(
|
||||
app: app,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -65,7 +77,12 @@ class _AuthAppConnectDialog extends State<AuthAppConnectDialog> {
|
||||
children: list,
|
||||
);
|
||||
|
||||
return AuthDialogBaseComponnet(title: "App Connect", child: child);
|
||||
return AuthDialogBaseComponnet(
|
||||
app: widget.app,
|
||||
title: "App Connect",
|
||||
onConfirm: onConfirm,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
void onConnectTypeChange(int? value) {
|
||||
@@ -75,4 +92,22 @@ class _AuthAppConnectDialog extends State<AuthAppConnectDialog> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onConfirm() async {
|
||||
var app = widget.app;
|
||||
app.connectType = connectType;
|
||||
if (StringUtil.isBlank(app.pubkey) && keyProvider.pubkeys.isNotEmpty) {
|
||||
app.pubkey = keyProvider.pubkeys.first;
|
||||
}
|
||||
if (connectType == ConnectType.REASONABLE) {
|
||||
app.alwaysAllow = ReasonablePermissions.text;
|
||||
}
|
||||
app.createdAt = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
app.updatedAt = app.createdAt;
|
||||
|
||||
if (await AppDB.insert(app) > 0) {
|
||||
await appProvider.reload();
|
||||
RouterUtil.back(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/const/app_type.dart';
|
||||
import 'package:nowser/const/base.dart';
|
||||
import 'package:nowser/data/app.dart';
|
||||
|
||||
import '../app/app_type_component.dart';
|
||||
|
||||
class AuthAppInfoComponent extends StatefulWidget {
|
||||
App app;
|
||||
|
||||
AuthAppInfoComponent({required this.app});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _AuthAppInfoComponent();
|
||||
@@ -16,6 +22,26 @@ class _AuthAppInfoComponent extends State<AuthAppInfoComponent> {
|
||||
Widget build(BuildContext context) {
|
||||
var themeData = Theme.of(context);
|
||||
|
||||
String? name;
|
||||
String? des;
|
||||
if (StringUtil.isNotBlank(widget.app.name)) {
|
||||
name = widget.app.name;
|
||||
des = widget.app.code;
|
||||
} else if (StringUtil.isBlank(widget.app.name)) {
|
||||
name = widget.app.code;
|
||||
}
|
||||
|
||||
List<Widget> rightList = [];
|
||||
if (StringUtil.isNotBlank(name)) {
|
||||
rightList.add(Text(
|
||||
name!,
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
));
|
||||
}
|
||||
if (StringUtil.isNotBlank(des)) {
|
||||
rightList.add(Text(des!));
|
||||
}
|
||||
|
||||
return Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
@@ -24,12 +50,13 @@ class _AuthAppInfoComponent extends State<AuthAppInfoComponent> {
|
||||
height: 64,
|
||||
child: Card(
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(Base.BASE_PADDING_HALF),
|
||||
padding: const EdgeInsets.all(Base.BASE_PADDING_HALF),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(right: Base.BASE_PADDING_HALF),
|
||||
margin:
|
||||
const EdgeInsets.only(right: Base.BASE_PADDING_HALF),
|
||||
child: Icon(
|
||||
Icons.image,
|
||||
size: 46,
|
||||
@@ -38,13 +65,7 @@ class _AuthAppInfoComponent extends State<AuthAppInfoComponent> {
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"APP NAME",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text("This is App info des"),
|
||||
],
|
||||
children: rightList,
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,14 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/component/auth_dialog/auth_dialog_base_componnet.dart';
|
||||
import 'package:nowser/const/auth_result.dart';
|
||||
import 'package:nowser/data/app.dart';
|
||||
import 'package:nowser/util/router_util.dart';
|
||||
|
||||
import '../../const/base.dart';
|
||||
|
||||
class AuthDialog extends StatefulWidget {
|
||||
static void show(BuildContext context) {
|
||||
showDialog(
|
||||
App app;
|
||||
|
||||
int authType;
|
||||
|
||||
int? eventKind;
|
||||
|
||||
String? authDetail;
|
||||
|
||||
AuthDialog({
|
||||
required this.app,
|
||||
required this.authType,
|
||||
this.eventKind,
|
||||
this.authDetail,
|
||||
});
|
||||
|
||||
static Future<int?> show(BuildContext context, App app, int authType,
|
||||
{int? eventKind, String? authDetail}) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AuthDialog();
|
||||
return AuthDialog(
|
||||
app: app,
|
||||
authType: authType,
|
||||
eventKind: eventKind,
|
||||
authDetail: authDetail,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -31,49 +56,54 @@ class _AuthDialog extends State<AuthDialog> {
|
||||
);
|
||||
var hintColor = themeData.hintColor;
|
||||
|
||||
// handle this title and des with widget.authType
|
||||
String authTitle = "Sign Event";
|
||||
String authDes = "Allow web.nostrmo.com to sign a authenticate event";
|
||||
authTitle = "AuthType ${widget.authType}";
|
||||
|
||||
List<Widget> list = [];
|
||||
list.add(Container(
|
||||
margin: baseMargin,
|
||||
child: Text(
|
||||
"Allow web.nostrmo.com to sign a authenticate event",
|
||||
authDes,
|
||||
),
|
||||
));
|
||||
|
||||
var showDetailWidget = GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
showDetail = !showDetail;
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text("detail"),
|
||||
showDetail ? Icon(Icons.expand_less) : Icon(Icons.expand_more),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
List<Widget> detailList = [];
|
||||
if (showDetail) {
|
||||
if (StringUtil.isNotBlank(widget.authDetail)) {
|
||||
var showDetailWidget = GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
showDetail = !showDetail;
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text("detail"),
|
||||
showDetail ? Icon(Icons.expand_less) : Icon(Icons.expand_more),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (showDetail) {
|
||||
detailList.add(Container(
|
||||
height: 210,
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(Base.BASE_PADDING_HALF),
|
||||
decoration: BoxDecoration(
|
||||
color: hintColor.withOpacity(0.3),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Text(widget.authDetail!),
|
||||
),
|
||||
));
|
||||
} else {}
|
||||
detailList.add(Container(
|
||||
height: 210,
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(Base.BASE_PADDING_HALF),
|
||||
decoration: BoxDecoration(
|
||||
color: hintColor.withOpacity(0.3),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Text(
|
||||
"GoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGoodGood"),
|
||||
),
|
||||
margin: baseMargin,
|
||||
child: showDetailWidget,
|
||||
));
|
||||
} else {}
|
||||
detailList.add(Container(
|
||||
margin: baseMargin,
|
||||
child: showDetailWidget,
|
||||
));
|
||||
}
|
||||
|
||||
list.add(Container(
|
||||
height: 250,
|
||||
@@ -90,6 +120,16 @@ class _AuthDialog extends State<AuthDialog> {
|
||||
children: list,
|
||||
);
|
||||
|
||||
return AuthDialogBaseComponnet(title: "Sign Event", child: child);
|
||||
return AuthDialogBaseComponnet(
|
||||
app: widget.app,
|
||||
title: authTitle,
|
||||
onConfirm: onConfirm,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
onConfirm() {
|
||||
print("auth dialog confirm!");
|
||||
RouterUtil.back(context, AuthResult.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/nip19/nip19.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/const/base.dart';
|
||||
import 'package:nowser/data/app.dart';
|
||||
import 'package:nowser/provider/key_provider.dart';
|
||||
import 'package:nowser/util/router_util.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../logo_component.dart';
|
||||
import 'auth_app_info_component.dart';
|
||||
|
||||
class AuthDialogBaseComponnet extends StatefulWidget {
|
||||
App app;
|
||||
|
||||
String title;
|
||||
|
||||
Widget child;
|
||||
|
||||
AuthDialogBaseComponnet({required this.title, required this.child});
|
||||
Function onConfirm;
|
||||
|
||||
Function(String)? onPubkeyChange;
|
||||
|
||||
AuthDialogBaseComponnet({
|
||||
required this.app,
|
||||
required this.title,
|
||||
required this.child,
|
||||
required this.onConfirm,
|
||||
this.onPubkeyChange,
|
||||
});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@@ -30,11 +47,43 @@ class _AuthDialog extends State<AuthDialogBaseComponnet> {
|
||||
|
||||
List<Widget> list = [];
|
||||
|
||||
var keyWidget =
|
||||
Selector<KeyProvider, List<String>>(builder: (context, pubkeys, child) {
|
||||
List<DropdownMenuItem<String>> items = [];
|
||||
for (var pubkey in pubkeys) {
|
||||
items.add(DropdownMenuItem(
|
||||
value: pubkey,
|
||||
child: Text(
|
||||
Nip19.encodePubKey(pubkey),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
if (StringUtil.isBlank(widget.app.pubkey) && pubkeys.isNotEmpty) {
|
||||
widget.app.pubkey = pubkeys.first;
|
||||
}
|
||||
|
||||
return DropdownButton<String>(
|
||||
items: items,
|
||||
onChanged: (String? value) {
|
||||
if (StringUtil.isNotBlank(value)) {
|
||||
widget.app.pubkey = value;
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
value: widget.app.pubkey,
|
||||
);
|
||||
}, selector: (context, provider) {
|
||||
return provider.pubkeys;
|
||||
});
|
||||
|
||||
var topWidget = Container(
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(
|
||||
margin: const EdgeInsets.only(
|
||||
left: Base.BASE_PADDING,
|
||||
right: Base.BASE_PADDING,
|
||||
top: Base.BASE_PADDING_HALF,
|
||||
@@ -46,16 +95,7 @@ class _AuthDialog extends State<AuthDialogBaseComponnet> {
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(right: Base.BASE_PADDING_HALF),
|
||||
alignment: Alignment.centerRight,
|
||||
child: DropdownButton<String>(
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
child: Text("npubxxxxxx"),
|
||||
value: "npubxxxxxx",
|
||||
)
|
||||
],
|
||||
onChanged: (Object? value) {},
|
||||
value: "npubxxxxxx",
|
||||
),
|
||||
child: keyWidget,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -76,7 +116,9 @@ class _AuthDialog extends State<AuthDialogBaseComponnet> {
|
||||
|
||||
list.add(Container(
|
||||
margin: baseMargin,
|
||||
child: AuthAppInfoComponent(),
|
||||
child: AuthAppInfoComponent(
|
||||
app: widget.app,
|
||||
),
|
||||
));
|
||||
|
||||
list.add(Container(
|
||||
@@ -112,7 +154,12 @@ class _AuthDialog extends State<AuthDialogBaseComponnet> {
|
||||
margin: EdgeInsets.only(
|
||||
left: Base.BASE_PADDING_HALF,
|
||||
),
|
||||
child: FilledButton(onPressed: () {}, child: Text("Confirm")),
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
widget.onConfirm();
|
||||
},
|
||||
child: Text("Confirm"),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user