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

[HOLD for payment 2023-09-18] [$1000] Bank account - Inconsistency bug: Checking ToS box before filling fields throws error in mweb but not in android app #26009

Closed
2 of 6 tasks
lanitochka17 opened this issue Aug 26, 2023 · 53 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Aug 26, 2023

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


Action Performed:

  1. Login to staging new dot
  2. Go to workspaces and select Bank account
  3. Click on connect manually and check the ToS box before filling the routing and bank account number fields
  4. Observe that an error is thrown
  5. Login to android app and repeat steps 2-3
  6. Observe that no error is thrown when checking and unchecking ToS box before filling routing and bank account number fields

Expected Result:

Error throwing should be consistent across platforms

Actual Result:

Inconsistent error throwing

Workaround:

Unknown

Platforms:

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

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.57-5

Reproducible in staging?: Yes

Reproducible in production?: Yes

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

Notes/Photos/Videos: Any additional supporting documentation

2023_08_17_02_11_16.mp4
0-02-01-e8ae26ce3bdcff366b1f530ea91e5fefc62c674d40979ebceefdc66bdab510cf_93b629adf30472ab.1.mp4

Expensify/Expensify Issue URL:

Issue reported by: @SofoniasN

Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1692271454788889

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01feabe39f1c833087
  • Upwork Job ID: 1696317266455986176
  • Last Price Increase: 2023-08-29
  • Automatic offers:
    • tamdao | Contributor | 26491662
    • sofoniasN | Reporter | 26491663
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 26, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 26, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Aug 26, 2023

Bug0 Triage Checklist (Main S/O)

@akinwale
Copy link
Contributor

akinwale commented Aug 27, 2023

Proposal

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

Checking the ToS box before filling fields throws an error in MWeb but not in android app

What is the root cause of that problem?

On mobile web, checking the ToS box causes the blur event for the text input field to fire which triggers validation. On native platforms, this is not the case.

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

Either of Solution 1 or 2 has to be selected for implementation.

Solution 1
On mobile web, the default behaviour when a checkbox is clicked is to blur the text input which causes the form validation to trigger since shouldValidateOnBlur is true by default. Add the following props to the Form component in BankAccountManualStep to disable validation when the text input is blurred or when the checkbox is changed (to match the behaviour on native platforms).

shouldValidateOnBlur={false}
shouldValidateOnChange={false}

Solution 2
On native platforms, blur the text input when the checkbox is tapped or clicked. This can be achieved with the following steps.

  1. In the BankAccountManualStep component, add a useRef hook for the routing number text input.
const routingNumberInputRef = useRef(null);

and set the ref for the TextInput.

<TextInput
    ...
    ref={(el) => routingNumberInputRef.current = el}
    inputID="routingNumber"
  1. Add an event handler, onCheckboxPress
const onCheckboxPress = () => {
    if (routingNumberInputRef.current) {
        routingNumberInputRef.current.blur();
    }
};

and set it as the onPress prop for the CheckboxWithLabel component.

  1. Update the CheckboxWithLabel component to support the onPress prop (add the corresponding prop type and update the toggleCheckbox method).
const toggleCheckbox = (e) => {
    if (props.onPress) {
        props.onPress(e);
    }
    const newState = !isChecked;
    props.onInputChange(newState);
    setIsChecked(newState);
};

and change the onPress props:

<Checkbox
    ...
    onPress={(e) => toggleCheckbox(e)}
    ....
/>
<PressableWithFeedback
    ...
    onPress={(e) => toggleCheckbox(e)}
    ...
/>
  1. Update the handleSpaceKey and firePressHandlerOnClick methods in the Checkbox component to pass the event parameter to the corresponding onPress calls. This is optional, but recommended for the sake of completeness.

Solution 3
Based on previous implementations of preventing loss of focus for a text input when a click is executed outside, add a preventDefault call for the checkbox press event and then programmatically change the value of the checkbox using a state variable. However, after testing, this doesn't seem to be working on web platforms in this scenario.

What alternative solutions did you explore? (Optional)

None.

@tamdao
Copy link
Contributor

tamdao commented Aug 27, 2023

Proposal

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

Bank account - Inconsistency bug: Checking ToS box before filling fields throws error in mweb but not in android app

What is the root cause of that problem?

The root cause of this issue is value change for the input not trigger blur event. In this case the input is checkbox.

What alternative solutions did you explore?

