Skip to content
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

[C+ Checklist Needs Completion] [$500] Android - Scan - Second tap on capture button causes error to show up #36520

Closed
2 of 6 tasks
lanitochka17 opened this issue Feb 14, 2024 · 52 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Internal Requires API changes or must be handled by Expensify staff

Comments

@lanitochka17
Copy link

lanitochka17 commented Feb 14, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.41-3
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

Precondition: Camera access is allowed

  1. Launch New Expensify app
  2. Tap + > Request money
  3. Go to Scan
  4. Tap on the capture button twice

Expected Result:

The second tap on the capture button should be disabled and no error will show up

Actual Result:

The second tap on the capture button is enabled, causing error to show up

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6379529_1707925292817.Screen_Recording_20240214_215216_New_Expensify.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~017ba8b79a30323bee
  • Upwork Job ID: 1757796267721375744
  • Last Price Increase: 2024-02-14
  • Automatic offers:
    • hoangzinh | Reviewer | 0
@lanitochka17 lanitochka17 added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Feb 14, 2024
@melvin-bot melvin-bot bot changed the title Android - Scan - Second tap on capture button causes error to show up [$500] Android - Scan - Second tap on capture button causes error to show up Feb 14, 2024
Copy link

melvin-bot bot commented Feb 14, 2024

Job added to Upwork: https://www.upwork.com/jobs/~017ba8b79a30323bee

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Feb 14, 2024
Copy link

melvin-bot bot commented Feb 14, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @hoangzinh (External)

Copy link

melvin-bot bot commented Feb 14, 2024

