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

[$500] Android - It is impossible to scan the receipt with the camera, an error is displayed #34750

Closed
2 of 6 tasks
lanitochka17 opened this issue Jan 18, 2024 · 58 comments
Closed
2 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Jan 18, 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.27-1
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:

  1. Open the App
  2. Login with any account
  3. Tap on FAB -> Request money -> Scan
  4. Tap on shot camera button

Expected Result:

You can take a photo and continue the process

Actual Result:

Camera error displayed

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

Bug6346784_1705598526136.video_2024-01-18_19-21-35.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01dcae17afc7313b12
  • Upwork Job ID: 1748038364144406528
  • Last Price Increase: 2024-01-18
  • Automatic offers:
    • ikevin127 | Contributor | 28120363
@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 Jan 18, 2024
Copy link

melvin-bot bot commented Jan 18, 2024

Job added to Upwork: https://www.upwork.com/jobs/~01dcae17afc7313b12

Copy link

melvin-bot bot commented Jan 18, 2024

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

@melvin-bot melvin-bot bot changed the title Android - It is impossible to scan the receipt with the camera, an error is displayed [$500] Android - It is impossible to scan the receipt with the camera, an error is displayed Jan 18, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jan 18, 2024
@lanitochka17
Copy link
Author

#wave5-free-submitters

Copy link

melvin-bot bot commented Jan 18, 2024

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

@aswin-s
Copy link
Contributor

aswin-s commented Jan 18, 2024

Proposal

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

Error displayed while trying to scan a receipt on Android

What is the root cause of that problem?

Error is displayed while trying to capture image with camera before requesting for permissions. Even though a message requesting CameraPermission is shown above the shutter button, tap on the shutter button itself is not prevented.

This causes camera.takePicture to get invoked even before camera ref is set, resulting in the error

{cameraPermissionStatus === RESULTS.GRANTED && device != null && (
<View style={[styles.cameraView]}>
<View style={styles.flex1}>
<NavigationAwareCamera
ref={camera}
device={device}
style={[styles.flex1]}
zoom={device.neutralZoom}
photo
cameraTabIndex={1}
/>
</View>
</View>

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

Though is it quite evident from the message that camera permission is required, the shutter button is not disabled.
The issue could be resolved by invoking the askForPermissions method instead of capturePhoto if permission is not available. This feels more natural as the intension of user tapping the shutter button is to capture an image anyway.

<PressableWithFeedback
    role={CONST.ACCESSIBILITY_ROLE.BUTTON}
    accessibilityLabel={translate('receipt.shutter')}
    style={[styles.alignItemsCenter]}
    onPress={cameraPermissionStatus !== RESULTS.GRANTED? askForPermissions:  capturePhoto}
>
    <ImageSVG
        contentFit="contain"
        src={Shutter}
        width={CONST.RECEIPT.SHUTTER_SIZE}
        height={CONST.RECEIPT.SHUTTER_SIZE}
    />
</PressableWithFeedback>

Result

Before After
before_out.mp4
after_out.mp4

What alternative solutions did you explore? (Optional)

Other option is to disable the shutter button. To give visual feedback to user that it is disabled, we'll need a disabled shutter button SVG image (probably a grey version) to denote that the button is not active until permission is granted.

@ikevin127
Copy link
Contributor

Proposal

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

Camera error displayed when tapping the shutter button of the camera on scan request.

What is the root cause of that problem?

When cameraPermissionStatus is not granted, we see the screen that says Camera access is required to take pictures of receipts. with a Continue button that if pressed calls the askForPermissions function.

While the permission is not granted, if the user will press the shutter button, the capturePhoto function is called which attempts to take a photo but because the camera is not available we get the error.

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

In order to make things as convenient as possible for the user, without extra click / press I suggest to have a useEffect that runs once which if the permission is not granted already, calls the askForPermissions function - this will prompt the camera permission everytime the user navigates to the scan request screen, unless granted.

    useEffect(() => {
        if (cameraPermissionStatus === RESULTS.GRANTED) {
            return;
        }
        
        askForPermissions();
    }, []);

This way every button has 1 function and the permission prompt will show up as long as the permission is not granted everytime the user opens the scan request screen - this will clear things up as there won't be any confusion as to why the error shows when the user is pressing the shutter button right after they denied / dismissed the camera permission prompt.

Videos

Android: Native
Screen.Recording.2024-01-19.at.03.57.55.mov

@Krishna2323
Copy link
Contributor

Krishna2323 commented Jan 19, 2024

Proposal

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

Camera error displayed when tapping the shutter button of the camera on scan request.

What is the root cause of that problem?

We intentionally show error message alert when camera ref is not there.

const showCameraAlert = () => {
Alert.alert(translate('receipt.cameraErrorTitle'), translate('receipt.cameraErrorMessage'));
};
if (!camera.current) {
showCameraAlert();
return;
}

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

When we show the error alert, we can check for the permission status, if it is denied or blocked we can ask for permission, and if permission status is something else we can show the error alert.

We will add this inside capturePhoto function.

        if (!camera.current && (cameraPermissionStatus === RESULTS.DENIED || cameraPermissionStatus === RESULTS.BLOCKED)) {
            askForPermissions();
            return;
        }

We can't apply directly onPress={cameraPermissionStatus !== RESULTS.GRANTED ? askForPermissions : capturePhoto} because it will always ask for permission even if there is some other issue setting the camera ref.

Result

Optional

We can add a ref like hasAskedForCameraPermission and use it to call askForPermission when user visits scan tab for the first time. We did ssomething simila inisde

useFocusEffect(
useCallback(() => {
if (isOffline) {
return;
}
if (hasAskedForLocationPermission.current) {
return;
}
hasAskedForLocationPermission.current = true;
getCurrentPosition(
(params) => {
const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude};
setCurrentPosition(currentCoords);
setUserLocation(currentCoords);
},
() => {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (cachedUserLocation || !initialState) {
return;
}
setCurrentPosition({longitude: initialState.location[0], latitude: initialState.location[1]});
},
);
}, [cachedUserLocation, initialState, isOffline]),
);

We can modify the error check condition to use similar check like we did in mWeb/Web.

if (!cameraRef.current.getScreenshot) {
return;
}

We also need to modify the check above because if the cameraRef.current in this(!cameraRef.current.getScreenshot) case it will throw error.

Condition to add in native capturePhoto function:

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

@Krishna2323
Copy link
Contributor

Krishna2323 commented Jan 19, 2024

Proposal Updated

Added more options in optional section that can be implemented to improve UX, that might look similar to @ikevin127 proposal but its completely different because I use ref and use similar code that is already implemented in distance page.

Added this for clarity.

@alexpensify
Copy link
Contributor

@thesahindia - Can you please review the proposals here? Thanks!

@melvin-bot melvin-bot bot added the Overdue label Jan 22, 2024
@alexpensify
Copy link
Contributor

@thesahindia - any update here?

@melvin-bot melvin-bot bot removed the Overdue label Jan 22, 2024
@alexpensify
Copy link
Contributor

@thesahindia - keep us posted if you can review this one or let me know if you can't, so we can find a replacement. Thanks!

@thesahindia
Copy link
Member

@ikevin127's proposal looks good to me!

🎀 👀 🎀 C+ reviewed

Copy link

melvin-bot bot commented Jan 24, 2024

Triggered auto assignment to @aldo-expensify, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@thesahindia
Copy link
Member

@thesahindia - keep us posted if you can review this one or let me know if you can't, so we can find a replacement. Thanks!

Sorry for the delay. Not in a good shape right now!

@aldo-expensify
Copy link
Contributor

aldo-expensify commented Jan 24, 2024

As a summary, I understand that we have the following proposals:

  • @aswin-s 's proposal: Make the shutter button ask for permissions to use the camera if permissions have not been granted
  • @ikevin127 's proposal: On mounting, ask for permissions to use the camera. The user could deny permissions and still click the shutter causing the error, but the user should be more aware why that happened.
  • @Krishna2323 's proposal: I think it implements the same behaviour compared to @aswin-s 's proposal, but it is just different way to code it.

I wanted to confirm that @ikevin127 's proposal behaviour is really what we want and not @aswin-s 's proposed behaviour, so I'll ask in slack

@aldo-expensify
Copy link
Contributor

I was pointed out that in web mobile we ask immediately for permissions, so I think we should just be consistent with that.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Jan 24, 2024
Copy link

melvin-bot bot commented Jan 24, 2024

📣 @ikevin127 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@Krishna2323
Copy link
Contributor

@aldo-expensify, the selected proposal is incorrect, it will ask for permission every time we visit scan tab. I mentioned the correct way to implement it in optional section.

@aldo-expensify
Copy link
Contributor

@ikevin127 can you modify your PR to include the changes from @Krishna2323 's proposal? 🙏

@ikevin127
Copy link
Contributor

Therefore I just closed the PR and ended the accepted upwork contract.

I think you guys might've missed this line from earlier, the PR is gone (deleted, incl. branch) as I thought @Krishna2323 is going to handle this one himself.

I took on other issues in the meantime and have a few other opened PR's - therefore no capacity to take on this one really, sorry guys!

@Krishna2323
Copy link
Contributor

No problem, I will handle this, will create a PR in 2-3 days.

@alexpensify
Copy link
Contributor

Awesome, thanks!

@Krishna2323
Copy link
Contributor

Probably raising a PR today, there is another bug in android created after applying the required solution which I'm trying to solve.

@alexpensify
Copy link
Contributor

Thanks for the update!

@alexpensify
Copy link
Contributor

PR is in the works

@Krishna2323
Copy link
Contributor

@aldo-expensify @thesahindia, need your suggestions on the PR

@alexpensify
Copy link
Contributor

Weekly Update: PR is merged and making progress forward!

Copy link

melvin-bot bot commented Feb 14, 2024

⚠️ Looks like this issue was linked to a Deploy Blocker here

If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

If a regression has occurred and you are the assigned CM follow the instructions here.

If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

@ikevin127
Copy link
Contributor

ikevin127 commented Feb 20, 2024

Looks like the automation failed to set the 7-day hold for payment here since the PR #35640 (comment) was deployed to production 5 days ago (02/15/2024, 07:24 EET)🧐

Hold for payment date should be:
2024-02-22

cc @alexpensify

Also the possible regression reported above was not caused by this PR, according to #36551 (comment).

@alexpensify
Copy link
Contributor

@ikevin127 - thanks for flagging, I agree and have a reminder to continue the payment process in two days.

@alexpensify
Copy link
Contributor

alexpensify commented Feb 22, 2024

Here is the payment summary:

Extra Notes regarding payment: #34750 (comment) that's the discussion where we decided to include feedback from multiple proposals and split up the payment.

@alexpensify
Copy link
Contributor

@Krishna2323 and @aswin-s - please accept the job in Upworks and I can complete the process. Thanks!

@ikevin127
Copy link
Contributor

ikevin127 commented Feb 22, 2024

@alexpensify I also need an offer for $250 as I ended the initial contract, mentioned here #34750 (comment) because somebody else handled the PR, then only later it was decided on a 3 way split of $250.

Accepted, thank you! 🙌

@Krishna2323
Copy link
Contributor

Accepted.

@aswin-s
Copy link
Contributor

aswin-s commented Feb 22, 2024

@alexpensify Accepted the offer

@alexpensify
Copy link
Contributor

@ikevin127 - #34750 (comment)

This has been addressed, we are back on track now.

@alexpensify
Copy link
Contributor

The contributors have been paid via Upwork. I'm still working with @aldo-expensify to confirm the payment for the C+ since there is one GH stating this PR created regression and then another GH states it did not. For now, those paid via Upwork have been paid there.

@alexpensify
Copy link
Contributor

I updated the summary here: #34750 (comment)

After reviewing more, there is no clear evidence that regression was caused by this GH. @thesahindia please input a request in chat for the payment. Closing for now.

Thanks to everyone here for figuring out a good plan.

@JmillsExpensify
Copy link

$500 approved for @thesahindia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
None yet
Development

No branches or pull requests

8 participants