Skip to content
Merged
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
9 changes: 9 additions & 0 deletions mobile-app/lib/providers/route_intent_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ class PaymentIntent {
final String? ref;

const PaymentIntent({required this.to, required this.amount, this.ref});

static PaymentIntent? tryParseUrl(String input) {
final uri = Uri.tryParse(input);
if (uri == null || uri.pathSegments.isEmpty || uri.pathSegments.first != 'pay') return null;
final to = uri.queryParameters['to'];
final amount = uri.queryParameters['amount'];
if (to == null || to.isEmpty || amount == null || amount.isEmpty) return null;
return PaymentIntent(to: to, amount: amount, ref: uri.queryParameters['ref']);
}
}

final paymentIntentProvider = StateProvider<PaymentIntent?>((_) => null);
9 changes: 3 additions & 6 deletions mobile-app/lib/services/deep_link_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ class DeepLinkService {
}

if (uri.pathSegments.isNotEmpty && uri.pathSegments.first == 'pay') {
final to = uri.queryParameters['to'];
final amount = uri.queryParameters['amount'];
final ref = uri.queryParameters['ref'];

if (to != null && to.isNotEmpty && amount != null && amount.isNotEmpty) {
_ref.read(paymentIntentProvider.notifier).state = PaymentIntent(to: to, amount: amount, ref: ref);
final payment = PaymentIntent.tryParseUrl(uri.toString());
if (payment != null) {
_ref.read(paymentIntentProvider.notifier).state = payment;
navigatorKey.currentState?.pushNamed('/account');
} else {
print('Missing payment parameters');
Expand Down
11 changes: 6 additions & 5 deletions mobile-app/lib/v2/components/qr_scanner_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import 'package:resonance_network_wallet/v2/components/glass_icon_button.dart';
import 'package:resonance_network_wallet/v2/theme/app_colors.dart';

class QrScannerPage extends StatefulWidget {
const QrScannerPage({super.key});
final bool Function(String)? validator;
const QrScannerPage({super.key, this.validator});

@override
State<QrScannerPage> createState() => _QrScannerPageState();
Expand All @@ -25,10 +26,10 @@ class _QrScannerPageState extends State<QrScannerPage> {
void _onDetect(BarcodeCapture capture) {
if (_scanned) return;
final code = capture.barcodes.firstOrNull?.rawValue;
if (code != null && code.isNotEmpty) {
_scanned = true;
Navigator.pop(context, code);
}
if (code == null || code.isEmpty) return;
if (widget.validator != null && !widget.validator!(code)) return;
_scanned = true;
Navigator.pop(context, code);
}

Future<void> _pickImage() async {
Expand Down
21 changes: 17 additions & 4 deletions mobile-app/lib/v2/screens/send/send_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:quantus_sdk/quantus_sdk.dart';
import 'package:resonance_network_wallet/v2/screens/send/send_providers.dart';
import 'package:resonance_network_wallet/v2/screens/send/send_screen_logic.dart';
import 'package:resonance_network_wallet/providers/account_providers.dart';
import 'package:resonance_network_wallet/providers/route_intent_providers.dart';
import 'package:resonance_network_wallet/providers/wallet_providers.dart';
import 'package:resonance_network_wallet/services/transaction_submission_service.dart';
import 'package:resonance_network_wallet/v2/components/success_check.dart';
Expand Down Expand Up @@ -120,12 +121,24 @@ class _SendSheetState extends ConsumerState<SendSheet> {
}

Future<void> _scanQr() async {
final address = await Navigator.push<String>(
final substrate = ref.read(substrateServiceProvider);
final scanResult = await Navigator.push<String>(
context,
MaterialPageRoute(fullscreenDialog: true, builder: (_) => const QrScannerPage()),
MaterialPageRoute(
fullscreenDialog: true,
builder: (_) => QrScannerPage(
validator: (code) => substrate.isValidSS58Address(code) || PaymentIntent.tryParseUrl(code) != null,
),
),
);
if (address != null && mounted) {
_recipientController.text = address;
// scanResult is either a valid address or a valid payment intent or null
if (scanResult == null || !mounted) return;
final payment = PaymentIntent.tryParseUrl(scanResult);
if (payment != null) {
_recipientController.text = payment.to;
_amountController.text = payment.amount;
} else {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we set text as result? Seems at this point result is malformed

@n13 n13 Mar 31, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it's a plain QR code

we validate the input now so we either get a valid payment link or a valid QUAN address as a result from the scanner - the scanner returns null for anything that's not one of these things.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question though, I had to go through the code

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh I see, okay looks good!

_recipientController.text = scanResult;
}
}

Expand Down
Loading