refactor: centralize NFC scanning into NFCUtils#3941
refactor: centralize NFC scanning into NFCUtils#3941myxmaster wants to merge 1 commit intoZeusLN:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors NFC functionality by centralizing logic into a shared utility, reducing duplication across multiple views including Send, Receive, and OpenChannel. It introduces a scanNfcTag helper and improves the user experience on Android by handling cases where NFC is disabled, providing a direct link to system settings. Review feedback suggests replacing console.warn with a dedicated logger and refining the handling of NFC scan results to ensure robustness and correct case-sensitivity for Lightning addresses.
378012b to
0aa8a45
Compare
0aa8a45 to
aabe1d9
Compare
|
After geminis suggestion (#3942 (comment)): Updated |
|
Please rebase |
aabe1d9 to
4e4847a
Compare
|
done |
4e4847a to
bb513f4
Compare
bb513f4 to
feff21f
Compare
Description
#3821 should be merged first.
enableNfc()fromSend,Receive,ReceiveEcash, andOpenChannelintoscanNfcTag()inNFCUtilsdisableNfc()(which only cleared event listeners and was misnamed) is inlined intoscanNfcTag()scanNfc()wrapper (renamed fromenableNfc()) that callsscanNfcTag()and passes the result to their ownvalidateAddress()/validateNodeUri()NFCUtils.test.tswith unit tests fornfcUtf8ArrayToStrSide effects:
OpenChannelnow also has.catch()onNfcManager.start()(was missing)Ndef.text.decodePayloadis now applied universally (was previously skipped inOpenChannel; safe since node URIs never match thehttps?/lnurlguard and always fall back tonfcUtf8ArrayToStr)Note:
I was unable to test NFC scanning end-to-end: the reading device consistently receives tag discovery events with an empty
ndefMessage, making the scan silently fail. I suspect this requires areact-native-hceupdate to fix, but I don't have a second debug device available for broadcasting. The refactored logic is identical to what was previously spread across the four views though, so it should be fine.This pull request is categorized as a:
Checklist
yarn run tscand made sure my code compiles correctlyyarn run lintand made sure my code didn’t contain any problematic patternsyarn run prettierand made sure my code is formatted correctlyyarn run testand made sure all of the tests passTesting
If you modified or added a utility file, did you add new unit tests?
I have tested this PR on the following platforms (please specify OS version and phone model/VM):
I have tested this PR with the following types of nodes (please specify node version and API version where appropriate):
On-device
Remote
Locales
Third Party Dependencies and Packages
yarnafter this PR is merged inpackage.jsonandyarn.lockhave been properly updatedOther: