Skip to content

Commit e7503a0

Browse files
author
Justice Arthur
authored
Merge pull request #10443 from Expensify/francois-refactorAcceptWalletTerms
Refactor Terms step of Wallet_Activate into `AcceptWalletTerms`
2 parents ca4ba68 + 1676919 commit e7503a0

File tree

8 files changed

+134
-38
lines changed

8 files changed

+134
-38
lines changed

src/languages/en.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ export default {
692692
},
693693
activateStep: {
694694
headerTitle: 'Enable payments',
695-
activated: 'Your Expensify Wallet is ready to use.',
695+
activatedTitle: 'Wallet activated!',
696+
activatedMessage: 'Congrats, your wallet is set up and ready to make payments.',
696697
checkBackLater: 'We\'re still reviewing your information. Please check back later.',
697698
},
698699
companyStep: {

src/languages/es.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,8 @@ export default {
694694
},
695695
activateStep: {
696696
headerTitle: 'Habilitar pagos',
697-
activated: 'Su billetera Expensify está lista para usar.',
697+
activatedTitle: '¡Billetera activada!',
698+
activatedMessage: 'Felicidades, tu Billetera está configurada y lista para hacer pagos.',
698699
checkBackLater: 'Todavía estamos revisando tu información. Por favor, vuelva más tarde.',
699700
},
700701
companyStep: {

src/libs/actions/BankAccounts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export {
3030
activateWallet,
3131
fetchUserWallet,
3232
verifyIdentity,
33+
acceptWalletTerms,
3334
} from './Wallet';
3435

3536
function clearPersonalBankAccount() {

src/libs/actions/Wallet.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,47 @@ function verifyIdentity(parameters) {
434434
});
435435
}
436436

437+
/**
438+
* Complete the "Accept Terms" step of the wallet activation flow.
439+
*
440+
* @param {Object} parameters
441+
* @param {Boolean} parameters.hasAcceptedTerms
442+
*/
443+
function acceptWalletTerms(parameters) {
444+
const optimisticData = [
445+
{
446+
onyxMethod: CONST.ONYX.METHOD.MERGE,
447+
key: ONYXKEYS.USER_WALLET,
448+
value: {
449+
shouldShowWalletActivationSuccess: true,
450+
},
451+
},
452+
];
453+
454+
const successData = [
455+
{
456+
onyxMethod: CONST.ONYX.METHOD.MERGE,
457+
key: ONYXKEYS.WALLET_TERMS,
458+
value: {
459+
errors: null,
460+
},
461+
},
462+
];
463+
464+
const failureData = [
465+
{
466+
onyxMethod: CONST.ONYX.METHOD.MERGE,
467+
key: ONYXKEYS.USER_WALLET,
468+
value: {
469+
shouldShowWalletActivationSuccess: null,
470+
shouldShowFailedKYC: true,
471+
},
472+
},
473+
];
474+
475+
API.write('AcceptWalletTerms', {hasAcceptedTerms: parameters.hasAcceptedTerms}, {optimisticData, successData, failureData});
476+
}
477+
437478
/**
438479
* Fetches information about a user's Expensify Wallet
439480
*
@@ -481,4 +522,5 @@ export {
481522
updateCurrentStep,
482523
updatePersonalDetails,
483524
verifyIdentity,
525+
acceptWalletTerms,
484526
};

src/pages/EnablePayments/ActivateStep.js

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import styles from '../../styles/styles';
99
import userWalletPropTypes from './userWalletPropTypes';
1010
import CONST from '../../CONST';
1111
import Text from '../../components/Text';
12+
import Icon from '../../components/Icon';
13+
import * as Illustrations from '../../components/Icon/Illustrations';
14+
import defaultTheme from '../../styles/themes/default';
15+
import FixedFooter from '../../components/FixedFooter';
16+
import Button from '../../components/Button';
17+
import * as PaymentMethods from '../../libs/actions/PaymentMethods';
1218

1319
const propTypes = {
1420
...withLocalizePropTypes,
@@ -21,24 +27,64 @@ const defaultProps = {
2127
userWallet: {},
2228
};
2329

24-
const ActivateStep = props => (
25-
<ScreenWrapper>
26-
<HeaderWithCloseButton
27-
title={props.translate('activateStep.headerTitle')}
28-
onCloseButtonPress={() => Navigation.dismissModal()}
29-
shouldShowBackButton
30-
onBackButtonPress={() => Navigation.goBack()}
31-
/>
32-
<View style={[styles.mh5, styles.flex1]}>
33-
{props.userWallet.tierName === CONST.WALLET.TIER_NAME.GOLD && (
34-
<Text>{props.translate('activateStep.activated')}</Text>
35-
)}
36-
{props.userWallet.tierName === CONST.WALLET.TIER_NAME.SILVER && (
37-
<Text>{props.translate('activateStep.checkBackLater')}</Text>
38-
)}
39-
</View>
40-
</ScreenWrapper>
41-
);
30+
class ActivateStep extends React.Component {
31+
constructor(props) {
32+
super(props);
33+
34+
this.renderGoldWalletActivationStep = this.renderGoldWalletActivationStep.bind(this);
35+
}
36+
37+
renderGoldWalletActivationStep() {
38+
return (
39+
<>
40+
<View style={[styles.pageWrapper, styles.flex1, styles.flexColumn, styles.alignItemsCenter, styles.justifyContentCenter]}>
41+
<Icon
42+
src={Illustrations.TadaBlue}
43+
height={100}
44+
width={100}
45+
fill={defaultTheme.iconSuccessFill}
46+
/>
47+
<View style={[styles.ph5]}>
48+
<Text style={[styles.mt5, styles.h1, styles.textAlignCenter]}>
49+
{this.props.translate('activateStep.activatedTitle')}
50+
</Text>
51+
<Text style={[styles.mt3, styles.textAlignCenter]}>
52+
{this.props.translate('activateStep.activatedMessage')}
53+
</Text>
54+
</View>
55+
</View>
56+
<FixedFooter>
57+
<Button
58+
text={this.props.translate('common.continue')}
59+
onPress={PaymentMethods.continueSetup}
60+
style={[styles.mt4]}
61+
iconStyles={[styles.mr5]}
62+
success
63+
/>
64+
</FixedFooter>
65+
</>
66+
);
67+
}
68+
69+
render() {
70+
return (
71+
<ScreenWrapper>
72+
<HeaderWithCloseButton
73+
title={this.props.translate('activateStep.headerTitle')}
74+
onCloseButtonPress={() => Navigation.dismissModal()}
75+
shouldShowBackButton
76+
onBackButtonPress={() => Navigation.goBack()}
77+
/>
78+
<View style={styles.flex1}>
79+
{this.props.userWallet.tierName === CONST.WALLET.TIER_NAME.GOLD && this.renderGoldWalletActivationStep()}
80+
{this.props.userWallet.tierName === CONST.WALLET.TIER_NAME.SILVER && (
81+
<Text>{this.props.translate('activateStep.checkBackLater')}</Text>
82+
)}
83+
</View>
84+
</ScreenWrapper>
85+
);
86+
}
87+
}
4288

4389
ActivateStep.propTypes = propTypes;
4490
ActivateStep.defaultProps = defaultProps;

src/pages/EnablePayments/EnablePaymentsPage.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class EnablePaymentsPage extends React.Component {
7070
</ScreenWrapper>
7171
);
7272
}
73+
if (this.props.userWallet.shouldShowWalletActivationSuccess) {
74+
return (
75+
<ActivateStep userWallet={this.props.userWallet} />
76+
);
77+
}
7378

7479
const currentStep = this.props.userWallet.currentStep || CONST.WALLET.STEP.ADDITIONAL_DETAILS;
7580

src/pages/EnablePayments/TermsStep.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,34 @@ import React from 'react';
22
import {ScrollView} from 'react-native';
33
import {withOnyx} from 'react-native-onyx';
44
import PropTypes from 'prop-types';
5+
import lodashGet from 'lodash/get';
6+
import _ from 'underscore';
57
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
68
import Navigation from '../../libs/Navigation/Navigation';
79
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
810
import styles from '../../styles/styles';
9-
import Button from '../../components/Button';
1011
import * as BankAccounts from '../../libs/actions/BankAccounts';
11-
import CONST from '../../CONST';
1212
import TextLink from '../../components/TextLink';
1313
import compose from '../../libs/compose';
1414
import ONYXKEYS from '../../ONYXKEYS';
1515
import CheckboxWithLabel from '../../components/CheckboxWithLabel';
1616
import Text from '../../components/Text';
1717
import ShortTermsForm from './TermsPage/ShortTermsForm';
1818
import LongTermsForm from './TermsPage/LongTermsForm';
19+
import FormAlertWithSubmitButton from '../../components/FormAlertWithSubmitButton';
1920

2021
const propTypes = {
2122
/** Comes from Onyx. Information about the terms for the wallet */
2223
walletTerms: PropTypes.shape({
23-
/** Whether or not the information is currently loading */
24-
loading: PropTypes.bool,
24+
/** Any additional error message to show */
25+
errors: PropTypes.objectOf(PropTypes.string),
2526
}),
2627
...withLocalizePropTypes,
2728
};
2829

