2017-12-01 04:51:55 +01:00
|
|
|
// these don't need to be exact
|
2017-12-28 00:48:11 +01:00
|
|
|
// Shapeshift does a more thorough check on validity
|
|
|
|
// just general matches to prevent unnecessary api calls
|
2017-12-01 04:51:55 +01:00
|
|
|
export const coinRegexPatterns = {
|
|
|
|
BTC: /^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$/,
|
|
|
|
BCH: /^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$/,
|
|
|
|
ETH: /^(0x)?[0-9a-fA-F]{40}$/,
|
|
|
|
DASH: /^X([0-9a-zA-Z]){33}/,
|
|
|
|
LTC: /^L[a-zA-Z0-9]{26,33}$/,
|
|
|
|
XMR: /^4[0-9ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{94}$/,
|
|
|
|
};
|
|
|
|
|
|
|
|
const validateAddress = (coinType, address) => {
|
|
|
|
if (!coinType || !address) return false;
|
|
|
|
|
|
|
|
const coinRegex = coinRegexPatterns[coinType.toUpperCase()];
|
|
|
|
if (!coinRegex) return false;
|
|
|
|
|
|
|
|
return coinRegex.test(address);
|
|
|
|
};
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const validateShapeShiftForm = vals => {
|
2017-12-13 22:36:30 +01:00
|
|
|
const errors = {};
|
2017-12-01 04:51:55 +01:00
|
|
|
|
|
|
|
if (!vals.returnAddress) {
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
const isValidAddress = validateAddress(vals.originCoin, vals.returnAddress);
|
|
|
|
|
|
|
|
if (!isValidAddress) {
|
|
|
|
errors.returnAddress = `Enter a valid ${vals.originCoin} address`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
};
|
|
|
|
|
|
|
|
const exampleCoinAddresses = {
|
2017-12-21 18:32:51 +01:00
|
|
|
BTC: '1745oPaHeW7Fmpb1fUKTtasYfxr4zu9bwq',
|
|
|
|
BCH: '1745oPaHeW7Fmpb1fUKTtasYfxr4zu9bwq',
|
|
|
|
ETH: '0x8507cA6a274123fC8f80d929AF9D83602bC4e8cC',
|
|
|
|
DASH: 'XedBP7vLPFXbS3URjrH2Z57Fg9SWftBmQ6',
|
|
|
|
LTC: 'LgZivMvFMTDoqcA5weCQ2QrmRp7pa56bBk',
|
2017-12-01 04:51:55 +01:00
|
|
|
XMR:
|
2017-12-21 18:32:51 +01:00
|
|
|
'466XMeJEcowYGx7RzUJj3VDWBZgRWErVQQX6tHYbsacS5QF6v3tidE6LZZnTJgzeEh6bKEEJ6GC9jHirrUKvJwVKVj9e7jm',
|
2017-12-01 04:51:55 +01:00
|
|
|
};
|
|
|
|
|
2017-12-13 22:36:30 +01:00
|
|
|
export const getExampleAddress = coin => exampleCoinAddresses[coin];
|