Skip to content
Merged
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
14 changes: 12 additions & 2 deletions src/pages/iou/steps/IOUAmountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ class IOUAmountPage extends React.Component {
return amount.replace(/,/g, '');
}

/**
* 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) {
return amount === '.' ? '0.' : amount;
}

/**
* Update amount with number or Backspace pressed for BigNumberPad.
* Validate new amount with decimal number regex up to 6 digits and 2 decimal digit to enable Next button
Expand All @@ -145,7 +155,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: this.stripCommaFromAmount(amount)} : prevState;
});
}
Expand All @@ -158,7 +168,7 @@ class IOUAmountPage extends React.Component {
*/
updateAmount(text) {
this.setState((prevState) => {
const amount = this.replaceAllDigits(text, this.props.fromLocaleDigit);
const amount = this.addLeadingZero(this.replaceAllDigits(text, this.props.fromLocaleDigit));
return this.validateAmount(amount)
? {amount: this.stripCommaFromAmount(amount)}
: prevState;
Expand Down