go icon indicating copy to clipboard operation
go copied to clipboard

fix: iOS crash when viewing payment details with URL (#433)

Open Utkarshpandey0001 opened this issue 9 months ago • 3 comments

  • Wrap JSON.parse in try-catch to handle malformed payloads
  • Add decodeURIComponent for proper URL decoding
  • Show error toast and navigate back on parse failure
  • Add null check with early return to prevent rendering with invalid data
  • Move all React hooks before early return to satisfy Rules of Hooks

Summary by CodeRabbit

  • Bug Fixes
    • Improved transaction loading error handling. Invalid or corrupted transactions now trigger error notifications and automatically navigate users back.
    • Enhanced data validation with improved null-safety checks to prevent incomplete transaction data from displaying.
    • Fixed wallet selection logic to ensure consistent and accurate wallet association with transactions.

Utkarshpandey0001 avatar Feb 08 '26 16:02 Utkarshpandey0001

📝 Walkthrough

Walkthrough

The changes improve transaction data parsing and error handling in Transaction.tsx. JSON parsing is now wrapped in try/catch with decodeURIComponent for safer processing. The component adds early guards against null transactions, provides user feedback via error toasts, and reorders initialization logic to prevent working with invalid data.

Changes

Cohort / File(s) Summary
Transaction Data Parsing & Error Handling
pages/Transaction.tsx
Replaced direct JSON.parse with decodeURIComponent-wrapped try/catch block that returns Nip47Transaction | null and logs errors. Added null transaction guards in useEffect and TransactionIcon memo. Introduced error toast display and router.back() navigation on parse failure. Simplified memo dependencies and consolidated duplicate displayCharacterCount calculation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A safer parse, with guards so keen, Error handling keeps the flow clean. No nulls slip through without a care, Toast messages show users we're there! Transaction data, now robust and bright, The rabbit approves—this refactor's just right! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: handling iOS crash when viewing payment details with a URL. It directly relates to the changeset's core objective of adding error handling and null checks for transaction parsing.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Feb 08 '26 16:02 coderabbitai[bot]

Hi @Utkarshpandey0001, did you manage to reproduce the error mentioned in the issue?

im-adithya avatar Feb 09 '26 08:02 im-adithya

@im-adithya on my side i was not getting that error even though i was using ios environment but i spot the potential cause which was the way we were parsing the JSON in case if it was not successfully parsing it cause to crash because there was no error handling so i kept it in try catch block.

Utkarshpandey0001 avatar Feb 14 '26 14:02 Utkarshpandey0001

Closing in favor of https://github.com/getAlby/go/pull/442, thanks for the effort 🙌

im-adithya avatar Jun 17 '26 15:06 im-adithya