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

Refactor part of Wallet_Activate into VerifyIdentity #10053

Merged
merged 22 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
801c2cc
Add call to refactored VerifyIdentity command
MariaHCD Jul 22, 2022
3df89d3
Call verifyIndentity in OnfidoStep
MariaHCD Jul 22, 2022
40ac178
Optimistically set shouldShowFailedKYC as false
MariaHCD Jul 25, 2022
554b31a
Handle Onfido fixable errors
MariaHCD Jul 25, 2022
34a25b1
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Jul 25, 2022
208b730
Use arrayOf
MariaHCD Jul 25, 2022
74adbf7
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Jul 25, 2022
11901b6
Display fixable errors
MariaHCD Jul 26, 2022
3890bf1
Improve display of fixable errors
MariaHCD Jul 26, 2022
f727d33
Omit value for boolean attribute
MariaHCD Jul 26, 2022
5d23285
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Aug 9, 2022
c498ade
Update error object format
MariaHCD Aug 9, 2022
c9b8ef2
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Aug 12, 2022
a10d2d9
Make FormAlertWrapper more readable
MariaHCD Aug 12, 2022
c94097e
Use newline instead of break tag
MariaHCD Aug 12, 2022
60b96ad
Use constants and update comment
MariaHCD Aug 12, 2022
e585326
Fix display of fixable error
MariaHCD Aug 12, 2022
d9cfe24
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Aug 16, 2022
824933e
Revert "Make FormAlertWrapper more readable"
MariaHCD Aug 19, 2022
10ad0b8
Set errors and fixableErrors to null
MariaHCD Aug 19, 2022
51665ca
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Aug 19, 2022
e9d29b1
Set errorFields to null
MariaHCD Aug 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/components/FormAlertWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@ const FormAlertWrapper = props => (
<View style={[styles.flexRow, styles.ml2, styles.flexWrap, styles.flex1]}>
{!_.isEmpty(props.message) && props.isMessageHtml && <RenderHTML html={`<muted-text>${props.message}</muted-text>`} />}

{!_.isEmpty(props.message) && !props.isMessageHtml
? <Text style={styles.mutedTextLabel}>{props.message}</Text>
: (
<>
<Text style={styles.mutedTextLabel}>
{`${props.translate('common.please')} `}
</Text>
<TextLink
style={styles.label}
onPress={props.onFixTheErrorsPressed}
>
{props.translate('common.fixTheErrors')}
</TextLink>
<Text style={styles.mutedTextLabel}>
{` ${props.translate('common.inTheFormBeforeContinuing')}.`}
</Text>
</>
)}
{!_.isEmpty(props.message) && !props.isMessageHtml && <Text style={styles.mutedTextLabel}>{props.message}</Text>}

{_.isEmpty(props.message) && (
<>
<Text style={styles.mutedTextLabel}>
{`${props.translate('common.please')} `}
</Text>
<TextLink
style={styles.label}
onPress={props.onFixTheErrorsPressed}
>
{props.translate('common.fixTheErrors')}
</TextLink>
<Text style={styles.mutedTextLabel}>
{` ${props.translate('common.inTheFormBeforeContinuing')}.`}
</Text>
</>
)}
MariaHCD marked this conversation as resolved.
Show resolved Hide resolved
</View>
</View>
)}
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export {
fetchOnfidoToken,
activateWallet,
fetchUserWallet,
verifyIdentity,
} from './Wallet';