Update the childrenWrapperWithProps function in Form component

App/src/components/Form.js

Lines 219 to 357 in c029dc5

const childrenWrapperWithProps = useCallback(
(childNodes) => {
const childrenElements = React.Children.map(childNodes, (child) => {
// Just render the child if it is not a valid React element, e.g. text within a <Text> component
if (!React.isValidElement(child)) {
return child;
}
// Depth first traversal of the render tree as the input element is likely to be the last node
if (child.props.children) {
return React.cloneElement(child, {
children: childrenWrapperWithProps(child.props.children),
});
}
// Look for any inputs nested in a custom component, e.g AddressForm or IdentityForm
if (_.isFunction(child.type)) {
const childNode = new child.type(child.props);
// If the custom component has a render method, use it to get the nested children
const nestedChildren = _.isFunction(childNode.render) ? childNode.render() : childNode;
// Render the custom component if it's a valid React element
// If the custom component has nested children, Loop over them and supply From props
if (React.isValidElement(nestedChildren) || lodashGet(nestedChildren, 'props.children')) {
return childrenWrapperWithProps(nestedChildren);
}
// Just render the child if it's custom component not a valid React element, or if it hasn't children
return child;
}
// We check if the child has the inputID prop.
// We don't want to pass form props to non form components, e.g. View, Text, etc
if (!child.props.inputID) {
return child;
}
// We clone the child passing down all form props
const inputID = child.props.inputID;
let defaultValue;
// We need to make sure that checkboxes have correct
// value assigned from the list of draft values
// https://github.com/Expensify/App/issues/16885#issuecomment-1520846065
if (_.isBoolean(props.draftValues[inputID])) {
defaultValue = props.draftValues[inputID];
} else {
defaultValue = props.draftValues[inputID] || child.props.defaultValue;
}
// We want to initialize the input value if it's undefined
if (_.isUndefined(inputValues[inputID])) {
inputValues[inputID] = defaultValue || '';
}
// We force the form to set the input value from the defaultValue props if there is a saved valid value
if (child.props.shouldUseDefaultValue) {
inputValues[inputID] = child.props.defaultValue;
}
if (!_.isUndefined(child.props.value)) {
inputValues[inputID] = child.props.value;
}
const errorFields = lodashGet(props.formState, 'errorFields', {});
const fieldErrorMessage =
_.chain(errorFields[inputID])
.keys()
.sortBy()
.reverse()
.map((key) => errorFields[inputID][key])
.first()
.value() || '';
return React.cloneElement(child, {
ref: (node) => {
inputRefs.current[inputID] = node;
const {ref} = child;
if (_.isFunction(ref)) {
ref(node);
}
},
value: inputValues[inputID],
// As the text input is controlled, we never set the defaultValue prop
// as this is already happening by the value prop.
defaultValue: undefined,
errorText: errors[inputID] || fieldErrorMessage,
onBlur: (event) => {
// Only run validation when user proactively blurs the input.
if (Visibility.isVisible() && Visibility.hasFocus()) {
// We delay the validation in order to prevent Checkbox loss of focus when
// the user are focusing a TextInput and proceeds to toggle a CheckBox in
// web and mobile web platforms.
setTimeout(() => {
setTouchedInput(inputID);
if (props.shouldValidateOnBlur) {
onValidate(inputValues);
}
}, 200);
}
if (_.isFunction(child.props.onBlur)) {
child.props.onBlur(event);
}
},
onTouched: () => {
setTouchedInput(inputID);
},
onInputChange: (value, key) => {
const inputKey = key || inputID;
setInputValues((prevState) => {
const newState = {
...prevState,
[inputKey]: value,
};
if (props.shouldValidateOnChange) {
onValidate(newState);
}
return newState;
});
if (child.props.shouldSaveDraft) {
FormActions.setDraftValues(props.formID, {[inputKey]: value});
}
if (child.props.onValueChange) {
child.props.onValueChange(value, inputKey);
}
},
});
});
return childrenElements;
},
[errors, inputRefs, inputValues, onValidate, props.draftValues, props.formID, props.formState, setTouchedInput, props.shouldValidateOnBlur, props.shouldValidateOnChange],
);

Add new ref

const focusedInput = useRef(null);

Update childrenWrapperWithProps logic to add onFocus function:

... line 307
onFocus: (event) => {
    focusedInput.current = inputID;
    if (_.isFunction(child.props.onFocus)) {
        child.props.onFocus(event);
    }
},
onBlur: ....