2930
const defaultProps = {
3031
walletTerms: {
31-
loading: false,
32+
errors: null,
3233
},
3334
};
3435

@@ -64,6 +65,8 @@ class TermsStep extends React.Component {
6465
}
6566

6667
render() {
68+
const errors = lodashGet(this.props, 'walletTerms.errors', {});
69+
const errorMessage = this.state.error ? this.props.translate('common.error.acceptedTerms') : (_.last(_.values(errors)) || '');
6770
return (
6871
<>
6972
<HeaderWithCloseButton
@@ -107,29 +110,24 @@ class TermsStep extends React.Component {
107110
</>
108111
)}
109112
/>
110-
{this.state.error && (
111-
<Text style={[styles.formError, styles.mb2]}>
112-
{this.props.translate('common.error.acceptedTerms')}
113-
</Text>
114-
)}
115-
<Button
116-
success
117-
style={[styles.mv4]}
118-
text={this.props.translate('termsStep.enablePayments')}
119-
isLoading={this.props.walletTerms.loading}
120-
onPress={() => {
113+
<FormAlertWithSubmitButton
114+
buttonText={this.props.translate('termsStep.enablePayments')}
115+
onSubmit={() => {
121116
if (!this.state.hasAcceptedDisclosure
122117
|| !this.state.hasAcceptedPrivacyPolicyAndWalletAgreement) {
123118
this.setState({error: true});
124119
return;
125120
}
126121

127122
this.setState({error: false});
128-
BankAccounts.activateWallet(CONST.WALLET.STEP.TERMS, {
123+
BankAccounts.acceptWalletTerms({
129124
hasAcceptedTerms: this.state.hasAcceptedDisclosure
130125
&& this.state.hasAcceptedPrivacyPolicyAndWalletAgreement,
131126
});
132127
}}
128+
message={errorMessage}
129+
isAlertVisible={this.state.error || !_.isEmpty(errors)}
130+
containerStyles={[styles.mh0, styles.mv4]}
133131
/>
134132
</ScrollView>
135133
</>
@@ -144,7 +142,6 @@ export default compose(
144142
withOnyx({
145143
walletTerms: {
146144
key: ONYXKEYS.WALLET_TERMS,
147-
initWithStoredValues: false,
148145
},
149146
}),
150147
)(TermsStep);

src/pages/EnablePayments/userWalletPropTypes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ export default PropTypes.shape({
1919

2020
/** Status of wallet - e.g. SILVER or GOLD */
2121
tierName: PropTypes.string,
22+
23+
/** Whether we should show the ActivateStep success view after the user finished the KYC flow */
24+
shouldShowWalletActivationSuccess: PropTypes.bool,
2225
});

0 commit comments

Comments
 (0)