Skip to content

Commit

Permalink
Merge pull request #17547 from akinwale/task-16974
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisl authored Apr 19, 2023
2 parents d40a139 + bea7af0 commit 410ccc6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/pages/iou/steps/MoneyRequestAmountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class MoneyRequestAmountPage extends React.Component {
this.updateLongPressHandlerState = this.updateLongPressHandlerState.bind(this);
this.updateAmount = this.updateAmount.bind(this);
this.stripCommaFromAmount = this.stripCommaFromAmount.bind(this);
this.stripSpacesFromAmount = this.stripSpacesFromAmount.bind(this);
this.focusTextInput = this.focusTextInput.bind(this);
this.navigateToCurrencySelectionPage = this.navigateToCurrencySelectionPage.bind(this);
this.amountViewID = 'amountView';
Expand Down Expand Up @@ -126,13 +127,16 @@ class MoneyRequestAmountPage extends React.Component {
* @returns {Object}
*/
getNewState(prevState, newAmount) {
if (!this.validateAmount(newAmount)) {
// Remove spaces from the newAmount value because Safari on iOS adds spaces when pasting a copied value
// More info: https://github.com/Expensify/App/issues/16974
const newAmountWithoutSpaces = this.stripSpacesFromAmount(newAmount);
if (!this.validateAmount(newAmountWithoutSpaces)) {
// Use a shallow copy of selection to trigger setSelection
// More info: https://github.com/Expensify/App/issues/16385
return {amount: prevState.amount, selection: {...prevState.selection}};
}
const selection = this.getNewSelection(prevState.selection, prevState.amount.length, newAmount.length);
return {amount: this.stripCommaFromAmount(newAmount), selection};
const selection = this.getNewSelection(prevState.selection, prevState.amount.length, newAmountWithoutSpaces.length);
return {amount: this.stripCommaFromAmount(newAmountWithoutSpaces), selection};
}

/**
Expand Down Expand Up @@ -194,6 +198,16 @@ class MoneyRequestAmountPage extends React.Component {
return amount.replace(/,/g, '');
}

/**
* Strip spaces from the amount
*
* @param {String} amount
* @returns {String}
*/
stripSpacesFromAmount(amount) {
return amount.replace(/\s+/g, '');
}

/**
* Adds a leading zero to the amount if user entered just the decimal separator
*
Expand Down

0 comments on commit 410ccc6

Please sign in to comment.