and update the onInputChange function (line 336) to check the changed value is focused input or not

const inputKey = key || inputID;

if (focusedInput.current && focusedInput.current !== inputKey) {
    setTouchedInput(focusedInput.current);
}

I have tested this change and it works well.

@melvin-bot
Copy link

melvin-bot bot commented Aug 27, 2023

📣 @tamdao! 📣
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. 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.
  2. 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.
  3. 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>

@tamdao
Copy link
Contributor

tamdao commented Aug 27, 2023

Contributor details
Your Expensify account email: daotam4536@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~0133d983376a3d0d3d

@melvin-bot
Copy link

melvin-bot bot commented Aug 27, 2023

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

@melvin-bot melvin-bot bot added the Overdue label Aug 29, 2023
@strepanier03
Copy link
Contributor

This was previously reported and the GH closed as a feature request, not a bug.

@melvin-bot melvin-bot bot removed the Overdue label Aug 29, 2023
@strepanier03
Copy link
Contributor

strepanier03 commented Aug 29, 2023

I'm going to move this to external so that we have consistency between devices.

Note that on m/web AND android/native, the error happens if you enter an account number before the routing number. I think the easiest solution is to populate the error when the TOS checkbox or accounting number is entered before the routing number. That way both devices would be just as picky about the order.

@strepanier03 strepanier03 added the External Added to denote the issue can be worked on by a contributor label Aug 29, 2023
@melvin-bot melvin-bot bot changed the title Bank account - Inconsistency bug: Checking ToS box before filling fields throws error in mweb but not in android app [$1000] Bank account - Inconsistency bug: Checking ToS box before filling fields throws error in mweb but not in android app Aug 29, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 29, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

Current assignee @strepanier03 is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

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

@burczu
Copy link
Contributor

burczu commented Aug 29, 2023

@strepanier03 Just to be clear: based on your comment, the correct behaviour is to show the validation error when we click/tap on the checkbox first (or trying to provide account number before routing number)? Ergo, we need to fix it on mobile, not on web. Am I right?

@burczu
Copy link
Contributor

burczu commented Aug 29, 2023

@tamdao Just wondering, what if there is more than one input with autoFocus property inside the Form? Probably it's rare case scenario, but I think we shouldn't add all of these inputs to the touchedInput list, but only the one that is really focused... WDYT?

@akinwale
Copy link
Contributor

@strepanier03 Just to be clear: based on your comment, the correct behaviour is to show the validation error when we click/tap on the checkbox first (or trying to provide account number before routing number)? Ergo, we need to fix it on mobile, not on web. Am I right?

If this is the expected behaviour, Solution 2 in my proposal takes care of this.

@tamdao
Copy link
Contributor

tamdao commented Aug 29, 2023

@tamdao Just wondering, what if there is more than one input with autoFocus property inside the Form? Probably it's rare case scenario, but I think we shouldn't add all of these inputs to the touchedInput list, but only the one that is really focused... WDYT?

@burczu if you implement correctly, the form should be only having 1 autFocus. Because the same time only 1 input can be focus

@burczu
Copy link
Contributor

burczu commented Aug 29, 2023

@tamdao I agree no one should do that but, as far as I know, it's not programmatically forbidden anywhere, so in case there is more than one autoFocus all of them will be added to the thouchedInput array in your solution - that's why I think your proposal should contain some kind of check for it.

@tamdao
Copy link
Contributor

tamdao commented Aug 29, 2023

@burczu if you want, I can add more logic to check that. But you know in development, we also need to compare the performance and the value of the logic to make sure that change valuable

@burczu
Copy link
Contributor

burczu commented Aug 29, 2023

@tamdao Yeah, let's at least try to check how hard it would be - then we can decide if it's worth it. Thanks

@tamdao
Copy link
Contributor

tamdao commented Aug 29, 2023

@burczu We can add a flag like this

