Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
vhpoet committed May 12, 2015
2 parents cab4c55 + 83f76cb commit e4b86bf
Show file tree
Hide file tree
Showing 49 changed files with 4,092 additions and 1,659 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Keep track of development and community news.
- Follow [@RippleLabs on Twitter](https://twitter.com/ripplelabs)
- Like [Ripple Labs on Facebook](https://facebook.com/ripplelabs)
- Subscribe to [@Ripple on Reddit](http://www.reddit.com/r/Ripple)
- Subscribe to [the Ripple user community on Reddit](http://www.reddit.com/r/Ripplers)
- Have a question that's not a feature request or bug report? Send a message to [[email protected]](mailto:[email protected])
- Chat directly with our engineers! Join us [here](https://gitter.im/ripple/developers).

Expand Down
134 changes: 64 additions & 70 deletions src/js/directives/accountExists.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,96 +16,90 @@
*/
angular.module('validators').directive('rpAccountExists', rpAccountExists);

rpAccountExists.$inject = ['$timeout', '$parse', 'rpNetwork'];
rpAccountExists.$inject = ['$timeout', '$parse', 'rpNetwork', '$q'];

function rpAccountExists($timeout, $parse, $network) {
function rpAccountExists($timeout, $parse, $network, $q) {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope, elm, attr, ctrl) {
if (!ctrl) return;

var rpAccountExistsModelGetter;
var currentCheckTimeout = null,
currentDefer = null;

function showLoading(doShow) {
if (attr.rpAccountExistsLoading) {
var getterL = $parse(attr.rpAccountExistsLoading);
getterL.assign(scope, doShow);
}
}
ctrl.$asyncValidators.rpAccountExists = function(value) {

var validator = function(value) {
var valToCheck = rpAccountExistsModelGetter ? rpAccountExistsModelGetter(scope) : value;
var strippedValue = webutil.stripRippleAddress(value),
address = ripple.UInt160.from_json(strippedValue);

var strippedValue = webutil.stripRippleAddress(valToCheck);
var address = ripple.UInt160.from_json(strippedValue);
if (currentDefer) {
// another check is pending, but it is not needed
currentDefer.resolve(true);
currentDefer = null;
$timeout.cancel(currentCheckTimeout);
currentCheckTimeout = null;
}

function checkCurrentValue() {
var currentValue = (rpAccountExistsModelGetter) ? rpAccountExistsModelGetter(scope) : ctrl.$viewValue;
var currentAddress = ripple.UInt160.from_json(webutil.stripRippleAddress(currentValue));
if (strippedValue != currentValue && !currentAddress.is_valid()) {
scope.$apply(function() {
ctrl.$setValidity('rpAccountExists', true);
showLoading(false);
});
}
return strippedValue != currentValue;
function checkFunded(addressToCheckPromise) {
return addressToCheckPromise.then(function(addressToCheck) {
if (addressToCheck === false) {
// skip check
return $q.when(true);
}
var address2 = ripple.UInt160.from_json(addressToCheck);
if (address2.is_valid()) {
var defer = $q.defer();

$network.remote.requestAccountInfo({account: addressToCheck})
.on('success', function(m) {
defer.resolve(true);
})
.on('error', function(m) {
if (m && m.remote && m.remote.error === 'actNotFound') {
defer.reject(false);
} else {
console.log('There was an error', m);
defer.resolve(true);
}
})
.request();
return defer.promise;
} else {
return $q.when(true);
}
});
}

if (address.is_valid()) {
ctrl.$setValidity('rpAccountExists', false);
showLoading(true);

$network.remote.requestAccountInfo({account: strippedValue})
.on('success', function(m) {
if (checkCurrentValue()) {
return;
}
scope.$apply(function() {
ctrl.$setValidity('rpAccountExists', true);
showLoading(false);
});
})
.on('error', function(m) {
if (checkCurrentValue()) {
return;
return checkFunded($q.when(value));
} else if (scope.userBlob && webutil.getContact(scope.userBlob.data.contacts, strippedValue)) {
return checkFunded($q.when(webutil.getContact(scope.userBlob.data.contacts, strippedValue).address));
} else if (webutil.isRippleName(value)) {
var defer = $q.defer();
currentDefer = defer;

currentCheckTimeout = $timeout(function() {
currentCheckTimeout = null;
currentDefer = null;

rippleVaultClient.AuthInfo.get(Options.domain, value, function(err, info) {
if (info && info.exists && info.address) {
defer.resolve(info.address);
} else {
defer.resolve(false);
}
scope.$apply(function() {
showLoading(false);
if (m && m.remote && m.remote.error_code === 15) {
ctrl.$setValidity('rpAccountExists', false);
} else {
console.log('There was an error', m);
ctrl.$setValidity('rpAccountExists', true);
}
});
})
.request();
return value;
});
}, 500);

return checkFunded(defer.promise);
}

ctrl.$setValidity('rpAccountExists', true);
return value;
return $q.when(true);
};

if (attr.rpAccountExistsModel) {
rpAccountExistsModelGetter = $parse(attr.rpAccountExistsModel);
var watcher = scope.$watch(attr.rpAccountExistsModel, function() {
var address = rpAccountExistsModelGetter(scope);
validator(address);
});

scope.$on('$destroy', function() {
// Remove watcher
watcher();
});
}

ctrl.$formatters.push(validator);
ctrl.$parsers.unshift(validator);

attr.$observe('rpAccountExists', function() {
validator(ctrl.$viewValue);
ctrl.$validate();
});
}
};
Expand Down
10 changes: 10 additions & 0 deletions src/js/directives/directives.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ module.directive('rpPopup', ['rpPopup', '$parse', function(popup, $parse) {
a.click(function(e) {
e.preventDefault();

var dismissOnEsc = function($event) {
// esc button
if ($event.which === 27) {
$(document).off('keyup', dismissOnEsc);
popup.close();
}
};

$(document).on('keyup', dismissOnEsc);

// onShow action
if (attrs.rpPopupOnOpen) {
$parse(attrs.rpPopupOnOpen)(scope);
Expand Down
37 changes: 32 additions & 5 deletions src/js/directives/fields.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,51 @@ module.directive('rpDatepicker', [function() {
require: '?ngModel',
link: function(scope, element, attr, ngModel) {
attr.$observe('rpDatepicker', function() {
var dp = $(element).datepicker({
var options = {
format: 'mm/dd/yyyy'
});
};

if (attr.rpDatepickerMin) {
var dateMinVal = 0;
options.onRender = function(date) {
return date.valueOf() < dateMinVal ? 'disabled' : '';
};

scope.$watch(attr.rpDatepickerMin, function(v) {
if (v instanceof Date) {
dateMinVal = v.valueOf();
var viewDate = ngModel.$viewValue.valueOf();
if (typeof viewDate === 'string') {
viewDate = Date.parse(viewDate).valueOf();
}
if (dateMinVal > viewDate) {
var newDate = new Date(dateMinVal + 24 * 60 * 60 * 1000);
ngModel.$setViewValue(newDate);
$(element).datepicker('setValue', newDate);
}
// fore re-render
$(element).data('datepicker').fill();
}
});
}

var dp = $(element).datepicker(options);
dp.on('changeDate', function(e) {
scope.$apply(function () {
ngModel.$setViewValue(e.date.getMonth() ? e.date : new Date(e.date));
});
});
scope.$watch(attr.ngModel,function() {

scope.$watch(attr.ngModel, function() {
var update = ngModel.$viewValue;

function falsy(v) {return v == '0' || v == 'false'; }

if (!falsy(attr.ignoreInvalidUpdate) &&
(update == null ||
(update instanceof Date && isNaN(update.getYear())) )) {
return;
}
return;
}
});
});
}
Expand Down
69 changes: 37 additions & 32 deletions src/js/directives/validators.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,48 +110,57 @@ module.directive('rpDest', ['$q', '$timeout', '$parse', 'rpFederation', function
link: function (scope, elm, attr, ctrl) {
if (!ctrl) return;

var getter;
var currentCheckTimeout = null,
currentDefer = null,
getter;

function setDestModelValue(value) {
if (attr.rpDestModel) {
getter = $parse(attr.rpDestModel);
getter.assign(scope, value);
}
}

ctrl.$asyncValidators.rpDest = function(value) {
var strippedValue = webutil.stripRippleAddress(value),
address = ripple.UInt160.from_json(strippedValue);

if (currentDefer) {
// another check is pending, but it is not needed
currentDefer.resolve(true);
currentDefer = null;
$timeout.cancel(currentCheckTimeout);
currentCheckTimeout = null;
}

ctrl.rpDestType = null;
if (attr.rpDestFederationModel) {
getter = $parse(attr.rpDestFederationModel);
getter.assign(scope,null);
getter.assign(scope, null);
}

// client-side validation
if (attr.rpDestAddress && address.is_valid()) {
ctrl.rpDestType = "address";

if (attr.rpDestModel) {
getter = $parse(attr.rpDestModel);
getter.assign(scope,value);
}
setDestModelValue(value);

return $q.when(true);
}

if (attr.rpDestContact && scope.userBlob &&
webutil.getContact(scope.userBlob.data.contacts,strippedValue)) {
webutil.getContact(scope.userBlob.data.contacts, strippedValue)) {
ctrl.rpDestType = "contact";

if (attr.rpDestModel) {
getter = $parse(attr.rpDestModel);
getter.assign(scope,webutil.getContact(scope.userBlob.data.contacts,strippedValue).address);
}
setDestModelValue(scope, webutil.getContact(scope.userBlob.data.contacts, strippedValue).address);

return $q.when(true);
}

if (attr.rpDestBitcoin && !isNaN(Base.decode_check([0, 5], strippedValue, 'bitcoin'))) {
ctrl.rpDestType = "bitcoin";

if (attr.rpDestModel) {
getter = $parse(attr.rpDestModel);
getter.assign(scope,value);
}
setDestModelValue(value);

return $q.when(true);
}
Expand All @@ -165,42 +174,38 @@ module.directive('rpDest', ['$q', '$timeout', '$parse', 'rpFederation', function
// Check if this request is still current, exit if not
if (value != ctrl.$viewValue) return;

if (attr.rpDestModel) {
getter = $parse(attr.rpDestModel);
getter.assign(scope,value);
}
setDestModelValue(value);

if (attr.rpDestFederationModel) {
getter = $parse(attr.rpDestFederationModel);
getter.assign(scope,result);
getter.assign(scope, result);
}
return true;
}, function() {
return false;
});
} else {
if (attr.rpDestModel) {
getter = $parse(attr.rpDestModel);
getter.assign(scope,value);
}
setDestModelValue(value);

return $q.when(true);
}
}

if (((attr.rpDestRippleName && webutil.isRippleName(value)) ||
(attr.rpDestRippleNameNoTilde && value && value[0] !== '~' && webutil.isRippleName('~'+value)))) { // TODO Don't do a client check in validators
(attr.rpDestRippleNameNoTilde && value && value[0] !== '~' && webutil.isRippleName('~' + value)))) { // TODO Don't do a client check in validators
ctrl.rpDestType = "rippleName";

var defer = $q.defer();
$timeout(function() {
rippleVaultClient.AuthInfo.get(Options.domain, value, function(err, info){
scope.$apply(function(){
if (attr.rpDestModel && info.exists) {
getter = $parse(attr.rpDestModel);
getter.assign(scope,info.address);
}
currentDefer = defer;

currentCheckTimeout = $timeout(function() {
currentCheckTimeout = null;
currentDefer = null;

rippleVaultClient.AuthInfo.get(Options.domain, value, function(err, info) {
scope.$apply(function(){
if (info.exists) {
setDestModelValue(info.address);
defer.resolve(info.exists);
} else {
defer.reject();
Expand Down
21 changes: 21 additions & 0 deletions src/js/services/id.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ module.factory('rpId', ['$rootScope', '$location', '$route', '$routeParams', '$t
$scope.userBlob.unset('/trade_currency_pairs');
}

var tradeCurrencyPairs = settings.getSetting($scope.userBlob, 'trade_currency_pairs', []);
if (_.isArray(tradeCurrencyPairs) && tradeCurrencyPairs.length > 0) {
var changed = false;
if (_.find(tradeCurrencyPairs, _.partial(_.has, _, '$$hashKey'))) {
// clear $$hashKey
tradeCurrencyPairs = angular.fromJson(angular.toJson(tradeCurrencyPairs));
changed = true;
}
var tradeCurrencyPairsUniq = _.uniq(tradeCurrencyPairs, false, function(o) {
return o.name;
});
if (tradeCurrencyPairsUniq.length !== tradeCurrencyPairs.length) {
tradeCurrencyPairs = tradeCurrencyPairsUniq;
changed = true;
}

if (changed) {
$scope.userBlob.set('/clients/rippletradecom/trade_currency_pairs', tradeCurrencyPairs);
}
}

if (_.has(d, 'txQueue')) {
$scope.userBlob.set('/clients/rippletradecom/txQueue', d.txQueue);
$scope.userBlob.unset('/txQueue');
Expand Down
Loading

0 comments on commit e4b86bf

Please sign in to comment.