Fix zaps text, only allow zaps when NWC loaded

This commit is contained in:
franzap
2025-01-03 19:41:21 -03:00
parent e65d4e35d7
commit 1289e75070
2 changed files with 98 additions and 96 deletions
+97 -93
View File
@@ -35,104 +35,108 @@ class ZapButton extends HookConsumerWidget {
}
return ElevatedButton(
onPressed: () async {
if (!nwcConnection.isPresent) {
await showDialog(
// ignore: use_build_context_synchronously
context: context,
builder: (_) => AlertDialog(
title: Text('Connect your wallet').bold,
content: NwcContainer(dialogMode: true),
),
);
}
if (!ref.read(nwcConnectionProvider).isPresent) {
return;
}
final amount = await showDialog<int>(
// ignore: use_build_context_synchronously
context: context,
builder: (context) {
return AlertDialog(
title: Text('Choose zap amount').bold,
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (user == null)
SignInButton(
publicKeyAllowed: false,
minimal: true,
signedOutText:
'⚠️ If you do not sign in, you will be zapping anonymously',
),
TextField(
controller: amountController,
keyboardType: TextInputType.number,
decoration:
InputDecoration(hintText: "Enter amount in sats"),
onPressed: nwcConnection.isLoading
? null
: () async {
if (!nwcConnection.isPresent) {
await showDialog(
// ignore: use_build_context_synchronously
context: context,
builder: (_) => AlertDialog(
title: Text('Connect your wallet').bold,
content: NwcContainer(dialogMode: true),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton(
onPressed: () => Navigator.of(context).pop(21),
child: Text('⚡️ 21'),
);
if (!ref.read(nwcConnectionProvider).isPresent) {
return;
}
}
final amount = await showDialog<int>(
// ignore: use_build_context_synchronously
context: context,
builder: (context) {
return AlertDialog(
title: Text('Choose zap amount').bold,
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (user == null)
SignInButton(
publicKeyAllowed: false,
minimal: true,
signedOutText:
'⚠️ If you do not sign in, you will be zapping anonymously',
),
TextField(
controller: amountController,
keyboardType: TextInputType.number,
decoration:
InputDecoration(hintText: "Enter amount in sats"),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton(
onPressed: () => Navigator.of(context).pop(21),
child: Text('⚡️ 21'),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(210),
child: Text('⚡️ 210'),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(2100),
child: Text('⚡️ 2100'),
),
],
),
],
),
actions: [
TextButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context)
.pop(); // Dismiss the dialog without returning an amount
},
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(210),
child: Text('⚡️ 210'),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(2100),
child: Text('⚡️ 2100'),
TextButton(
child: Text('Zap').bold,
onPressed: () {
Navigator.of(context)
.pop(int.tryParse(amountController.text) ?? 0);
},
),
],
),
],
),
actions: [
TextButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context)
.pop(); // Dismiss the dialog without returning an amount
},
),
TextButton(
child: Text('Zap').bold,
onPressed: () {
Navigator.of(context)
.pop(int.tryParse(amountController.text) ?? 0);
},
),
],
);
},
);
);
},
);
if (amount != null && amount > 0) {
try {
// ignore: use_build_context_synchronously
context.showInfo('Zap sent!',
description:
'$amount sats on their way. Your zap should show up in a few seconds.');
if (user != null) {
await user.zap(amount, event: app.latestMetadata!);
} else {
await anonUser!
.zap(amount, event: app.latestMetadata!, signer: pkSigner);
}
} catch (e) {
// ignore: use_build_context_synchronously
context.showError(
title: 'Unable to zap', description: e.toString());
}
}
},
style: ElevatedButton.styleFrom(backgroundColor: Colors.grey[800]),
if (amount != null && amount > 0) {
try {
// ignore: use_build_context_synchronously
context.showInfo('Zap sent!',
description:
'$amount sats on their way. Your zap should show up in a few seconds.');
if (user != null) {
await user.zap(amount, event: app.latestMetadata!);
} else {
await anonUser!.zap(amount,
event: app.latestMetadata!, signer: pkSigner);
}
} catch (e) {
// ignore: use_build_context_synchronously
context.showError(
title: 'Unable to zap', description: e.toString());
}
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.grey[800],
disabledBackgroundColor: Colors.grey[500],
),
child: Text(
'⚡️ Zap this release',
style: TextStyle(
+1 -3
View File
@@ -50,9 +50,7 @@ class ZapReceipts extends HookConsumerWidget {
return Padding(
padding: const EdgeInsets.only(top: 10, bottom: 10),
child: UsersRichText(
preSpan: TextSpan(
text: '⚡ $totalAmountInSats sats (${receipts.length} zaps) by'),
trailingText: ' and others',
preSpan: TextSpan(text: '⚡ $totalAmountInSats sats zapped from '),
users: senders,
),
);