From 1e56faea74b922b4e63802607f5853178bd93e62 Mon Sep 17 00:00:00 2001 From: Yevhenii Voloshchak Date: Wed, 20 Jul 2022 12:52:46 +0300 Subject: [PATCH 1/4] Add zero to amount if user entered just the decimal separator --- src/pages/iou/steps/IOUAmountPage.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/steps/IOUAmountPage.js b/src/pages/iou/steps/IOUAmountPage.js index 90d00cf77e04..f8d5870e28d2 100755 --- a/src/pages/iou/steps/IOUAmountPage.js +++ b/src/pages/iou/steps/IOUAmountPage.js @@ -54,6 +54,7 @@ class IOUAmountPage extends React.Component { this.updateAmount = this.updateAmount.bind(this); this.focusTextInput = this.focusTextInput.bind(this); this.navigateToCurrencySelectionPage = this.navigateToCurrencySelectionPage.bind(this); + this.addLeadingZero = this.addLeadingZero.bind(this); this.state = { amount: props.selectedAmount.replace('.', this.props.fromLocaleDigit('.')), @@ -134,7 +135,7 @@ class IOUAmountPage extends React.Component { } this.setState((prevState) => { - const amount = `${prevState.amount}${key}`; + const amount = this.addLeadingZero(`${prevState.amount}${key}`); return this.validateAmount(amount) ? {amount} : prevState; }); } @@ -146,7 +147,22 @@ class IOUAmountPage extends React.Component { * @param {String} amount - Changed amount from user input */ updateAmount(amount) { - this.setState(prevState => (this.validateAmount(amount) ? {amount} : prevState)); + const newAmount = this.addLeadingZero(amount); + this.setState(prevState => (this.validateAmount(newAmount) ? {amount: newAmount} : prevState)); + } + + /** + * Adds a leading zero to amount if user entered just the decimal separator + * + * @param {String} amount - Changed amount from user input + * @returns {String} + */ + addLeadingZero(amount) { + const decimalSeparator = this.props.fromLocaleDigit('.'); + if (amount === decimalSeparator) { + return `0${decimalSeparator}`; + } + return amount; } navigateToCurrencySelectionPage() { From 9ffa6228e28a872fa92af9e72b77141e6077c447 Mon Sep 17 00:00:00 2001 From: Yevhenii Voloshchak Date: Wed, 20 Jul 2022 13:00:10 +0300 Subject: [PATCH 2/4] Do not bind this to addLeadingZero --- src/pages/iou/steps/IOUAmountPage.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/iou/steps/IOUAmountPage.js b/src/pages/iou/steps/IOUAmountPage.js index f8d5870e28d2..545fd940bb77 100755 --- a/src/pages/iou/steps/IOUAmountPage.js +++ b/src/pages/iou/steps/IOUAmountPage.js @@ -54,7 +54,6 @@ class IOUAmountPage extends React.Component { this.updateAmount = this.updateAmount.bind(this); this.focusTextInput = this.focusTextInput.bind(this); this.navigateToCurrencySelectionPage = this.navigateToCurrencySelectionPage.bind(this); - this.addLeadingZero = this.addLeadingZero.bind(this); this.state = { amount: props.selectedAmount.replace('.', this.props.fromLocaleDigit('.')), From 94f918ff40f8155d3f9f1476d0e188f8df05bd64 Mon Sep 17 00:00:00 2001 From: Yevhenii Voloshchak Date: Wed, 27 Jul 2022 17:02:59 +0300 Subject: [PATCH 3/4] Fix linter error --- src/pages/iou/steps/IOUAmountPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/steps/IOUAmountPage.js b/src/pages/iou/steps/IOUAmountPage.js index 98d4fca480ea..f9d6c3b5104b 100755 --- a/src/pages/iou/steps/IOUAmountPage.js +++ b/src/pages/iou/steps/IOUAmountPage.js @@ -126,7 +126,7 @@ class IOUAmountPage extends React.Component { stripCommaFromAmount(amount) { return amount.replace(/,/g, ''); } - + /** * Adds a leading zero to amount if user entered just the decimal separator * From 723e8155f9f82c88457df5deb1b38ce7db3eaeb8 Mon Sep 17 00:00:00 2001 From: Yevhenii Voloshchak Date: Thu, 28 Jul 2022 21:29:44 +0300 Subject: [PATCH 4/4] Cleanup --- src/pages/iou/steps/IOUAmountPage.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/pages/iou/steps/IOUAmountPage.js b/src/pages/iou/steps/IOUAmountPage.js index f9d6c3b5104b..28ca5c68034c 100755 --- a/src/pages/iou/steps/IOUAmountPage.js +++ b/src/pages/iou/steps/IOUAmountPage.js @@ -128,16 +128,13 @@ class IOUAmountPage extends React.Component { } /** - * Adds a leading zero to amount if user entered just the decimal separator + * Adds a leading zero to the amount if user entered just the decimal separator * * @param {String} amount - Changed amount from user input * @returns {String} */ addLeadingZero(amount) { - if (amount === '.') { - return '0.'; - } - return amount; + return amount === '.' ? '0.' : amount; } /**