Triggered auto assignment to @greg-schroeder (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@lanitochka17
Copy link
Author

We think that this bug might be related to #wave5
CC @quinthar

@agent3bood
Copy link
Contributor

agent3bood commented Feb 14, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

Android - Scan - Second tap on capture button causes error to show up

What is the root cause of that problem?

This is multiple levels of issues causing the problem.

  • In src/pages/iou/request/step/IOURequestStepScan/index.native.js the capturePhoto has an async operation, we need to return a Promise to make it work with the native implementation of singleExecution.
  • The native implementation expects a promise to be returned for it to work, if we don't return a promise then the singleExecution will exit before the async operation has completed which means the function can be called again before the async function is completed.
  • Current code execution flow is like this
// 1. `singleExecution` will make sure this is called just once 
capturePhoto() {
  // ... code
  
  // 2. this async callback function is added to the event loop to be executed in future tick/time.
  camera.current.takePhoto().then() => {
    // 4. some time later, the event loop will execute this code, it has nothing to do with `singleExecution`, and if the camera is busy it will throw.
  } 

  //
  // ... code
 // 3. function code is completed, `singleExecution` job is done here.
}
  • We need to fix all components that wrap capturePhoto to return a Promise, and not ignore it, for example in here the promise is not returned properly.
  • As for web, this is not an issue because the capturePhoto function is completely sync.

What changes do you think we should make in order to solve the problem?

  • Make capturePhoto return a Promise.
  • Fix all components that wrap capturePhoto to return a Promise, and not ignore it.
  • Make sure I am not introducing new async operation when the callback is just a sync operation (i.e. do not do return new Promise(/* some sync result */))
// bad
return new Promise((resolve) => {
  const results = onPress(event);
  if(results instanceof Promise) {
    return results.finally(() => {resolve();});
  } 
});

// good
const results = onPress(event);
... other code might live here
return results;

What alternative solutions did you explore? (Optional)

See previous proposal.

original proposal

Proposal

Please re-state the problem that we are trying to solve in this issue.

Android - Scan - Second tap on capture button causes error to show up

What is the root cause of that problem?

In IOURequestStepScan.capturePhoto there is an async operation to capture the photo camera.current.takePhoto().then(), only after the async operation we do the navigation/error handling.
Between the time of requesting the first photo and getting the results if the user calls the capture button again, the camera is already busy and we get an error.

What changes do you think we should make in order to solve the problem?

Add a new flag capturePhotoInProgress and return early from capturePhoto if it is true. Set the variable to true when we start the function and reset it when it is done.

What alternative solutions did you explore? (Optional)

@Krishna2323
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

Android - Scan - Second tap on capture button causes error to show up

What is the root cause of that problem?

When we call capturePhoto is called we call camera.current.takePhoto which is a async operation and if we immediately call capturePhoto again the camera is busy and !camera.current is true.

if (!camera.current) {
showCameraAlert();
return;
}

What changes do you think we should make in order to solve the problem?

We need to use useSingleExecution to solve this bug.

Result

@EnderKilledYou
Copy link

So I see these on upwork. Are they taken or finished since they have a proposal? If I apply there am I wasting connects? I can update this one for sure. You can also disable the button or remove the click handler and add it back later.

Copy link

melvin-bot bot commented Feb 14, 2024

📣 @EnderKilledYou! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@EnderKilledYou
Copy link

Contributor details
Your Expensify account email: kooshesh@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/sterlingkooshesh

Copy link

melvin-bot bot commented Feb 14, 2024

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

@EnderKilledYou
Copy link

EnderKilledYou commented Feb 14, 2024

Proposal

Update the button handler to disable the button to prevent further inputs

Please re-state the problem that we are trying to solve in this issue.

The button is able to be clicked multiple times before being prevented

What is the root cause of that problem?

Not disabling the button via a state on first click

What changes do you think we should make in order to solve the problem?

Update the button handler to disable the button to prevent further inputs
On success or error, reenable it.

USe the disabled tag. This is very common practice and is well tested.

@hoangzinh
Copy link
Contributor

Screenshot 2024-02-16 at 00 44 31

Minor update from me, I'm getting infinite loading after granting camera access on my Android simulator. I'm trying to figure out how to fix it.

@hoangzinh
Copy link
Contributor

hoangzinh commented Feb 16, 2024

@agent3bood @Krishna2323 @EnderKilledYou Thanks for proposals, everyone. I think we found the reason why it shows error but I don't think we found the root cause yet. The capture button is using Button component, which is already using useSingleExecution hook underneath => Expecting it already supported preventing double click issue

const {isExecuting, singleExecution} = useSingleExecution();

We need to find out why it doesn't work in this case.

@greg-schroeder
Copy link
Contributor

Still waiting on new proposals given @hoangzinh's comment above

@agent3bood
Copy link
Contributor

@agent3bood @Krishna2323 @EnderKilledYou Thanks for proposals, everyone. I think we found the reason why it shows error but I don't think we found the root cause yet. The capture button is using Button component, which is already using useSingleExecution hook underneath => Expecting it already supported preventing double click issue

const {isExecuting, singleExecution} = useSingleExecution();

We need to find out why it doesn't work in this case.

The issue is because of the async function .then(), so useSingleExecution will not work here.
Let me explain

// 1. `useSingleExecution` will make sure this is called just once 
capturePhoto() {
  // ... code
  
  // 2. this async callback function is added to the event loop to be executed in future tick/time.
  camera.current.takePhoto().then() => {
    // 4. some time later, the event loop will execute this code, it has nothing to do with `useSingleExecution`, and if the camera is busy it will throw.
  } 

  //
  // ... code
 // 3. function code is completed, `useSingleExecution` job is done here.
}

Buy why are we still to click twice?
Because useSingleExecution will prevent second execution in the same "tick", but it does not work for async functions, and for that we need a lock/mutex.

@Krishna2323
Copy link
Contributor

I think @agent3bood is correct here.

@hoangzinh
Copy link
Contributor

great found @agent3bood. Btw useSingleExecution also supports async callbacks, is there any way to make it work in this case?

const execution = action(...params);
InteractionManager.runAfterInteractions(() => {
if (!(execution instanceof Promise)) {
setIsExecuting(false);
return;
}
execution.finally(() => {
setIsExecuting(false);
});
});

@agent3bood
Copy link
Contributor

@hoangzinh yes it is possible, I have checked the code, for the native singleExecution to work the action must return a Promise.
But because the onPress handler is passed on multiple levels it is not returning the value of the original.
To make it work first we do return camera.current.takePhoto(.....
Then on every child component that wraps the handler it has to return the result as well.
For example this must do

const res = onPress(event);
Accessibility.moveAccessibilityFocus(nextFocusRef);
return res;

Should I update my proposal with the new fix?

@hoangzinh
Copy link
Contributor

@agent3bood yes please, could you check if it works on Web platform as well?

@agent3bood
Copy link
Contributor

@hoangzinh proposal updates, web is not affected by this issue.

@hoangzinh
Copy link
Contributor

Thanks @agent3bood. Could you include your previous root cause analytics in your current proposal? Because your current root cause is explaining why useSingleExecution doesn't work in this case, but it does not include how it's related to the current issue. It's hard for internal engineers to understand the root cause without reading all the comments.

Beside that,

Fix all components that wrap capturePhoto to return a Promise

Do you mean child components in IOURequestStepScan?

Make sure I am not introducing new async operation when the callback is just a sync operation

Could you elaborate on what you mean here? Thanks

@agent3bood
Copy link
Contributor

agent3bood commented Feb 17, 2024

@hoangzinh updated.

Fix all components that wrap capturePhoto to return a Promise

I added two places where it need to be updated, GenericPressable.

@hoangzinh
Copy link
Contributor

Thanks. @agent3bood proposal #36520 (comment) looks good to me. He pointed out the correct root cause and provided a solution that helped solve the issue well.

🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Mar 13, 2024

@agent3bood @hoangzinh @greg-schroeder @techievivek this issue is now 4 weeks old and preventing us from maintaining WAQ, can you:

  • Decide whether any proposals currently meet our guidelines and can be approved as-is today
  • If no proposals meet that standard, please take this issue internal and treat it as one of your highest priorities
  • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

Thanks!

@melvin-bot melvin-bot bot added Internal Requires API changes or must be handled by Expensify staff and removed External Added to denote the issue can be worked on by a contributor labels Mar 13, 2024
Copy link

melvin-bot bot commented Mar 13, 2024

Current assignee @hoangzinh is eligible for the Internal assigner, not assigning anyone new.

@greg-schroeder
Copy link
Contributor

PR is merged. Awaiting deploy to staging -> prod

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Apr 8, 2024
@melvin-bot melvin-bot bot changed the title [$500] Android - Scan - Second tap on capture button causes error to show up [HOLD for payment 2024-04-15] [$500] Android - Scan - Second tap on capture button causes error to show up Apr 8, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Apr 8, 2024
Copy link

melvin-bot bot commented Apr 8, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented Apr 8, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.60-13 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-04-15. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Apr 8, 2024

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@hoangzinh] The PR that introduced the bug has been identified. Link to the PR:
  • [@hoangzinh] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@hoangzinh] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@hoangzinh] Determine if we should create a regression test for this bug.
  • [@hoangzinh] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@greg-schroeder] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Apr 14, 2024
