Merge branch 'spike/block2-derisking'

This commit is contained in:
vjrj 2026-07-10 12:42:33 +02:00
commit 1750f3fa97
22 changed files with 576 additions and 16 deletions

View file

@ -41,18 +41,27 @@ class AppDrawer extends StatelessWidget {
onTap: marketEnabled
? () {
Navigator.of(context).pop();
context.go('/market');
context.push('/market');
}
: null,
),
_DrawerItem(
icon: const Icon(Icons.person),
label: t.menu.profile,
onTap: marketEnabled
? () {
Navigator.of(context).pop();
context.push('/profile');
}
: null,
),
_DrawerItem(icon: const Icon(Icons.person), label: t.menu.profile),
_DrawerItem(
icon: const Icon(Icons.chat_bubble),
label: t.menu.chat,
onTap: marketEnabled
? () {
Navigator.of(context).pop();
context.go('/messages');
context.push('/messages');
}
: null,
),

View file

@ -65,7 +65,7 @@ class _ChatListScreenState extends State<ChatListScreen> {
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
onTap: () => context.go('/chat/${c.peerPubkey}'),
onTap: () => context.push('/chat/${c.peerPubkey}'),
);
},
),

View file

@ -87,7 +87,7 @@ class HomeScreen extends StatelessWidget {
subtitle: t.home.openMarketSubtitle,
tag: marketEnabled ? null : t.common.comingSoon,
onTap: marketEnabled
? () => context.go('/market')
? () => context.push('/market')
: null,
),
],

View file

@ -148,13 +148,6 @@ class _MarketScreenState extends State<MarketScreen> {
appBar: AppBar(
title: Text(t.market.title),
actions: [
if (cubit != null && (cubit.isOnline || widget.outbox != null))
IconButton(
key: const Key('market.shareMine'),
icon: const Icon(Icons.ios_share_outlined),
tooltip: t.market.shareMine,
onPressed: _shareMine,
),
IconButton(
key: const Key('market.config'),
icon: const Icon(Icons.tune),
@ -163,6 +156,15 @@ class _MarketScreenState extends State<MarketScreen> {
),
],
),
floatingActionButton:
cubit != null && (cubit.isOnline || widget.outbox != null)
? FloatingActionButton.extended(
key: const Key('market.shareMine'),
onPressed: _shareMine,
icon: const Icon(Icons.campaign_outlined),
label: Text(t.market.shareMine),
)
: null,
body: _loading || cubit == null
? const Center(child: CircularProgressIndicator())
: BlocProvider.value(
@ -232,7 +234,7 @@ class MarketBody extends StatelessWidget {
return _OfferCard(
offer: o,
mine: mine,
onContact: mine ? null : () => context.go('/chat/${o.authorPubkeyHex}'),
onContact: mine ? null : () => context.push('/chat/${o.authorPubkeyHex}'),
);
},
);

View file

@ -0,0 +1,190 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../i18n/strings.g.dart';
import '../services/profile_store.dart';
import '../services/social_service.dart';
import '../services/social_settings.dart';
import 'theme.dart';
/// Your own profile: the shareable identity (npub) plus a display name and short
/// "about" others see instead of a raw key. Saving persists locally and, when
/// online, publishes NIP-01 kind:0 metadata so peers can recognise you.
class ProfileScreen extends StatefulWidget {
const ProfileScreen({
required this.social,
required this.settings,
required this.profileStore,
super.key,
});
final SocialService social;
final SocialSettings settings;
final ProfileStore profileStore;
@override
State<ProfileScreen> createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
final _name = TextEditingController();
final _about = TextEditingController();
bool _loading = true;
bool _saving = false;
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
_name.text = await widget.profileStore.name();
_about.text = await widget.profileStore.about();
if (mounted) setState(() => _loading = false);
}
Future<void> _copyId() async {
final messenger = ScaffoldMessenger.of(context);
final t = context.t;
await Clipboard.setData(ClipboardData(text: widget.social.npub));
if (!mounted) return;
messenger.showSnackBar(SnackBar(content: Text(t.profile.copied)));
}
Future<void> _save() async {
final messenger = ScaffoldMessenger.of(context);
final t = context.t;
setState(() => _saving = true);
await widget.profileStore.save(name: _name.text, about: _about.text);
// Best-effort publish to the network so peers see the name.
final relays = await widget.settings.relayUrls();
if (relays.isNotEmpty) {
try {
final session = await widget.social.openSession(relays);
await session.profile.publish(
name: _name.text.trim(),
about: _about.text.trim(),
);
await session.close();
} catch (_) {
// offline / unreachable the local copy is saved regardless.
}
}
if (!mounted) return;
setState(() => _saving = false);
messenger.showSnackBar(SnackBar(content: Text(t.profile.saved)));
}
@override
void dispose() {
_name.dispose();
_about.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final t = context.t;
return Scaffold(
appBar: AppBar(title: Text(t.profile.title)),
body: _loading
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(20),
children: [
_IdentityCard(npub: widget.social.npub, onCopy: _copyId),
const SizedBox(height: 24),
TextField(
key: const Key('profile.name'),
controller: _name,
decoration: InputDecoration(
labelText: t.profile.name,
helperText: t.profile.nameHint,
),
),
const SizedBox(height: 16),
TextField(
key: const Key('profile.about'),
controller: _about,
minLines: 2,
maxLines: 4,
decoration: InputDecoration(
labelText: t.profile.about,
helperText: t.profile.aboutHint,
),
),
const SizedBox(height: 24),
FilledButton(
key: const Key('profile.save'),
onPressed: _saving ? null : _save,
child: _saving
? const SizedBox(
height: 18,
width: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
: Text(t.profile.save),
),
],
),
);
}
}
class _IdentityCard extends StatelessWidget {
const _IdentityCard({required this.npub, required this.onCopy});
final String npub;
final VoidCallback onCopy;
@override
Widget build(BuildContext context) {
final t = context.t;
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: seedPrimaryContainer.withValues(alpha: 0.4),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: seedOutline),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
t.profile.yourId,
style: const TextStyle(
fontWeight: FontWeight.w600,
color: seedOnSurface,
),
),
const SizedBox(height: 4),
Text(
t.profile.idHelp,
style: const TextStyle(color: seedMuted, fontSize: 12),
),
const SizedBox(height: 10),
SelectableText(
npub,
style: const TextStyle(
fontFamily: 'monospace',
fontSize: 12,
color: seedOnSurface,
),
),
const SizedBox(height: 8),
Align(
alignment: AlignmentDirectional.centerEnd,
child: TextButton.icon(
key: const Key('profile.copyId'),
onPressed: onCopy,
icon: const Icon(Icons.copy, size: 16),
label: Text(t.profile.copy),
),
),
],
),
);
}
}