Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions apipod/apipod_server/lib/src/endpoints/nip05/nip05_endpoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,28 @@ class Nip05Endpoint extends Endpoint {

Future<NameCheckResult> checkName(
Session session,
String name,
String nameUser,
String domain,
) async {
final result = NameCheckResult(
isAvailable: false,
suggestions: [],
);

final cleanedName = nameUser.replaceAll(" ", "");

// Check if name is in disallowed list
if (disallowedWords.contains(name.toLowerCase())) {
if (disallowedWords.contains(cleanedName.toLowerCase())) {
result.reason = 'This name is not allowed';
// Generate suggestions
result.suggestions = generateSuggestions(name);
result.suggestions = generateSuggestions(cleanedName);
return result;
}

// Check if name exists in database
var existingName = await Nip05Data.db.findFirstRow(
final existingName = await Nip05Data.db.findFirstRow(
session,
where: (t) => t.name.equals(name) & t.domain.equals(domain),
where: (t) => t.name.equals(cleanedName) & t.domain.equals(domain),
);

if (existingName == null) {
Expand All @@ -73,7 +75,7 @@ class Nip05Endpoint extends Endpoint {
return result;
} else {
result.reason = 'This name is already taken';
result.suggestions = generateSuggestions(name);
result.suggestions = generateSuggestions(cleanedName);
return result;
}
}
Expand Down
104 changes: 104 additions & 0 deletions lib/presentation_layer/atoms/username_input.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import 'package:flutter/material.dart';

import '../../config/palette.dart';

class UsernameInputField extends StatefulWidget {
final String username;
final String domain;
final Widget? trailing;

final Function(String) onChange;

const UsernameInputField({
super.key,
required this.username,
required this.domain,
required this.onChange,
this.trailing,
});

@override
State<UsernameInputField> createState() => _UsernameInputFieldState();
}

class _UsernameInputFieldState extends State<UsernameInputField> {
final FocusNode _nameFocusNode = FocusNode();
final TextEditingController _nameController = TextEditingController();

@override
void initState() {
super.initState();
_nameController.text = widget.username;
}

@override
void dispose() {
_nameFocusNode.dispose();
_nameController.dispose();
super.dispose();
}

@override
void didUpdateWidget(UsernameInputField oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.username != oldWidget.username) {
_nameController.text = widget.username;
}
}

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20),
width: MediaQuery.of(context).size.width * 0.95,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: IntrinsicWidth(
child: TextField(
textAlign: TextAlign.left,
cursorRadius: const Radius.circular(50),
maxLines: 1,
textAlignVertical: TextAlignVertical.center,
autofocus: true,
focusNode: _nameFocusNode,
controller: _nameController,
autofillHints: const [AutofillHints.username],
decoration: const InputDecoration(
hintText: '_',
contentPadding: EdgeInsets.all(0),
hintStyle: TextStyle(
color: Palette.white,
letterSpacing: 1.1,
),
alignLabelWithHint: true,
border: InputBorder.none,
isDense: true,
),
onChanged: (value) {
widget.onChange(value);
},
style: const TextStyle(
color: Palette.lightGray,
letterSpacing: 1.1,
fontSize: 28,
),
),
),
),
Text(
widget.domain,
style: const TextStyle(
color: Palette.gray,
letterSpacing: 1.1,
fontSize: 28,
),
),
if (widget.trailing != null) widget.trailing!
],
),
);
}
}
10 changes: 9 additions & 1 deletion lib/presentation_layer/routes/nostr/onboarding/onboarding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'onboarding_page01.dart';
import 'onboarding_picture.dart';
import 'onboarding_profile.dart';
import 'onboarding_starter_pack.dart';
import 'onboarding_username.dart';

class NostrOnboarding extends ConsumerStatefulWidget {
const NostrOnboarding({
Expand Down Expand Up @@ -86,7 +87,7 @@ class _NostrOnboardingState extends ConsumerState<NostrOnboarding>
void initState() {
super.initState();
_tabController = TabController(
length: 6,
length: 7,
initialIndex: 0,
vsync: this,
);
Expand Down Expand Up @@ -176,6 +177,13 @@ class _NostrOnboardingState extends ConsumerState<NostrOnboarding>
_nextTab();
},
),
OnboardingUsername(
userInfo: signUpInfo,
submitCallback: (username) {
signUpInfo.nip05 = username;
_nextTab();
},
),
OnboardingPicture(
pictureCallback: () {
_nextTab();
Expand Down
Loading