|
|
@ -454,16 +454,42 @@ WalletService.prototype.joinWallet = function(opts, cb) { |
|
|
|
* Save copayer preferences for the current wallet/copayer pair. |
|
|
|
* @param {Object} opts |
|
|
|
* @param {string} opts.email - Email address for notifications. |
|
|
|
* @param {string} opts.language - Language used for notifications. |
|
|
|
* @param {string} opts.unit - Bitcoin unit used to format amounts in notifications. |
|
|
|
*/ |
|
|
|
WalletService.prototype.savePreferences = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
if (opts.email) { |
|
|
|
if (!EmailValidator.validate(opts.email)) { |
|
|
|
return cb(new ClientError('Invalid email address')); |
|
|
|
} |
|
|
|
var preferences = [{ |
|
|
|
name: 'email', |
|
|
|
isValid: function(value) { |
|
|
|
return EmailValidator.validate(value); |
|
|
|
}, |
|
|
|
}, { |
|
|
|
name: 'language', |
|
|
|
isValid: function(value) { |
|
|
|
return _.isString(value) && value.length == 2; |
|
|
|
}, |
|
|
|
}, { |
|
|
|
name: 'unit', |
|
|
|
isValid: function(value) { |
|
|
|
return _.isString(value) && _.contains(['btc', 'bit'], value.toLowerCase()); |
|
|
|
}, |
|
|
|
}]; |
|
|
|
|
|
|
|
try { |
|
|
|
_.each(preferences, function(preference) { |
|
|
|
var value = opts[preference.name]; |
|
|
|
if (!value) return; |
|
|
|
if (!preference.isValid(value)) { |
|
|
|
throw 'Invalid ' + preference.name; |
|
|
|
return false; |
|
|
|
} |
|
|
|
}); |
|
|
|
} catch (ex) { |
|
|
|
return cb(new ClientError(ex)); |
|
|
|
} |
|
|
|
|
|
|
|
self._runLocked(cb, function(cb) { |
|
|
@ -471,6 +497,8 @@ WalletService.prototype.savePreferences = function(opts, cb) { |
|
|
|
walletId: self.walletId, |
|
|
|
copayerId: self.copayerId, |
|
|
|
email: opts.email, |
|
|
|
language: opts.language, |
|
|
|
unit: opts.unit, |
|
|
|
}); |
|
|
|
self.storage.storePreferences(preferences, function(err) { |
|
|
|
return cb(err); |
|
|
|