Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/validation.js
Show All 21 Lines | if (isNaN(testedAmount)) { | ||||
error = 'Amount must be a number'; | error = 'Amount must be a number'; | ||||
} else if (testedAmount.lte(0)) { | } else if (testedAmount.lte(0)) { | ||||
error = 'Amount must be greater than 0'; | error = 'Amount must be greater than 0'; | ||||
} else if (testedAmount.lt(currency.dust)) { | } else if (testedAmount.lt(currency.dust)) { | ||||
error = `Send amount must be at least ${currency.dust} ${currency.ticker}`; | error = `Send amount must be at least ${currency.dust} ${currency.ticker}`; | ||||
} else if (testedAmount.gt(totalCashBalance)) { | } else if (testedAmount.gt(totalCashBalance)) { | ||||
error = `Amount cannot exceed your ${currency.ticker} balance`; | error = `Amount cannot exceed your ${currency.ticker} balance`; | ||||
} else if (!isNaN(testedAmount) && testedAmount.toString().includes('.')) { | } else if (!isNaN(testedAmount) && testedAmount.toString().includes('.')) { | ||||
if (testedAmount.toString().split('.')[1].length > 8) { | if ( | ||||
error = `${currency.ticker} transactions do not support more than 8 decimal places`; | testedAmount.toString().split('.')[1].length > currency.cashDecimals | ||||
) { | |||||
error = `${currency.ticker} transactions do not support more than ${currency.cashDecimals} decimal places`; | |||||
} | } | ||||
} | } | ||||
// return false if no error, or string error msg if error | // return false if no error, or string error msg if error | ||||
return error; | return error; | ||||
}; | }; | ||||
export const fiatToCrypto = (fiatAmount, fiatPrice) => { | export const fiatToCrypto = (fiatAmount, fiatPrice) => { | ||||
// Return a string with no more than 8 decimal places | |||||
let cryptoAmount = new BigNumber(fiatAmount) | let cryptoAmount = new BigNumber(fiatAmount) | ||||
.div(new BigNumber(fiatPrice)) | .div(new BigNumber(fiatPrice)) | ||||
.toFixed(8); | .toFixed(currency.cashDecimals); | ||||
return cryptoAmount; | return cryptoAmount; | ||||
}; | }; |