add check for two decimals and fix showing error for fiat tip
This commit is contained in:
parent
8919182c0c
commit
86deadf099
2 changed files with 26 additions and 8 deletions
|
@ -186,8 +186,7 @@ function WalletSendTip(props: Props) {
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// Regex for number up to 8 decimal places
|
// Regex for number up to 8 decimal places
|
||||||
const regexp = RegExp(/^(\d*([.]\d{0,8})?)$/);
|
let regexp;
|
||||||
const validTipInput = regexp.test(String(tipAmount));
|
|
||||||
let tipError;
|
let tipError;
|
||||||
|
|
||||||
if (tipAmount === 0) {
|
if (tipAmount === 0) {
|
||||||
|
@ -198,8 +197,13 @@ function WalletSendTip(props: Props) {
|
||||||
|
|
||||||
// if it's not fiat, aka it's boost or lbc tip
|
// if it's not fiat, aka it's boost or lbc tip
|
||||||
else if (activeTab !== TAB_FIAT) {
|
else if (activeTab !== TAB_FIAT) {
|
||||||
|
regexp = RegExp(/^(\d*([.]\d{0,8})?)$/);
|
||||||
|
const validTipInput = regexp.test(String(tipAmount));
|
||||||
|
|
||||||
if (!validTipInput) {
|
if (!validTipInput) {
|
||||||
tipError = __('Amount must have no more than 8 decimal places');
|
tipError = __('Amount must have no more than 8 decimal places');
|
||||||
|
} else if (!validTipInput) {
|
||||||
|
tipError = __('Amount must have no more than 8 decimal places');
|
||||||
} else if (tipAmount === balance) {
|
} else if (tipAmount === balance) {
|
||||||
tipError = __('Please decrease the amount to account for transaction fees');
|
tipError = __('Please decrease the amount to account for transaction fees');
|
||||||
} else if (tipAmount > balance) {
|
} else if (tipAmount > balance) {
|
||||||
|
@ -209,7 +213,12 @@ function WalletSendTip(props: Props) {
|
||||||
}
|
}
|
||||||
// if tip fiat tab
|
// if tip fiat tab
|
||||||
} else {
|
} else {
|
||||||
if (tipAmount < 1) {
|
regexp = RegExp(/^(\d*([.]\d{0,2})?)$/);
|
||||||
|
const validTipInput = regexp.test(String(tipAmount));
|
||||||
|
|
||||||
|
if (!validTipInput) {
|
||||||
|
tipError = __('Amount must have no more than 2 decimal places');
|
||||||
|
} else if (tipAmount < 1) {
|
||||||
tipError = __('Amount must be at least one dollar');
|
tipError = __('Amount must be at least one dollar');
|
||||||
} else if (tipAmount > 1000) {
|
} else if (tipAmount > 1000) {
|
||||||
tipError = __('Amount cannot be over 1000 dollars');
|
tipError = __('Amount cannot be over 1000 dollars');
|
||||||
|
@ -544,7 +553,7 @@ function WalletSendTip(props: Props) {
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
}
|
}
|
||||||
className="form-field--price-amount"
|
className="form-field--price-amount"
|
||||||
error={tipError && activeTab !== TAB_FIAT}
|
error={tipError}
|
||||||
min="0"
|
min="0"
|
||||||
step="any"
|
step="any"
|
||||||
type="number"
|
type="number"
|
||||||
|
|
|
@ -120,9 +120,7 @@ function WalletTipAmountSelector(props: Props) {
|
||||||
// setHasSavedCard(false);
|
// setHasSavedCard(false);
|
||||||
// setCanReceiveFiatTip(true);
|
// setCanReceiveFiatTip(true);
|
||||||
|
|
||||||
const regexp = RegExp(/^(\d*([.]\d{0,8})?)$/);
|
let regexp, tipError;
|
||||||
const validTipInput = regexp.test(String(amount));
|
|
||||||
let tipError = '';
|
|
||||||
|
|
||||||
if (amount === 0) {
|
if (amount === 0) {
|
||||||
tipError = __('Amount must be a positive number');
|
tipError = __('Amount must be a positive number');
|
||||||
|
@ -132,6 +130,9 @@ function WalletTipAmountSelector(props: Props) {
|
||||||
|
|
||||||
// if it's not fiat, aka it's boost or lbc tip
|
// if it's not fiat, aka it's boost or lbc tip
|
||||||
else if (activeTab !== TAB_FIAT) {
|
else if (activeTab !== TAB_FIAT) {
|
||||||
|
regexp = RegExp(/^(\d*([.]\d{0,8})?)$/);
|
||||||
|
const validTipInput = regexp.test(String(amount));
|
||||||
|
|
||||||
if (!validTipInput) {
|
if (!validTipInput) {
|
||||||
tipError = __('Amount must have no more than 8 decimal places');
|
tipError = __('Amount must have no more than 8 decimal places');
|
||||||
} else if (amount === balance) {
|
} else if (amount === balance) {
|
||||||
|
@ -143,7 +144,12 @@ function WalletTipAmountSelector(props: Props) {
|
||||||
}
|
}
|
||||||
// if tip fiat tab
|
// if tip fiat tab
|
||||||
} else {
|
} else {
|
||||||
if (amount < 1) {
|
regexp = RegExp(/^(\d*([.]\d{0,2})?)$/);
|
||||||
|
const validTipInput = regexp.test(String(amount));
|
||||||
|
|
||||||
|
if (!validTipInput) {
|
||||||
|
tipError = __('Amount must have no more than 2 decimal places');
|
||||||
|
} else if (amount < 1) {
|
||||||
tipError = __('Amount must be at least one dollar');
|
tipError = __('Amount must be at least one dollar');
|
||||||
} else if (amount > 1000) {
|
} else if (amount > 1000) {
|
||||||
tipError = __('Amount cannot be over 1000 dollars');
|
tipError = __('Amount cannot be over 1000 dollars');
|
||||||
|
@ -154,8 +160,10 @@ function WalletTipAmountSelector(props: Props) {
|
||||||
onTipErrorChange(tipError);
|
onTipErrorChange(tipError);
|
||||||
}, [amount, balance, setTipError, activeTab]);
|
}, [amount, balance, setTipError, activeTab]);
|
||||||
|
|
||||||
|
// parse number as float and sets it in the parent component
|
||||||
function handleCustomPriceChange(amount: number) {
|
function handleCustomPriceChange(amount: number) {
|
||||||
const tipAmount = parseFloat(amount);
|
const tipAmount = parseFloat(amount);
|
||||||
|
|
||||||
onChange(tipAmount);
|
onChange(tipAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,6 +237,7 @@ function WalletTipAmountSelector(props: Props) {
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* custom number input form */}
|
||||||
{useCustomTip && (
|
{useCustomTip && (
|
||||||
<div className="comment__tip-input">
|
<div className="comment__tip-input">
|
||||||
<FormField
|
<FormField
|
||||||
|
|
Loading…
Reference in a new issue