App icon indicating copy to clipboard operation
App copied to clipboard

Store receipts in stable directory on the native platforms

Open rezkiy37 opened this issue 1 year ago • 16 comments

Explanation of Change

The PR improves the app to store captured receipts in a new stable directory - /Receipts-Upload.

Fixed Issues

$ https://github.com/Expensify/App/issues/51761 PROPOSAL: https://github.com/Expensify/App/issues/51761#issuecomment-2473936965

Tests

  1. Go offline.
  2. Submit an expense and scan a receipt with the in-app camera (submit it to anyone).
  3. Kill the app (close).
  4. Re-open the app.
  5. Go back online
  6. The receipt is uploaded and scanned correctly. If it fails for some reason, then the user can download the receipt.
  • [x] Verify that no errors appear in the JS console

Offline tests

Same as "Tests".

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

Same as "Tests".

  • [x] Verify that no errors appear in the JS console

PR Author Checklist

  • [x] I linked the correct issue in the ### Fixed Issues section above
  • [x] I wrote clear testing steps that cover the changes made in this PR
    • [x] I added steps for local testing in the Tests section
    • [x] I added steps for the expected offline behavior in the Offline steps section
    • [x] I added steps for Staging and/or Production testing in the QA steps section
    • [x] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • [x] I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • [x] I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • [x] I included screenshots or videos for tests on all platforms
  • [x] I ran the tests on all platforms & verified they passed on:
    • [x] Android: Native
    • [x] Android: mWeb Chrome
    • [x] iOS: Native
    • [x] iOS: mWeb Safari
    • [x] MacOS: Chrome / Safari
    • [x] MacOS: Desktop
  • [x] I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • [x] I followed proper code patterns (see Reviewing the code)
    • [x] I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • [x] I verified that comments were added to code that is not self explanatory
    • [x] I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • [x] I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • [x] If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • [x] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • [x] I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • [x] I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • [x] I verified the JSDocs style guidelines (in STYLE.md) were followed
  • [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • [x] I followed the guidelines as stated in the Review Guidelines
  • [x] I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • [x] I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • [x] I verified that if a function's arguments changed that all usages have also been updated correctly
  • [x] If any new file was added I verified that:
    • [x] The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • [x] If a new CSS style is added I verified that:
    • [x] A similar style doesn't already exist
    • [x] The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • [x] If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • [x] If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • [x] If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • [x] If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • [x] If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • [x] I verified that all the inputs inside a form are aligned with each other.
    • [x] I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • [x] If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • [x] If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native

https://github.com/user-attachments/assets/a5fd7d92-c7ff-4b5b-aec1-19e0c50a9ca3

https://github.com/user-attachments/assets/120611bd-74da-42c9-813c-e12ca5f4a7ca

Android resctictinos

Files
Android: mWeb Chrome

https://github.com/user-attachments/assets/67adc093-04bb-4a64-bdda-93284434a24f

iOS: Native

https://github.com/user-attachments/assets/92536863-dfb6-486c-a27a-4da285054d00

iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop

rezkiy37 avatar Nov 13 '24 15:11 rezkiy37

@allgandalf Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

melvin-bot[bot] avatar Nov 29 '24 12:11 melvin-bot[bot]

🚧 @rlinoz has triggered a test build. You can view the workflow run here.

github-actions[bot] avatar Nov 29 '24 21:11 github-actions[bot]

:test_tube::test_tube: Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! :test_tube::test_tube:

Android :robot: iOS :apple:
https://ad-hoc-expensify-cash.s3.amazonaws.com/android/52483/index.html https://ad-hoc-expensify-cash.s3.amazonaws.com/ios/52483/index.html
Android iOS
Desktop :computer: Web :spider_web:
https://ad-hoc-expensify-cash.s3.amazonaws.com/desktop/52483/NewExpensify.dmg https://52483.pr-testing.expensify.com
Desktop Web

:eyes: View the workflow run that generated this build :eyes:

github-actions[bot] avatar Nov 29 '24 21:11 github-actions[bot]

Will complete the review today

allgandalf avatar Dec 02 '24 10:12 allgandalf

@rezkiy37 This works really great! , My only concern is every time i tested the scanning failed and we were allowed to download the scan image (Which is expected).

But how do i have a successful scan in our testing ? it's failing for me everytime on iOS native

allgandalf avatar Dec 02 '24 12:12 allgandalf

@allgandalf could you please attach a video because it works correctly on IOS on dev for me? Btw, is it possible to add my iPhone to the whitelist so I can test it as well?

rezkiy37 avatar Dec 02 '24 15:12 rezkiy37

I am attaching proofs:

Details

https://github.com/user-attachments/assets/8232298d-614a-4011-bd3a-52db265b50ff

IMG_0872

As you can see it automatically scanned the receipt successfully.

rezkiy37 avatar Dec 02 '24 16:12 rezkiy37

is it possible to add my iPhone to the whitelist so I can test it as well?

You can ask on any of the slack channels other than #expensify-open-source , the internal team has to. add your UDID for that 😄

allgandalf avatar Dec 03 '24 11:12 allgandalf

Apologies for the delay, my physical android was doing something weird fixed that, I will continue testing today

allgandalf avatar Dec 04 '24 06:12 allgandalf

I cannot test the ad hoc build on a real iPhone temporarily. So @allgandalf please retest and upload a video I can review 🙂

Screenshot 2024-12-04 at 10 43 58

rezkiy37 avatar Dec 04 '24 09:12 rezkiy37

Yes here it is, followed the steps in the OP:

https://github.com/user-attachments/assets/15a7639c-62f4-4b76-bb03-ae0692e09c4a

It fails for offline test, if we do this while online, everything works just fine!

allgandalf avatar Dec 04 '24 10:12 allgandalf

I've investigated the network deeply and realized the server returns the 405 error. Also, the FormData contains the image and it exists in the fs obviously. Can we double-check the server logs via the requestID?

Screenshot 2024-12-04 at 16 44 27 Screenshot 2024-12-04 at 16 38 16

cc @allgandalf

rezkiy37 avatar Dec 04 '24 15:12 rezkiy37

Also, the FormData contains the image and it exists in the fs obviously. Can we double-check the server logs via the requestID?

Umm i don't have access to devportal, @neil-marcellini can you help here please, the issue is that if we kill the app while offline, the receipt will always fail scanning (even when we send the file) . can you check the logs please, (@rezkiy37 correct me if i am wrong in the above statement)

allgandalf avatar Dec 04 '24 15:12 allgandalf

All good, I just want to figure it out if the backend receives the file and why sends this error. Thank you!

rezkiy37 avatar Dec 04 '24 16:12 rezkiy37

Can we double-check the server logs via the requestID?

Yeah, thanks for providing that. Looking at the logs I can see that when the request is made from our api layer to our database layer, the receipt is empty, when it should be the filename from the S3 upload response of the receipt image. So I think the problem is somewhere on the frontend with the way the receipt is sent. Would you please add some front end logging to verify that the receipt file is present, non-empty, and in the proper format?


Bedrock\Client - Starting a request ~~ command: 'CreateMoneyRequest' clusterName: 'auth' headers: '[authToken: '<REDACTED>' debtorEmail: '' amount: '0' currency: 'USD' comment: '' created: '2024-12-04' merchant: '(none)' iouReportID: '5259455211799816' chatReportID: '8301563627134920' transactionID: '3114714428657765752' reportActionID: '8074998914474577022' createdChatReportActionID: '0' createdIOUReportActionID: '0' reportPreviewReportActionID: '5351253755105051316' receipt: '' receiptState: 'SCANREADY' receiptID: '0' category: '' tag: '' billable: '' transactionThreadReportID: '5397098710674854' createdReportActionIDForThread: '3412775657730853189' commentNVP: '{"comment":""}' uploadingIP: '178.255.168.3' gps: '' personalPolicyValue: '[]' debtorAccountID: '0' reimbursable: '1' policyID: '' idempotent: '' logParam: '[email protected]' urlToNewDot: 'https://staging.new.expensify.com/' shouldReadUsingThreads: '' shouldHandleOnyxUpdates: '1' isNewDotRequest: '1' clientUpdateID: '3250954058' maxNumberOfUpdates: '500' requestID: '8ecce0ce9f2ff978-PRG' lastIP: '178.255.168.3' writeConsistency: 'ASYNC' priority: '500' timeout: '110000']'

neil-marcellini avatar Dec 09 '24 22:12 neil-marcellini

To be clear, I do see the screen shot there showing the receipt object and it looks like there's a blob for the receipt image, so it's confusing why it doesn't upload. Is everything about the request sent to the backend exactly the same between the request online that succeeds and the one that fails? I wonder if maybe there's some other receipt meta-data that gets removed when the app is killed?

neil-marcellini avatar Dec 09 '24 22:12 neil-marcellini

Working on it.

rezkiy37 avatar Dec 10 '24 16:12 rezkiy37

@rezkiy37 any updates ? lets aim to get this one merged this week

allgandalf avatar Dec 11 '24 12:12 allgandalf

@allgandalf, it is my priority right now. I am testing it with Proxyman to understand why the file is missing. Yeah, I can confirm that the blob object disappears. Working on the fix.

rezkiy37 avatar Dec 11 '24 14:12 rezkiy37

Thanks for the update man, appreciated ❤️

allgandalf avatar Dec 12 '24 08:12 allgandalf

It looks like there is a problem with Blob between app restarts. I am trying some solutions.

rezkiy37 avatar Dec 12 '24 10:12 rezkiy37

I've asked my Callstack colleagues for help with this blob issue. Tbh, I don't think we will merge the PR tomorrow. However, we could split the work up. We merge this PR because it stores receipts in the stable directory and this part of the work is done. I will work on a follow-up PR to solve the blob problem which has not occurred due to this PR. WDYT @allgandalf ?

rezkiy37 avatar Dec 12 '24 16:12 rezkiy37

Thanks @rezkiy37, that sounds good to me

neil-marcellini avatar Dec 12 '24 23:12 neil-marcellini

All good, I agree we shouldn't block this PR

allgandalf avatar Dec 13 '24 12:12 allgandalf

Reviewer Checklist

  • [x] I have verified the author checklist is complete (all boxes are checked off).
  • [x] I verified the correct issue is linked in the ### Fixed Issues section above
  • [x] I verified testing steps are clear and they cover the changes made in this PR
    • [x] I verified the steps for local testing are in the Tests section
    • [x] I verified the steps for Staging and/or Production testing are in the QA steps section
    • [x] I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • [x] I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • [x] I checked that screenshots or videos are included for tests on all platforms
  • [x] I included screenshots or videos for tests on all platforms
  • [x] I verified tests pass on all platforms & I tested again on:
    • [x] Android: Native
    • [x] Android: mWeb Chrome
    • [x] iOS: Native
    • [x] iOS: mWeb Safari
    • [x] MacOS: Chrome / Safari
    • [x] MacOS: Desktop
  • [x] If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • [x] I verified proper code patterns were followed (see Reviewing the code)
    • [x] I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • [x] I verified that comments were added to code that is not self explanatory
    • [x] I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • [x] I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • [x] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • [x] I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • [x] I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • [x] I verified the JSDocs style guidelines (in STYLE.md) were followed
  • [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • [x] I verified that this PR follows the guidelines as stated in the Review Guidelines
  • [x] I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • [x] I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • [x] If a new component is created I verified that:
    • [x] A similar component doesn't exist in the codebase
    • [x] All props are defined accurately and each prop has a /** comment above it */
    • [x] The file is named correctly
    • [x] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • [x] The only data being stored in the state is data necessary for rendering and nothing else
    • [x] For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • [x] Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • [x] All JSX used for rendering exists in the render method
    • [x] The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • [x] If any new file was added I verified that:
    • [x] The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • [x] If a new CSS style is added I verified that:
    • [x] A similar style doesn't already exist
    • [x] The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • [x] If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • [x] If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • [x] If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • [x] If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • [x] If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • [x] I verified that all the inputs inside a form are aligned with each other.
    • [x] I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • [x] If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • [x] For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • [x] If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • [x] I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native

https://github.com/user-attachments/assets/7fecf64c-2476-4022-a4b1-5f1a8c86de57

Android: mWeb Chrome

https://github.com/user-attachments/assets/65ebc951-f174-46c5-a893-9db13f3909ce

iOS: Native

https://github.com/user-attachments/assets/626fcbfe-8b2c-45d3-bd57-78904c0b09d7

iOS: mWeb Safari

https://github.com/user-attachments/assets/7b7d2175-16b4-438a-88c7-173361e9db70

MacOS: Chrome / Safari

https://github.com/user-attachments/assets/1b375a8d-fc25-4bc8-9539-9800531ec1a4

MacOS: Desktop

https://github.com/user-attachments/assets/461d63de-39be-45db-9da4-5c21b5ec9684

allgandalf avatar Dec 13 '24 20:12 allgandalf

:hand: This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

OSBotify avatar Dec 16 '24 20:12 OSBotify

🚀 Deployed to staging by https://github.com/neil-marcellini in version: 9.0.77-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅
🤖🔄 android HybridApp 🤖🔄 success ✅
🍎🔄 iOS HybridApp 🍎🔄 failure ❌

github-actions[bot] avatar Dec 18 '24 13:12 github-actions[bot]

@rezkiy37 Found issue https://github.com/Expensify/App/issues/54345 on iOS

https://platform.applause.com/services/links/v1/external/f80e8be259b8fe00c0f0be8cd97c5f8be4e5300e895d30be7e27919b99edbd07

izarutskaya avatar Dec 20 '24 11:12 izarutskaya

@rezkiy37 Found issue #54345 on iOS

https://platform.applause.com/services/links/v1/external/f80e8be259b8fe00c0f0be8cd97c5f8be4e5300e895d30be7e27919b99edbd07

@izarutskaya the issue you mentioned is not associated with this PR and the video you attached.

rezkiy37 avatar Dec 20 '24 15:12 rezkiy37

@izarutskaya, also I don't see a problem on the video. Could you please clarify?

rezkiy37 avatar Dec 20 '24 15:12 rezkiy37