Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eb76669
add the method
sketchydroide Aug 9, 2022
46567a4
adding the OnyxData
sketchydroide Aug 9, 2022
77f30de
calling api from the right js file
sketchydroide Aug 9, 2022
29ae567
adding onyxKey
sketchydroide Aug 9, 2022
30ad2f1
using the isLoading
sketchydroide Aug 9, 2022
86fe203
linter requested changes
sketchydroide Aug 10, 2022
c31819f
using the errors and error code
sketchydroide Aug 10, 2022
ed809ba
need to json stringify first?
sketchydroide Aug 10, 2022
7477c23
I think this is where the error code will be used
sketchydroide Aug 10, 2022
02cf2ca
Merge branch 'main' into afonseca_wallet_questions_refactor
sketchydroide Aug 19, 2022
eb67376
remove import duplicated
sketchydroide Aug 19, 2022
c67d184
linter removing extra line (bad merge?)
sketchydroide Aug 19, 2022
ed6a04a
fixing linter, I think it's good this time
sketchydroide Aug 19, 2022
1d76934
Merge branch 'main' into afonseca_wallet_questions_refactor
sketchydroide Aug 22, 2022
06c1432
Merge branch 'main' into afonseca_wallet_questions_refactor
sketchydroide Aug 30, 2022
ccf63b3
correcting the name to walletAdditionalDetails
sketchydroide Aug 30, 2022
66fc734
adding some TODO so when I'm done. I can remove this mehtod
sketchydroide Aug 30, 2022
b9c7d67
adding some handling for what happens when the answers were correct.
sketchydroide Aug 30, 2022
d9153aa
fix jest hopefully
sketchydroide Aug 30, 2022
f0d04db
adding some more logic
sketchydroide Aug 30, 2022
de24b00
localize is not a mehtod
sketchydroide Aug 30, 2022
4cf33e7
Merge branch 'main' into afonseca_wallet_questions_refactor
sketchydroide Aug 30, 2022
31b42d9
fixing linter
sketchydroide Aug 30, 2022
160da4e
Remove TODOs and cleanup
MariaHCD Aug 31, 2022
539ecee
Clean up props and remove un-needed logic
MariaHCD Aug 31, 2022
f42ed2a
Fix command params for answerQuestionsForWallet
MariaHCD Aug 31, 2022
3595d65
Don't show redundant error
MariaHCD Aug 31, 2022
f1f621e
Fix lint errors
MariaHCD Aug 31, 2022
bc6be2d
Add offline indicator and display error messages
MariaHCD Sep 1, 2022
a8bc734
Update param type
MariaHCD Sep 15, 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
1 change: 1 addition & 0 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export {
export {
openOnfidoFlow,
activateWallet,
answerQuestionsForWallet,
verifyIdentity,
acceptWalletTerms,
} from './Wallet';
Expand Down
37 changes: 37 additions & 0 deletions src/libs/actions/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,42 @@ function updateCurrentStep(currentStep) {
Onyx.merge(ONYXKEYS.USER_WALLET, {currentStep});
}

/**
* @param {Array} answers
* @param {String} idNumber
*/
function answerQuestionsForWallet(answers, idNumber) {
const idologyAnswers = JSON.stringify(answers);
API.write('AnswerQuestionsForWallet',
{
idologyAnswers,
idNumber,
},
{
optimisticData: [{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.WALLET_ADDITIONAL_DETAILS,
value: {
isLoading: true,
},
}],
successData: [{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.WALLET_ADDITIONAL_DETAILS,
value: {
isLoading: false,
},
}],
failureData: [{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.WALLET_ADDITIONAL_DETAILS,
value: {
isLoading: false,
},
}],
});
}

export {
openOnfidoFlow,
activateWallet,
Expand All @@ -539,6 +575,7 @@ export {
setAdditionalDetailsQuestions,
buildIdologyError,
updateCurrentStep,
answerQuestionsForWallet,
updatePersonalDetails,
verifyIdentity,
acceptWalletTerms,
Expand Down
51 changes: 36 additions & 15 deletions src/pages/EnablePayments/IdologyQuestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import PropTypes from 'prop-types';
import {
View,
} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import RadioButtons from '../../components/RadioButtons';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import styles from '../../styles/styles';
import * as BankAccounts from '../../libs/actions/BankAccounts';
import CONST from '../../CONST';
import Text from '../../components/Text';
import TextLink from '../../components/TextLink';
import FormScrollView from '../../components/FormScrollView';
import FormAlertWithSubmitButton from '../../components/FormAlertWithSubmitButton';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import OfflineIndicator from '../../components/OfflineIndicator';

const MAX_SKIP = 1;
const SKIP_QUESTION_TEXT = 'Skip Question';
Expand All @@ -30,11 +34,23 @@ const propTypes = {

/** ID from Idology, referencing those questions */
idNumber: PropTypes.string,

walletAdditionalDetails: PropTypes.shape({
/** Are we waiting for a response? */
isLoading: PropTypes.bool,

/** Any additional error message to show */
errors: PropTypes.objectOf(PropTypes.string),

/** What error do we need to handle */
errorCode: PropTypes.string,
}),
};

const defaultProps = {
questions: [],
idNumber: '',
walletAdditionalDetails: {},
};

class IdologyQuestions extends React.Component {
Expand All @@ -54,9 +70,6 @@ class IdologyQuestions extends React.Component {

/** Any error message */
errorMessage: '',

Comment thread
MariaHCD marked this conversation as resolved.
/** Did the user just submitted all his answers? */
isLoading: false,
};
}

Expand Down Expand Up @@ -103,13 +116,8 @@ class IdologyQuestions extends React.Component {
}
}

BankAccounts.activateWallet(CONST.WALLET.STEP.ADDITIONAL_DETAILS, {
idologyAnswers: {
answers,
idNumber: this.props.idNumber,
},
});
return {answers, isLoading: true};
BankAccounts.answerQuestionsForWallet(answers, this.props.idNumber);
return {answers};
}

// Else, show next question
Expand All @@ -134,6 +142,10 @@ class IdologyQuestions extends React.Component {
};
}));

