Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/validation.js
import BigNumber from 'bignumber.js'; | import BigNumber from 'bignumber.js'; | ||||
import { currency } from '@components/Common/Ticker.js'; | import { currency } from '@components/Common/Ticker.js'; | ||||
import { fromSmallestDenomination } from '@utils/cashMethods'; | import { fromSmallestDenomination } from '@utils/cashMethods'; | ||||
// Validate cash amount | // Validate cash amount | ||||
export const shouldRejectAmountInput = ( | export const shouldRejectAmountInput = ( | ||||
cashAmount, | cashAmount, | ||||
selectedCurrency, | selectedCurrency, | ||||
fiatPrice, | fiatPrice, | ||||
totalCashBalance, | totalCashBalance, | ||||
) => { | ) => { | ||||
// Take cashAmount as input, a string from form input | // Take cashAmount as input, a string from form input | ||||
let error = false; | let error = false; | ||||
let testedAmount = new BigNumber(cashAmount); | let testedAmount = new BigNumber(cashAmount); | ||||
if (selectedCurrency === 'USD') { | if (selectedCurrency !== currency.ticker) { | ||||
// Ensure no more than 8 decimal places | // Ensure no more than currency.cashDecimals decimal places | ||||
testedAmount = new BigNumber(fiatToCrypto(cashAmount, fiatPrice)); | testedAmount = new BigNumber(fiatToCrypto(cashAmount, fiatPrice)); | ||||
} | } | ||||
// Validate value for > 0 | // Validate value for > 0 | ||||
if (isNaN(testedAmount)) { | 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'; | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | return ( | ||||
'documentUri' in tokenStats && | 'documentUri' in tokenStats && | ||||
'containsBaton' in tokenStats && | 'containsBaton' in tokenStats && | ||||
'initialTokenQty' in tokenStats && | 'initialTokenQty' in tokenStats && | ||||
'totalMinted' in tokenStats && | 'totalMinted' in tokenStats && | ||||
'totalBurned' in tokenStats && | 'totalBurned' in tokenStats && | ||||
'circulatingSupply' in tokenStats | 'circulatingSupply' in tokenStats | ||||
); | ); | ||||
}; | }; | ||||
export const isValidCashtabSettings = settings => { | |||||
try { | |||||
const isValid = | |||||
typeof settings === 'object' && | |||||
settings.fiatCurrency && | |||||
currency.settingsValidation.fiatCurrency.includes( | |||||
settings.fiatCurrency, | |||||
); | |||||
if (isValid) { | |||||
return true; | |||||
} | |||||
return false; | |||||
} catch (err) { | |||||
return false; | |||||
} | |||||
}; |