2018-09-10 09:55:26 -07:00
|
|
|
export function getAmountError(amount: number, max: number = Infinity) {
|
|
|
|
if (amount < 0) {
|
|
|
|
return 'Amount must be a positive number';
|
|
|
|
} else if (
|
|
|
|
amount.toFixed(3).length < amount.toString().length ||
|
|
|
|
amount.toString().includes('1e')
|
|
|
|
) {
|
|
|
|
return 'Must be in increments of 0.001';
|
|
|
|
} else if (amount > max) {
|
2018-12-27 09:41:26 -08:00
|
|
|
return `Cannot exceed maximum (${max} ZEC)`;
|
2018-09-10 09:55:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2018-09-20 11:58:47 -07:00
|
|
|
|
2018-11-09 11:54:04 -08:00
|
|
|
export function isValidEmail(email: string): boolean {
|
|
|
|
return /\S+@\S+\.\S+/.test(email);
|
|
|
|
}
|
2018-12-14 11:36:22 -08:00
|
|
|
|
2019-02-05 12:26:37 -08:00
|
|
|
// Uses simple regex to validate addresses, doesn't check checksum or network
|
2018-12-14 11:36:22 -08:00
|
|
|
export function isValidAddress(address: string): boolean {
|
2019-02-05 12:26:37 -08:00
|
|
|
// T address
|
|
|
|
if (/^t[a-zA-Z0-9]{34}$/.test(address)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Sprout address
|
|
|
|
if (/^z[a-zA-Z0-9]{94}$/.test(address)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Sapling address
|
|
|
|
if (/^z(s)?(reg)?(testsapling)?[a-zA-Z0-9]{76}$/.test(address)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2018-12-14 11:36:22 -08:00
|
|
|
}
|