@greg-schroeder
Copy link
Contributor

Payment summary:

@agent3bood - $500 - C
@hoangzinh - $500 - C+

@greg-schroeder
Copy link
Contributor

greg-schroeder commented Apr 15, 2024

The upwork issue closed for inactivity, creating a new one via #40222

Offers sent manually - please accept them and I can pay them out tomorrow.

Last up is @hoangzinh to take care of the checklist :)

@greg-schroeder greg-schroeder changed the title [HOLD for payment 2024-04-15] [$500] Android - Scan - Second tap on capture button causes error to show up [C+ Checklist Needs Completion] [$500] Android - Scan - Second tap on capture button causes error to show up Apr 15, 2024
@hoangzinh
Copy link
Contributor

Accepeted. Thanks @greg-schroeder. I will complete the checklist today

@hoangzinh
Copy link
Contributor

hoangzinh commented Apr 16, 2024

Regression Test Proposal

On Native Apps/mWeb:

  1. Open Expensify app
  2. Tap + > Request money
  3. Go to Scan
  4. Tap on the capture button multiple times
  5. Verify that the App captures successfully and no errors popup

Do we agree 👍 or 👎

@hoangzinh
Copy link
Contributor

BugZero Checklist:

@techievivek
Copy link
Contributor

Regression test looks good to me. @greg-schroeder Can we get this added? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Internal Requires API changes or must be handled by Expensify staff
Projects
None yet
Development

No branches or pull requests

7 participants