-
Notifications
You must be signed in to change notification settings - Fork 77
feat: Add Coldcard MK4 and Coldcard Q NFC by ben-kaufman
#1314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aabbb68
Add Coldcard MK4 and Coldcard Q NFC
ben-kaufman 06a9326
Fix Android navigation issue
ben-kaufman cfc9969
Fix Android NFC animation size
ben-kaufman bc8d571
Update NFC sheet colour
ben-kaufman 1b6ec9a
Merge pull request #1284 from ben-kaufman/coldcard-nfc
ethicnology File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>com.apple.developer.nfc.readersession.formats</key> | ||
| <array> | ||
| <string>TAG</string> | ||
| <string>NDEF</string> | ||
| </array> | ||
| </dict> | ||
| </plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| import 'dart:io' show Platform; | ||
|
|
||
| import 'package:bb_mobile/core/themes/app_theme.dart'; | ||
| import 'package:bb_mobile/core/utils/logger.dart'; | ||
| import 'package:bb_mobile/core/widgets/bottom_sheet/x.dart'; | ||
| import 'package:bb_mobile/core/widgets/nfc_scanner_widget.dart'; | ||
| import 'package:bb_mobile/core/widgets/snackbar_utils.dart'; | ||
| import 'package:bb_mobile/core/widgets/text/text.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_nfc_kit/flutter_nfc_kit.dart'; | ||
| import 'package:ndef/ndef.dart' as ndef; | ||
|
|
||
| class NfcBottomSheet { | ||
| static Future<void> showReadNfc({ | ||
| required BuildContext context, | ||
| required String title, | ||
| required Future<void> Function(String payload) onDataReceived, | ||
| }) async { | ||
| await _showNfcBottomSheet( | ||
| context: context, | ||
| title: title, | ||
| onNfcAction: (tag) => _handleNfcRead(tag, context, onDataReceived), | ||
| ); | ||
| } | ||
|
|
||
| static Future<void> showWriteNfc({ | ||
| required BuildContext context, | ||
| required String title, | ||
| required String data, | ||
| required VoidCallback onSuccess, | ||
| }) async { | ||
| await _showNfcBottomSheet( | ||
| context: context, | ||
| title: title, | ||
| onNfcAction: (tag) => _writeNfcData(context, data, onSuccess), | ||
| ); | ||
| } | ||
|
|
||
| static Future<void> _showNfcBottomSheet({ | ||
| required BuildContext context, | ||
| required String title, | ||
| required Future<void> Function(NFCTag tag) onNfcAction, | ||
| }) async { | ||
| final isAvailable = await FlutterNfcKit.nfcAvailability; | ||
| if (isAvailable != NFCAvailability.available) { | ||
| if (context.mounted) { | ||
| final message = switch (isAvailable) { | ||
| NFCAvailability.disabled => 'NFC is disabled. Please enable NFC in your device settings', | ||
| NFCAvailability.not_supported => 'NFC is not supported on this device', | ||
| _ => 'NFC is not available on this device', | ||
| }; | ||
| SnackBarUtils.showSnackBar(context, message); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if (!context.mounted) { | ||
| return; | ||
| } | ||
|
|
||
| if (Platform.isIOS) { | ||
| try { | ||
| final tag = await FlutterNfcKit.poll(iosAlertMessage: title); | ||
| if (context.mounted) { | ||
| await onNfcAction(tag); | ||
| } | ||
| } catch (e) { | ||
| log.warning('NFC operation failed', error: e); | ||
| if (context.mounted && | ||
| !e.toString().contains('Session invalidated by user')) { | ||
| SnackBarUtils.showSnackBar(context, 'NFC error: $e'); | ||
| } | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| await BlurredBottomSheet.show( | ||
| context: context, | ||
| isDismissible: true, | ||
| child: SafeArea( | ||
| child: Container( | ||
| padding: const EdgeInsets.all(24), | ||
| decoration: BoxDecoration( | ||
| color: context.colour.onPrimary, | ||
| borderRadius: const BorderRadius.vertical(top: Radius.circular(16)), | ||
| ), | ||
| height: 450, | ||
| child: Column( | ||
| children: [ | ||
| BBText( | ||
| title, | ||
| style: context.font.headlineSmall, | ||
| textAlign: TextAlign.center, | ||
| ), | ||
| Expanded( | ||
| child: NfcScannerWidget( | ||
| onScanned: (NFCTag tag) async { | ||
| if (context.mounted) { | ||
| Navigator.of(context).pop(); | ||
| } | ||
| await onNfcAction(tag); | ||
| }, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| static Future<void> _handleNfcRead( | ||
| NFCTag tag, | ||
| BuildContext context, | ||
| Future<void> Function(String payload) onDataReceived, | ||
| ) async { | ||
| try { | ||
| final ndefRecords = await FlutterNfcKit.readNDEFRecords(); | ||
|
|
||
| if (ndefRecords.isEmpty) return; | ||
|
|
||
| final lastRecord = ndefRecords.last; | ||
|
|
||
| String payload = ''; | ||
| if (lastRecord is ndef.ExternalRecord) { | ||
| payload = | ||
| lastRecord.payload | ||
| ?.map((byte) => byte.toRadixString(16).padLeft(2, '0')) | ||
| .join('') ?? | ||
| ''; | ||
| } else if (lastRecord is ndef.TextRecord) { | ||
| payload = lastRecord.text ?? ''; | ||
| } | ||
|
|
||
| if (payload.isEmpty) return; | ||
|
|
||
| await onDataReceived(payload); | ||
| } catch (e) { | ||
| log.warning('Failed reading/parsing NDEF', error: e); | ||
| if (context.mounted && | ||
| !e.toString().contains('Session invalidated by user')) { | ||
| SnackBarUtils.showSnackBar(context, 'NFC error: $e'); | ||
| } | ||
| } finally { | ||
| try { | ||
| await FlutterNfcKit.finish(); | ||
| } catch (_) {} | ||
| } | ||
| } | ||
|
|
||
| static Future<void> _writeNfcData( | ||
| BuildContext context, | ||
| String data, | ||
| VoidCallback onSuccess, | ||
| ) async { | ||
| try { | ||
| await FlutterNfcKit.writeNDEFRecords([ | ||
| ndef.TextRecord( | ||
| text: data, | ||
| language: 'en', | ||
| encoding: ndef.TextEncoding.UTF8, | ||
| ), | ||
| ]); | ||
|
|
||
| await FlutterNfcKit.finish(); | ||
| onSuccess(); | ||
| } catch (e) { | ||
| log.warning('Failed to send data via NFC: $e'); | ||
| if (context.mounted && | ||
| !e.toString().contains('Session invalidated by user')) { | ||
| SnackBarUtils.showSnackBar(context, 'NFC error: $e'); | ||
| } | ||
| } finally { | ||
| try { | ||
| await FlutterNfcKit.finish(); | ||
| } catch (_) {} | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NFC was disabled probably because of stores publication process.
May be delayed into another release
cc @i5hi