function clearPersonalBankAccount() {
Expand Down
58 changes: 58 additions & 0 deletions src/libs/actions/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as DeprecatedAPI from '../deprecatedAPI';
import CONST from '../../CONST';
import * as PaymentMethods from './PaymentMethods';
import * as Localize from '../Localize';
import * as API from '../API';

/**
* Fetch and save locally the Onfido SDK token and applicantID
Expand Down Expand Up @@ -316,6 +317,62 @@ function activateWallet(currentStep, parameters) {
});
}

/**
* Creates an identity check by calling Onfido's API with data returned from the SDK
*
* The API will always return the updated userWallet in the response as a convenience so we can avoid calling
* Get&returnValueList=userWallet after we call Wallet_Activate.
*
* @param {Object} parameters
* @param {String} [parameters.onfidoData] - JSON string
*/
function verifyIdentity(parameters) {
const onfidoData = parameters.onfidoData;

API.write('VerifyIdentity', {
onfidoData,
}, {
optimisticData: [
{
onyxMethod: 'merge',
key: ONYXKEYS.WALLET_ONFIDO,
value: {
loading: true,
errors: {},
fixableErrors: [],
MariaHCD marked this conversation as resolved.
Show resolved Hide resolved
},
},
{
onyxMethod: 'merge',
key: ONYXKEYS.USER_WALLET,
value: {
shouldShowFailedKYC: false,
},
},
],
successData: [
{
onyxMethod: 'merge',
key: ONYXKEYS.WALLET_ONFIDO,
value: {
loading: false,
errors: {},
MariaHCD marked this conversation as resolved.
Show resolved Hide resolved
},
},
],
failureData: [
{
onyxMethod: 'merge',
key: ONYXKEYS.WALLET_ONFIDO,
value: {
loading: false,
hasAcceptedPrivacyPolicy: false,
},
},
],
});
}

/**
* Fetches information about a user's Expensify Wallet
*
Expand Down Expand Up @@ -361,4 +418,5 @@ export {
setAdditionalDetailsQuestions,
buildIdologyError,
updateCurrentStep,
verifyIdentity,
};
29 changes: 9 additions & 20 deletions src/pages/EnablePayments/OnfidoPrivacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import FormAlertWithSubmitButton from '../../components/FormAlertWithSubmitButto
import FormScrollView from '../../components/FormScrollView';
import walletAdditionalDetailsDraftPropTypes from './walletAdditionalDetailsDraftPropTypes';
import walletOnfidoDataPropTypes from './walletOnfidoDataPropTypes';
import * as Localize from '../../libs/Localize';

const propTypes = {
/** Stores various information used to build the UI and call any APIs */
Expand All @@ -32,7 +31,8 @@ const defaultProps = {
applicantID: '',
sdkToken: '',
loading: false,
error: '',
errors: {},
fixableErrors: [],
hasAcceptedPrivacyPolicy: false,
},
};
Expand All @@ -53,28 +53,16 @@ class OnfidoPrivacy extends React.Component {
}

render() {
let onfidoError = lodashGet(this.props, 'walletOnfidoData.error') || '';
if (!onfidoError) {
const onfidoFixableErrors = lodashGet(this.props, 'userWallet.onfidoFixableErrors', []);
if (!_.isEmpty(onfidoFixableErrors)) {
const supportedErrorKeys = ['originalDocumentNeeded', 'documentNeedsBetterQuality', 'imageNeedsBetterQuality', 'selfieIssue', 'selfieNotMatching', 'selfieNotLive'];
const translatedFixableErrors = _.filter(_.map(onfidoFixableErrors, (errorKey) => {
if (_.contains(supportedErrorKeys, errorKey)) {
return Localize.translateLocal(`onfidoStep.${errorKey}`);
}
return null;
}));
if (!_.isEmpty(translatedFixableErrors)) {
onfidoError = translatedFixableErrors.join(' ');
}
}
}
const errors = lodashGet(this.props, 'walletOnfidoData.errors', {});
let onfidoError = _.isEmpty(errors) ? '' : _.last(_.values(errors));
const onfidoFixableErrors = lodashGet(this.props, 'walletOnfidoData.fixableErrors', []);
onfidoError += !_.isEmpty(onfidoFixableErrors) ? `<br/> ${onfidoFixableErrors.join('<br>')}` : '';
MariaHCD marked this conversation as resolved.
Show resolved Hide resolved

return (
<View style={[styles.mh5, styles.mb5, styles.flex1, styles.justifyContentBetween]}>
<View style={[styles.mb5, styles.flex1, styles.justifyContentBetween]}>
{!this.props.walletOnfidoData.hasAcceptedPrivacyPolicy ? (
<FormScrollView ref={el => this.form = el}>
<View style={styles.justifyContentCenter}>
<View style={[styles.mh5, styles.justifyContentCenter]}>
<Text style={[styles.mb5]}>
{this.props.translate('onfidoStep.acceptTerms')}
<TextLink
Expand Down Expand Up @@ -104,6 +92,7 @@ class OnfidoPrivacy extends React.Component {
this.form.scrollTo({y: 0, animated: true});
}}
message={onfidoError}
isMessageHtml
isLoading={this.props.walletOnfidoData.loading}
buttonText={onfidoError ? this.props.translate('onfidoStep.tryAgain') : this.props.translate('common.continue')}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/EnablePayments/OnfidoStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class OnfidoStep extends React.Component {
Navigation.goBack();
}}
onSuccess={(data) => {
BankAccounts.activateWallet(CONST.WALLET.STEP.ONFIDO, {
BankAccounts.verifyIdentity({
onfidoData: JSON.stringify({
...data,
applicantID: this.props.walletOnfidoData.applicantID,
Expand Down
3 changes: 3 additions & 0 deletions src/pages/EnablePayments/walletOnfidoDataPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export default PropTypes.shape({
/** Error message to inform the user of any problem that might occur */
error: PropTypes.string,

/** A list of Onfido errors that the user can fix in order to attempt the Onfido flow again */
fixableErrors: PropTypes.arrayOf(PropTypes.string),

/** Whether the user has accepted the privacy policy of Onfido or not */
hasAcceptedPrivacyPolicy: PropTypes.bool,
});