The optional Ğ1 (free currency) integration, per g1-integration.md. - Profile: an optional 'Ğ1 address' field, persisted locally and published in your NIP-01 kind:0 metadata (separate from the Nostr key). - commons_core: UserProfile/ProfileTransport carry a 'g1' field (round-trip tested). - Chat: when the peer published a Ğ1 address, a 'Pay in Ğ1' app-bar action opens their wallet (url_launcher) so value moves in the wallet, not the app — copies the address as a fallback. No payment rails in-app (sharing-model §4.3). NOTE (vjrj): the wallet deep-link uses the Cesium web wallet as a universal fallback; swap the URI in chat_screen._payG1 for the Ğ1nkgo/Ğecko scheme you prefer. Analyzer clean (both packages); profile transport test covers g1.
208 lines
6.3 KiB
Dart
208 lines
6.3 KiB
Dart
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 'qr_view.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();
|
|
final _g1 = 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();
|
|
_g1.text = await widget.profileStore.g1();
|
|
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, g1: _g1.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(),
|
|
g1: _g1.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();
|
|
_g1.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: 16),
|
|
TextField(
|
|
key: const Key('profile.g1'),
|
|
controller: _g1,
|
|
decoration: InputDecoration(
|
|
labelText: t.profile.g1,
|
|
helperText: t.profile.g1Hint,
|
|
helperMaxLines: 2,
|
|
),
|
|
),
|
|
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: 14),
|
|
Center(child: QrView(data: npub, size: 200)),
|
|
const SizedBox(height: 12),
|
|
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),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|