-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Update "Additional details" form in KYC wallet upgrade flow #6752
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f7171b6
Add fix the errors to additional details step
marcaaron 79cff94
Use DatePicker and add more validation
marcaaron 36bfc7e
fix containerStyles in DatePicker
marcaaron b1ce75f
undo unnecessary changes
marcaaron a694ff0
reset error message on submit
marcaaron 0a0580d
restore usages of scrollview for now.. add comment where we handle se…
marcaaron 31bdc6d
Break up the setAdditionalDetailsStep method
marcaaron 8007892
explicitly set error message insstead of using default
marcaaron 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 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 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 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,25 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {ScrollView} from 'react-native'; | ||
import styles from '../styles/styles'; | ||
|
||
const propTypes = { | ||
/** Form elements */ | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
const FormScrollView = React.forwardRef((props, ref) => ( | ||
<ScrollView | ||
style={[styles.w100, styles.flex1]} | ||
ref={ref} | ||
contentContainerStyle={styles.flexGrow1} | ||
keyboardShouldPersistTaps="handled" | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
> | ||
{props.children} | ||
</ScrollView> | ||
)); | ||
|
||
FormScrollView.propTypes = propTypes; | ||
export default FormScrollView; |
This file contains 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 |
---|---|---|
|
@@ -316,4 +316,5 @@ export { | |
isValidLengthForFirstOrLastName, | ||
isValidPaypalUsername, | ||
isValidRoutingNumber, | ||
isValidSSNLastFour, | ||
}; |
This file contains 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 |
---|---|---|
|
@@ -28,15 +28,26 @@ function fetchOnfidoToken() { | |
} | ||
|
||
/** | ||
* Privately used to update the additionalDetails object in Onyx (which will have various effects on the UI) | ||
* | ||
* @param {Boolean} loading whether we are making the API call to validate the user's provided personal details | ||
* @param {String[]} [errorFields] an array of field names that should display errors in the UI | ||
* @param {String} [additionalErrorMessage] an additional error message to display in the UI | ||
* @private | ||
*/ | ||
function setAdditionalDetailsStep(loading, errorFields = null, additionalErrorMessage = '') { | ||
Onyx.merge(ONYXKEYS.WALLET_ADDITIONAL_DETAILS, {loading, errorFields, additionalErrorMessage}); | ||
function setAdditionalDetailsLoading(loading) { | ||
Onyx.merge(ONYXKEYS.WALLET_ADDITIONAL_DETAILS, {loading}); | ||
} | ||
|
||
/** | ||
* @param {Object} errorFields | ||
*/ | ||
function setAdditionalDetailsErrors(errorFields) { | ||
Onyx.merge(ONYXKEYS.WALLET_ADDITIONAL_DETAILS, {errorFields: null}); | ||
Onyx.merge(ONYXKEYS.WALLET_ADDITIONAL_DETAILS, {errorFields}); | ||
} | ||
|
||
/** | ||
* @param {String} additionalErrorMessage | ||
*/ | ||
function setAdditionalDetailsErrorMessage(additionalErrorMessage) { | ||
Onyx.merge(ONYXKEYS.WALLET_ADDITIONAL_DETAILS, {additionalErrorMessage}); | ||
} | ||
|
||
/** | ||
|
@@ -70,19 +81,9 @@ function activateWallet(currentStep, parameters) { | |
onfidoData = parameters.onfidoData; | ||
Onyx.merge(ONYXKEYS.WALLET_ONFIDO, {error: '', loading: true}); | ||
} else if (currentStep === CONST.WALLET.STEP.ADDITIONAL_DETAILS) { | ||
setAdditionalDetailsStep(true); | ||
|
||
// Personal details are heavily validated on the API side. We will only do a quick check to ensure the values | ||
// exist in some capacity and then stringify them. | ||
const errorFields = _.reduce(CONST.WALLET.REQUIRED_ADDITIONAL_DETAILS_FIELDS, (missingFields, fieldName) => ( | ||
!personalDetails[fieldName] ? [...missingFields, fieldName] : missingFields | ||
), []); | ||
|
||
if (!_.isEmpty(errorFields)) { | ||
setAdditionalDetailsStep(false, errorFields); | ||
return; | ||
} | ||
|
||
setAdditionalDetailsLoading(true); | ||
setAdditionalDetailsErrors(null); | ||
setAdditionalDetailsErrorMessage(''); | ||
personalDetails = JSON.stringify(parameters.personalDetails); | ||
} else if (currentStep === CONST.WALLET.STEP.TERMS) { | ||
hasAcceptedTerms = parameters.hasAcceptedTerms; | ||
|
@@ -104,7 +105,15 @@ function activateWallet(currentStep, parameters) { | |
|
||
if (currentStep === CONST.WALLET.STEP.ADDITIONAL_DETAILS) { | ||
if (response.title === CONST.WALLET.ERROR.MISSING_FIELD) { | ||
setAdditionalDetailsStep(false, response.data.fieldNames); | ||
// Errors for missing fields are returned from the API as an array of strings so we are converting this to an | ||
// object with field names as keys and boolean for values | ||
const errorFields = _.reduce(response.data.fieldNames, (errors, fieldName) => ({ | ||
...errors, | ||
[fieldName]: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 like the change to booleans for values, will keep this refactor in mind |
||
}), {}); | ||
setAdditionalDetailsLoading(false); | ||
setAdditionalDetailsErrors(errorFields); | ||
setAdditionalDetailsErrorMessage(''); | ||
return; | ||
} | ||
|
||
|
@@ -116,11 +125,15 @@ function activateWallet(currentStep, parameters) { | |
]; | ||
|
||
if (_.contains(errorTitles, response.title)) { | ||
setAdditionalDetailsStep(false, null, response.message); | ||
setAdditionalDetailsLoading(false); | ||
setAdditionalDetailsErrorMessage(response.message); | ||
setAdditionalDetailsErrors(null); | ||
return; | ||
} | ||
|
||
setAdditionalDetailsStep(false); | ||
setAdditionalDetailsLoading(false); | ||
setAdditionalDetailsErrors(null); | ||
setAdditionalDetailsErrorMessage(''); | ||
return; | ||
} | ||
|
||
|
@@ -132,7 +145,9 @@ function activateWallet(currentStep, parameters) { | |
if (currentStep === CONST.WALLET.STEP.ONFIDO) { | ||
Onyx.merge(ONYXKEYS.WALLET_ONFIDO, {error: '', loading: true}); | ||
} else if (currentStep === CONST.WALLET.STEP.ADDITIONAL_DETAILS) { | ||
setAdditionalDetailsStep(false); | ||
setAdditionalDetailsLoading(false); | ||
setAdditionalDetailsErrors(null); | ||
setAdditionalDetailsErrorMessage(''); | ||
} else if (currentStep === CONST.WALLET.STEP.TERMS) { | ||
Onyx.merge(ONYXKEYS.WALLET_TERMS, {loading: false}); | ||
} | ||
|
@@ -159,9 +174,18 @@ function fetchUserWallet() { | |
}); | ||
} | ||
|
||
/** | ||
* @param {Object} keyValuePair | ||
*/ | ||
function updateAdditionalDetailsDraft(keyValuePair) { | ||
Onyx.merge(ONYXKEYS.WALLET_ADDITIONAL_DETAILS_DRAFT, keyValuePair); | ||
} | ||
|
||
export { | ||
fetchOnfidoToken, | ||
setAdditionalDetailsStep, | ||
activateWallet, | ||
fetchUserWallet, | ||
setAdditionalDetailsErrors, | ||
updateAdditionalDetailsDraft, | ||
setAdditionalDetailsErrorMessage, | ||
}; |
Oops, something went wrong.
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.
A little bit confused by this key name, why
DRAFT
over something likeWALLET_ADDITIONAL_DETAILS_KYC
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.
Is it a
DRAFT
because the user might not finish but will need to come back to it?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.
I'm following the pattern we initially set up here:
App/src/ONYXKEYS.js
Lines 133 to 134 in 1c80150
And yeah they are drafts since if the user bails on the flow and returns later they can pick up where they left off.
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.
This hopefully will be a detail of all forms eventually but for now we have to store it somewhere.