let isTouchedAutoFucusInput = false;
const childrenElements = React.Children.map(childNodes, (child) => {
....
    if (child.props.autoFocus && !isTouchedAutoFucusInput) {
       setTouchedInput(child.props.inputID);
       isTouchedAutoFucusInput = true;
     }
....

But I have tested the form with multiple autoFocus, it will cause validation issue when user open the screen like this (not included my change)
Screenshot 2023-08-29 at 19 39 47
This issue happens because I add 2 autoFucus into 2 input and the second will show the error message

@burczu
Copy link
Contributor

burczu commented Aug 29, 2023

Thanks @tamdao for this investigation! So it seems this check is not necessary because having more than one autoFocus in the Form will cause unexpected behaviour anyway.

Let's wait for the confirmation from @strepanier03 about my concern here. But once confirmed I think we will proceed with your proposal.

@tamdao
Copy link
Contributor

tamdao commented Sep 8, 2023

That not true :(

@SofoniasN
Copy link

@puneetlath I noticed that the offer sent in upwork for the bug report is 50 dollars, but this issue was created before the new price scheme was announcement and is eligble for the original 250 payment . Could you please look into it. Thanks

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Sep 11, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Bank account - Inconsistency bug: Checking ToS box before filling fields throws error in mweb but not in android app [HOLD for payment 2023-09-18] [$1000] Bank account - Inconsistency bug: Checking ToS box before filling fields throws error in mweb but not in android app Sep 11, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 11, 2023

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

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Sep 11, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 11, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.67-3 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 2023-09-18. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

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

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Sep 11, 2023

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:

  • [@burczu] The PR that introduced the bug has been identified. Link to the PR:
  • [@burczu] 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:
  • [@burczu] 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:
  • [@burczu] Determine if we should create a regression test for this bug.
  • [@burczu] 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.
  • [@puneetlath / @strepanier03] 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 Daily KSv2 labels Sep 18, 2023
@strepanier03
Copy link
Contributor

strepanier03 commented Sep 18, 2023

Payment summary:

  • External issue reporter - @SofoniasN - $250 paid via Upwork
  • Contributor that fixed the issue - @tamdao - $1000 paid via Upwork
  • Contributor+ that helped on the issue and/or PR - @burczu - $1000 paid via Manual Requests

Speed bonus assessment: @tamdao assigned on 2023-09-04 / PR merged on 2023-09-08 - 4 days lapsed = not eligible

@strepanier03
Copy link
Contributor

@burczu - Please submit your manual request for payment and let me know once you've done so. I will then assign Jason to issue payment.

@SofoniasN - I have paid you via Upwork and since this was reported prior to our pay change I made sure it was $250.

@tamdao - I took another look at the timeline based on your comment here but I confirmed the date you were assigned and the PR was merged was 4 days so I paid you out via Upwork at $1000.

@strepanier03
Copy link
Contributor

@burczu - I totally spaced the checklist here so please take care of that and then submit for manual payment, sorry about that!

@burczu
Copy link
Contributor

burczu commented Sep 19, 2023

@strepanier03 I'm from Callstack, so I'm not eligible for payment for this.

In terms of BZ Checklist I'll fill it as soon as I have some free time, because I'm not a bit overwhelmed by issues and PR's...

@strepanier03
Copy link
Contributor

Oh doh, I knew that. Thanks for reminding me @burczu 🤦‍♀️.

I'll follow along and finish up once you have time to do the checklist. Thanks again!

@strepanier03
Copy link
Contributor

I'm out of the office Monday-Tuesday next week. If urgent action is needed from a BZ either day, please reach out in #expensify-open-source for help. Otherwise I'll check in Wednesday.

@melvin-bot melvin-bot bot added the Overdue label Sep 25, 2023
@puneetlath
Copy link
Contributor

Going to set this to weekly priority since only thing left is the checklist.

@melvin-bot melvin-bot bot removed the Overdue label Sep 25, 2023
@puneetlath puneetlath added Weekly KSv2 and removed Daily KSv2 labels Sep 25, 2023
@puneetlath
Copy link
Contributor

@burczu also, if you have too many issues to handle, please feel encouraged to ask in #contributor-plus if others want to take some over!

@burczu
Copy link
Contributor

burczu commented Sep 25, 2023

@puneetlath No worries, I've just managed to address all my other assignments and will start handling BZ checklists that are waiting for me.

@burczu
Copy link
Contributor

burczu commented Sep 25, 2023

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:

  • [@burczu] The PR that introduced the bug has been identified. Link to the PR: This is not a regression - it just wasn't implemented this way.
  • [@burczu] 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: n/a
  • [@burczu] 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: n/a
  • [@burczu] Determine if we should create a regression test for this bug.
  • [@burczu] 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.
  • [@puneetlath / @strepanier03] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@puneetlath
Copy link
Contributor

Thanks! I think we're good to go here.

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. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests

7 participants