-
Notifications
You must be signed in to change notification settings - Fork 7
fix: handle blob URL downloads for history CSV export #158
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
Open
0xApotheosis
wants to merge
1
commit into
main
Choose a base branch
from
fix/history-download-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−0
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * Injected JavaScript to intercept blob URL creation for file downloads. | ||
| * When the web app creates a blob URL for a downloadable file (like CSV export), | ||
| * this script converts the blob to base64 and sends it to the native app | ||
| * via postMessage for proper file handling using expo-file-system and expo-sharing. | ||
| */ | ||
| export const injectedJavaScript = ` | ||
| ;(function() { | ||
| const originalCreateObjectURL = URL.createObjectURL; | ||
| URL.createObjectURL = function(blob) { | ||
| const url = originalCreateObjectURL.call(URL, blob); | ||
|
|
||
| // Check if this is a downloadable file type | ||
| const downloadableTypes = [ | ||
| 'text/csv', | ||
| 'application/csv', | ||
| 'application/octet-stream', | ||
| 'text/plain', | ||
| 'application/json' | ||
| ]; | ||
|
|
||
| if (blob instanceof Blob && downloadableTypes.includes(blob.type)) { | ||
| const reader = new FileReader(); | ||
| reader.onloadend = function() { | ||
| if (reader.result && typeof reader.result === 'string') { | ||
| const base64 = reader.result.split(',')[1]; | ||
| if (base64 && window.ReactNativeWebView) { | ||
| // Determine filename and extension based on MIME type | ||
| const mimeToExt = { | ||
| 'text/csv': '.csv', | ||
| 'application/csv': '.csv', | ||
| 'application/json': '.json', | ||
| 'text/plain': '.txt', | ||
| 'application/octet-stream': '.csv' // Default to CSV for history export | ||
| }; | ||
| const ext = mimeToExt[blob.type] || '.csv'; | ||
| const filename = 'transaction-history' + ext; | ||
|
|
||
| window.ReactNativeWebView.postMessage(JSON.stringify({ | ||
| cmd: 'downloadFile', | ||
| data: base64, | ||
| filename: filename, | ||
| mimeType: blob.type || 'application/octet-stream' | ||
| })); | ||
| } | ||
| } | ||
| }; | ||
| reader.readAsDataURL(blob); | ||
| } | ||
|
|
||
| return url; | ||
| }; | ||
| })(); | ||
| ` |
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
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.
🧩 Analysis chain
🌐 Web query:
expo-file-system expo-sharing compatibility Expo SDK 54💡 Result:
Short answer: expo-file-system had breaking API changes in Expo SDK 54 (the "next" rewrite became the default and the old API is available as expo-file-system/legacy). expo-sharing remains compatible with SDK 54 (no breaking changes called out).
Details and actions:
If you want, tell me whether you’re upgrading an app or a library and I’ll suggest the exact import changes or search your package.json for affected packages.
Sources: [1] Expo SDK 54 changelog; [2] github issues about expo-file-system in SDK 54; [3] expo-sharing docs.
🌐 Web query:
Expo SDK 54 dependencies compatibility matrix💡 Result:
Here’s a concise compatibility summary for Expo SDK 54 (key dependencies, platform/tooling, and important notes):
Sources:
If you want, I can generate a more detailed matrix listing specific Expo module package versions (expo-constants, expo-file-system, reanimated, react-native-screens, etc.) pulled from the SDK 54 bundled modules. Which exact packages would you like included?
🌐 Web query:
expo-file-system 19.0.21 Expo SDK 54💡 Result:
Short answer: Expo SDK 54 ships with expo-file-system v19 (bundled ~19.0.21). The package’s new API is now the default; the old API is available under expo-file-system/legacy if you need it. Install with npx expo install expo-file-system and update imports (or use /legacy). [1][2]
Sources:
Review code using expo-file-system for Expo SDK 54 breaking changes.
expo-file-system ~19.0.21 is compatible with Expo SDK 54 but includes breaking API changes: the new API became the default, and the old API is available under
expo-file-system/legacy. Verify that your code uses the correct API or update imports toexpo-file-system/legacyif needed.expo-sharing ~14.0.8 is fully compatible with SDK 54 with no breaking changes.
🤖 Prompt for AI Agents