Skip to content

Commit bdfa147

Browse files
authored
Merge pull request #9914 from Expensify/alberto-refactorWallet
Refactor part of ActivateWallet into UpdatePersonalDetailsForWallet
2 parents 7a58ab9 + 990dbc9 commit bdfa147

File tree

5 files changed

+90
-23
lines changed

5 files changed

+90
-23
lines changed

src/CONST.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ const CONST = {
539539
},
540540
},
541541
ERROR: {
542+
// If these get updated, we need to update the codes on the Web side too
543+
SSN: 'ssnError',
544+
KBA: 'kbaNeeded',
545+
KYC: 'kycFailed',
542546
FULL_SSN_NOT_FOUND: 'Full SSN not found',
543547
MISSING_FIELD: 'Missing required additional details fields',
544548
WRONG_ANSWERS: 'Wrong answers',

src/libs/actions/Wallet.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as DeprecatedAPI from '../deprecatedAPI';
77
import CONST from '../../CONST';
88
import * as PaymentMethods from './PaymentMethods';
99
import * as Localize from '../Localize';
10+
import * as API from '../API';
1011

1112
/**
1213
* Fetch and save locally the Onfido SDK token and applicantID
@@ -153,6 +154,66 @@ function buildIdologyError(idologyErrors) {
153154
return `${errorStart} ${Localize.arrayToString(errorsTranslated)}. ${errorEnd}`;
154155
}
155156

157+
/**
158+
* Validates a user's provided details against a series of checks
159+
*
160+
* @param {Object} personalDetails
161+
*/
162+
function updatePersonalDetails(personalDetails) {
163+
if (!personalDetails) {
164+
return;
165+
}
166+
const firstName = personalDetails.legalFirstName || '';
167+
const lastName = personalDetails.legalLastName || '';
168+
const dob = personalDetails.dob || '';
169+
const addressStreet = personalDetails.addressStreet || '';
170+
const addressCity = personalDetails.addressCity || '';
171+
const addressState = personalDetails.addressState || '';
172+
const addressZip = personalDetails.addressZip || '';
173+
const ssn = personalDetails.ssn || '';
174+
const phoneNumber = personalDetails.phoneNumber || '';
175+
API.write('UpdatePersonalDetailsForWallet', {
176+
firstName,
177+
lastName,
178+
dob,
179+
addressStreet,
180+
addressCity,
181+
addressState,
182+
addressZip,
183+
ssn,
184+
phoneNumber,
185+
}, {
186+
optimisticData: [
187+
{
188+
onyxMethod: CONST.ONYX.METHOD.MERGE,
189+
key: ONYXKEYS.WALLET_ADDITIONAL_DETAILS,
190+
value: {
191+
isLoading: true,
192+
errors: [],
193+
},
194+
},
195+
],
196+
successData: [
197+
{
198+
onyxMethod: CONST.ONYX.METHOD.MERGE,
199+
key: ONYXKEYS.WALLET_ADDITIONAL_DETAILS,
200+
value: {
201+
isLoading: false,
202+
},
203+
},
204+
],
205+
failureData: [
206+
{
207+
onyxMethod: CONST.ONYX.METHOD.MERGE,
208+
key: ONYXKEYS.WALLET_ADDITIONAL_DETAILS,
209+
value: {
210+
isLoading: false,
211+
},
212+
},
213+
],
214+
});
215+
}
216+
156217
/**
157218
* This action can be called repeatedly with different steps until an Expensify Wallet has been activated.
158219
*
@@ -361,4 +422,5 @@ export {
361422
setAdditionalDetailsQuestions,
362423
buildIdologyError,
363424
updateCurrentStep,
425+
updatePersonalDetails,
364426
};

src/pages/EnablePayments/AdditionalDetailsStep.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize
1111
import Navigation from '../../libs/Navigation/Navigation';
1212
import styles from '../../styles/styles';
1313
import Text from '../../components/Text';
14-
import * as BankAccounts from '../../libs/actions/BankAccounts';
1514
import CONST from '../../CONST';
1615
import compose from '../../libs/compose';
1716
import ONYXKEYS from '../../ONYXKEYS';
@@ -28,6 +27,7 @@ import FormHelper from '../../libs/FormHelper';
2827
import walletAdditionalDetailsDraftPropTypes from './walletAdditionalDetailsDraftPropTypes';
2928
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../components/withCurrentUserPersonalDetails';
3029
import * as PersonalDetails from '../../libs/actions/PersonalDetails';
30+
import OfflineIndicator from '../../components/OfflineIndicator';
3131

3232
const propTypes = {
3333
...withLocalizePropTypes,
@@ -36,13 +36,13 @@ const propTypes = {
3636
/** Stores additional information about the additional details step e.g. loading state and errors with fields */
3737
walletAdditionalDetails: PropTypes.shape({
3838
/** Are we waiting for a response? */
39-
loading: PropTypes.bool,
39+
isLoading: PropTypes.bool,
4040

4141
/** Which field needs attention? */
4242
errorFields: PropTypes.objectOf(PropTypes.bool),
4343

4444
/** Any additional error message to show */
45-
additionalErrorMessage: PropTypes.string,
45+
errors: PropTypes.objectOf(PropTypes.string),
4646

4747
/** Questions returned by Idology */
4848
questions: PropTypes.arrayOf(PropTypes.shape({
@@ -54,8 +54,8 @@ const propTypes = {
5454
/** ExpectID ID number related to those questions */
5555
idNumber: PropTypes.string,
5656

57-
/** If we should ask for the full SSN (when LexisNexis failed retrieving the first 5 from the last 4) */
58-
shouldAskForFullSSN: PropTypes.bool,
57+
/** Error code to determine additional behavior */
58+
errorCode: PropTypes.string,
5959
}),
6060

6161
/** Stores the personal details typed by the user */
@@ -65,11 +65,11 @@ const propTypes = {
6565
const defaultProps = {
6666
walletAdditionalDetails: {
6767
errorFields: {},
68-
loading: false,
69-
additionalErrorMessage: '',
68+
isLoading: false,
69+
errors: {},
7070
questions: [],
7171
idNumber: '',
72-
shouldAskForFullSSN: false,
72+
errorCode: '',
7373
},
7474
walletAdditionalDetailsDraft: {
7575
legalFirstName: '',
@@ -187,7 +187,7 @@ class AdditionalDetailsStep extends React.Component {
187187
errors.phoneNumber = true;
188188
}
189189

190-
if (this.props.walletAdditionalDetails.shouldAskForFullSSN) {
190+
if (this.props.walletAdditionalDetails.errorCode === CONST.WALLET.ERROR.SSN) {
191191
if (!ValidationUtils.isValidSSNFullNine(this.props.walletAdditionalDetailsDraft.ssn)) {
192192
errors.ssnFull9 = true;
193193
}
@@ -211,13 +211,11 @@ class AdditionalDetailsStep extends React.Component {
211211
if (!this.validate()) {
212212
return;
213213
}
214-
215-
BankAccounts.activateWallet(CONST.WALLET.STEP.ADDITIONAL_DETAILS, {
216-
personalDetails: {
217-
...this.props.walletAdditionalDetailsDraft,
218-
phoneNumber: LoginUtils.getPhoneNumberWithoutUSCountryCodeAndSpecialChars(this.props.walletAdditionalDetailsDraft.phoneNumber),
219-
},
220-
});
214+
const personalDetails = {
215+
...this.props.walletAdditionalDetailsDraft,
216+
phoneNumber: LoginUtils.getPhoneNumberWithoutUSCountryCodeAndSpecialChars(this.props.walletAdditionalDetailsDraft.phoneNumber),
217+
};
218+
Wallet.updatePersonalDetails(personalDetails);
221219
}
222220

223221
/**
@@ -267,10 +265,12 @@ class AdditionalDetailsStep extends React.Component {
267265
);
268266
}
269267

268+
const errors = lodashGet(this.props, 'walletAdditionalDetails.errors', {});
270269
const isErrorVisible = _.size(this.getErrors()) > 0
271-
|| lodashGet(this.props, 'walletAdditionalDetails.additionalErrorMessage', '').length > 0;
272-
const shouldAskForFullSSN = this.props.walletAdditionalDetails.shouldAskForFullSSN;
270+
|| !_.isEmpty(errors);
271+
const shouldAskForFullSSN = this.props.walletAdditionalDetails.errorCode === CONST.WALLET.ERROR.SSN;
273272
const {firstName, lastName} = PersonalDetails.extractFirstAndLastNameFromAvailableDetails(this.props.currentUserPersonalDetails);
273+
const errorMessage = _.isEmpty(errors) ? '' : _.last(_.values(errors));
274274

275275
return (
276276
<ScreenWrapper style={[styles.flex1]} keyboardAvoidingViewBehavior="height">
@@ -386,10 +386,11 @@ class AdditionalDetailsStep extends React.Component {
386386
onFixTheErrorsLinkPressed={() => {
387387
this.form.scrollTo({y: 0, animated: true});
388388
}}
389-
message={this.props.walletAdditionalDetails.additionalErrorMessage}
390-
isLoading={this.props.walletAdditionalDetails.loading}
389+
message={errorMessage}
390+
isLoading={this.props.walletAdditionalDetails.isLoading}
391391
buttonText={this.props.translate('common.saveAndContinue')}
392392
/>
393+
<OfflineIndicator containerStyles={[styles.mh5, styles.mb3]} />
393394
</FormScrollView>
394395
</View>
395396
</ScreenWrapper>

src/pages/EnablePayments/EnablePaymentsPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class EnablePaymentsPage extends React.Component {
5656
return <FullScreenLoadingIndicator />;
5757
}
5858

59-
if (this.props.userWallet.shouldShowFailedKYC) {
59+
if (this.props.userWallet.errorCode === CONST.WALLET.ERROR.KYC) {
6060
return (
6161
<ScreenWrapper style={[styles.flex1]} keyboardAvoidingViewBehavior="height">
6262
<HeaderWithCloseButton

src/pages/EnablePayments/userWalletPropTypes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
/** Status of wallet - e.g. SILVER or GOLD */
1010
tierName: PropTypes.string,
1111

12-
/** If we should show the FailedKYC view after the user submitted their info with a non fixable error */
13-
shouldShowFailedKYC: PropTypes.bool,
12+
/** Error code returned by the server */
13+
errorCode: PropTypes.string,
1414
}),
1515
};

0 commit comments

Comments
 (0)