const errors = lodashGet(this.props, 'walletAdditionalDetails.errors', {});
const isErrorVisible = this.state.errorMessage || !_.isEmpty(errors);
const errorMessage = _.isEmpty(errors) ? this.state.errorMessage : _.last(_.values(errors));

return (
<View style={[styles.flex1]}>
<View style={[styles.ph5]}>
Expand All @@ -150,20 +162,22 @@ class IdologyQuestions extends React.Component {
<Text style={[styles.textStrong, styles.mb5]}>{question.prompt}</Text>
<RadioButtons
items={possibleAnswers}
key={questionIndex}
onPress={answer => this.chooseAnswer(questionIndex, answer)}
/>
</View>

<FormAlertWithSubmitButton
isAlertVisible={Boolean(this.state.errorMessage)}
Comment thread
MariaHCD marked this conversation as resolved.
isAlertVisible={Boolean(isErrorVisible)}
onSubmit={this.submitAnswers}
onFixTheErrorsLinkPressed={() => {
this.form.scrollTo({y: 0, animated: true});
}}
message={this.state.errorMessage}
isLoading={this.state.isLoading}
message={errorMessage}
isLoading={this.props.walletAdditionalDetails.isLoading}
buttonText={this.props.translate('common.saveAndContinue')}
/>
<OfflineIndicator containerStyles={[styles.mh5, styles.mb3]} />
</FormScrollView>
</View>
);
Expand All @@ -172,4 +186,11 @@ class IdologyQuestions extends React.Component {

IdologyQuestions.propTypes = propTypes;
IdologyQuestions.defaultProps = defaultProps;
export default withLocalize(IdologyQuestions);
export default compose(
withLocalize,
withOnyx({
walletAdditionalDetails: {
key: ONYXKEYS.WALLET_ADDITIONAL_DETAILS,
},
}),
)(IdologyQuestions);