Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ export default {
send: ({amount}) => `Send ${amount}`,
choosePaymentMethod: 'Choose payment method:',
noReimbursableExpenses: 'This report has an invalid amount',
error: {
invalidAmount: 'Invalid Amount',
invalidSplit: 'Splits amount does not equal total amount',
other: 'Unexpected error, please try again later',
},
},
reportDetailsPage: {
notificationPreferencesDescription: 'How often should we notify you when there are new messages to catch up on in this room?',
Expand Down
5 changes: 5 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ export default {
send: ({amount}) => `Enviar ${amount}`,
choosePaymentMethod: 'Elige el método de pago:',
noReimbursableExpenses: 'El monto de este informe es inválido',
error: {
invalidAmount: 'Monto no válido',
invalidSplit: 'La suma de las partes no equivale al monto total',
other: 'Error inesperado, por favor inténtalo más tarde',
},
},
reportDetailsPage: {
notificationPreferencesDescription: 'Cada cuanto tiempo quieres que te avisemos que hay nuevos mensajes en este canal?',
Expand Down
7 changes: 7 additions & 0 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ Network.registerResponseHandler((queuedRequest, response) => {
return;
}

if (response.jsonCode === 405 || response.jsonCode === 404) {
// IOU Split & Request money transactions failed due to invalid amount(405) or unable to split(404)
// It's a failure, so reject the queued request
queuedRequest.reject(response);
return;
}

queuedRequest.resolve(response);
});

Expand Down
30 changes: 30 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ function getIOUReportsForNewTransaction(requestParams) {
.finally(() => Onyx.merge(ONYXKEYS.IOU, {loading: false, creatingIOUTransaction: false}));
}

/**
* Returns IOU Transaction Error Messages
* @param {Object} error
*/

function getIOUErrorMessage(error) {
if (error && error.jsonCode) {
if (error.jsonCode === 405) {
return translateLocal('iou.error.invalidAmount');
} if (error.jsonCode === 404) {
return translateLocal('iou.error.invalidSplit');
}
}
return translateLocal('iou.error.other');
}

/**
* Creates IOUSplit Transaction
* @param {Object} params
Expand All @@ -69,6 +85,13 @@ function createIOUTransaction(params) {
.then((data) => {
getIOUReportsForNewTransaction([data]);
Navigation.navigate(ROUTES.getReportRoute(data.chatReportID));
})?.catch((error) => {
Onyx.merge(ONYXKEYS.IOU, {
loading: false,
creatingIOUTransaction: false,
error: true,
});
Growl.error(getIOUErrorMessage(error));
});
}

Expand Down Expand Up @@ -111,6 +134,13 @@ function createIOUSplit(params) {
}
getIOUReportsForNewTransaction(reportParams);
Navigation.navigate(ROUTES.getReportRoute(chatReportID));
})?.catch((error) => {
Onyx.merge(ONYXKEYS.IOU, {
loading: false,
creatingIOUTransaction: false,
error: true,
});
Growl.error(getIOUErrorMessage(error));
});
}

Expand Down
11 changes: 11 additions & 0 deletions src/pages/iou/IOUModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class IOUModal extends Component {
this.addParticipants = this.addParticipants.bind(this);
this.createTransaction = this.createTransaction.bind(this);
this.updateComment = this.updateComment.bind(this);
this.handleTransactionError = this.handleTransactionError.bind(this);
const participants = lodashGet(props, 'report.participants', []);
const participantsWithDetails = getPersonalDetailsForLogins(participants, props.personalDetails)
.map(personalDetails => ({
Expand Down Expand Up @@ -140,6 +141,11 @@ class IOUModal extends Component {
Navigation.dismissModal();
}

// If transaction fails, handling it here
if (prevProps.iou.creatingIOUTransaction && this.props.iou.error === true) {
this.handleTransactionError();
}

if (prevProps.iou.selectedCurrencyCode
!== this.props.iou.selectedCurrencyCode) {
setIOUSelectedCurrency(this.props.iou.selectedCurrencyCode);
Expand Down Expand Up @@ -248,6 +254,11 @@ class IOUModal extends Component {
});
}

handleTransactionError() {
// Navigating to Enter Amount Page
this.setState({currentStepIndex: 0});
}

render() {
const currentStep = this.steps[this.state.currentStepIndex];
const reportID = lodashGet(this.props, 'route.params.reportID', '');
Expand Down