2014-03-14 13:38:27 -07:00
|
|
|
'use strict';
|
2014-04-22 12:07:14 -07:00
|
|
|
|
2014-06-03 12:39:06 -07:00
|
|
|
angular.module('copayApp.directives')
|
2014-05-07 15:04:36 -07:00
|
|
|
.directive('validAddress', [
|
2014-04-22 12:07:14 -07:00
|
|
|
|
2014-05-07 15:04:36 -07:00
|
|
|
function() {
|
2014-04-22 12:07:14 -07:00
|
|
|
|
2014-05-07 15:04:36 -07:00
|
|
|
var bitcore = require('bitcore');
|
|
|
|
var Address = bitcore.Address;
|
2014-04-22 12:07:14 -07:00
|
|
|
|
2014-05-07 15:04:36 -07:00
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function(scope, elem, attrs, ctrl) {
|
|
|
|
var validator = function(value) {
|
|
|
|
var a = new Address(value);
|
2014-07-04 07:24:11 -07:00
|
|
|
ctrl.$setValidity('validAddress', a.isValid() && a.network().name === config.networkName);
|
2014-05-07 15:04:36 -07:00
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
|
|
|
ctrl.$parsers.unshift(validator);
|
|
|
|
ctrl.$formatters.unshift(validator);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2014-06-16 08:44:18 -07:00
|
|
|
.directive('notification', ['$rootScope',
|
2014-05-07 15:04:36 -07:00
|
|
|
function($rootScope) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link: function(scope, element, attrs, ctrl) {
|
|
|
|
setTimeout(function() {
|
2014-07-04 08:51:27 -07:00
|
|
|
scope.$apply(function() {});
|
2014-05-07 15:04:36 -07:00
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
|
|
|
.directive('enoughAmount', ['$rootScope',
|
|
|
|
function($rootScope) {
|
2014-06-12 07:09:18 -07:00
|
|
|
var bitcore = require('bitcore');
|
2014-06-25 11:44:19 -07:00
|
|
|
var feeSat = Number(bitcore.TransactionBuilder.FEE_PER_1000B_SAT);
|
2014-05-07 15:04:36 -07:00
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function(scope, element, attrs, ctrl) {
|
|
|
|
var val = function(value) {
|
2014-06-25 11:44:19 -07:00
|
|
|
var availableBalanceNum = Number(($rootScope.availableBalance * config.unitToSatoshi).toFixed(0));
|
2014-06-16 08:44:18 -07:00
|
|
|
var vNum = Number((value * config.unitToSatoshi).toFixed(0)) + feeSat;
|
2014-05-07 15:04:36 -07:00
|
|
|
if (typeof vNum == "number" && vNum > 0) {
|
2014-06-12 07:09:18 -07:00
|
|
|
if (availableBalanceNum < vNum) {
|
2014-05-07 15:04:36 -07:00
|
|
|
ctrl.$setValidity('enoughAmount', false);
|
2014-06-12 07:09:18 -07:00
|
|
|
scope.notEnoughAmount = true;
|
2014-05-07 15:04:36 -07:00
|
|
|
} else {
|
|
|
|
ctrl.$setValidity('enoughAmount', true);
|
|
|
|
scope.notEnoughAmount = null;
|
|
|
|
}
|
|
|
|
} else {
|
2014-04-23 10:41:27 -07:00
|
|
|
scope.notEnoughAmount = null;
|
2014-04-23 09:16:20 -07:00
|
|
|
}
|
2014-05-07 15:04:36 -07:00
|
|
|
return value;
|
2014-04-23 09:16:20 -07:00
|
|
|
}
|
2014-05-07 15:04:36 -07:00
|
|
|
ctrl.$parsers.unshift(val);
|
|
|
|
ctrl.$formatters.unshift(val);
|
2014-04-23 09:16:20 -07:00
|
|
|
}
|
2014-05-07 15:04:36 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2014-05-14 14:24:24 -07:00
|
|
|
.directive('walletSecret', ['walletFactory',
|
|
|
|
function(walletFactory) {
|
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function(scope, elem, attrs, ctrl) {
|
|
|
|
var validator = function(value) {
|
2014-06-16 08:44:18 -07:00
|
|
|
ctrl.$setValidity('walletSecret', Boolean(walletFactory.decodeSecret(value)));
|
2014-05-14 14:24:24 -07:00
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
|
|
|
ctrl.$parsers.unshift(validator);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2014-05-07 15:04:36 -07:00
|
|
|
.directive('loading', function() {
|
2014-04-24 18:43:19 -07:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
2014-05-16 14:33:06 -07:00
|
|
|
link: function($scope, element, attr) {
|
2014-04-24 18:43:19 -07:00
|
|
|
var a = element.html();
|
|
|
|
var text = attr.loading;
|
2014-05-16 14:33:06 -07:00
|
|
|
element.on('click', function() {
|
2014-06-16 08:44:18 -07:00
|
|
|
element.html('<i class="size-21 fi-bitcoin-circle icon-rotate spinner"></i> ' + text + '...');
|
2014-05-16 14:33:06 -07:00
|
|
|
});
|
|
|
|
$scope.$watch('loading', function(val) {
|
|
|
|
if (!val) {
|
2014-04-24 18:43:19 -07:00
|
|
|
element.html(a);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-05-07 15:04:36 -07:00
|
|
|
.directive('ngFileSelect', function() {
|
2014-04-25 15:11:56 -07:00
|
|
|
return {
|
|
|
|
link: function($scope, el) {
|
|
|
|
el.bind('change', function(e) {
|
|
|
|
$scope.file = (e.srcElement || e.target).files[0];
|
|
|
|
$scope.getFile();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-05-26 11:03:39 -07:00
|
|
|
})
|
|
|
|
.directive('avatar', function($rootScope, controllerUtils) {
|
2014-05-07 15:04:36 -07:00
|
|
|
return {
|
|
|
|
link: function(scope, element, attrs) {
|
2014-05-08 11:48:00 -07:00
|
|
|
var peer = JSON.parse(attrs.peer)
|
|
|
|
var peerId = peer.peerId;
|
|
|
|
var nick = peer.nick;
|
|
|
|
element.addClass('video-small');
|
2014-05-16 14:33:06 -07:00
|
|
|
var muted = controllerUtils.getVideoMutedStatus(peerId);
|
2014-06-06 11:16:11 -07:00
|
|
|
if (true || muted) { // mute everyone for now
|
2014-05-07 15:04:36 -07:00
|
|
|
element.attr("muted", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-26 11:03:39 -07:00
|
|
|
})
|
2014-06-23 13:34:54 -07:00
|
|
|
.directive('contact', function() {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
2014-06-24 08:36:32 -07:00
|
|
|
link: function(scope, element, attrs) {
|
2014-06-23 13:34:54 -07:00
|
|
|
if (!scope.wallet) return;
|
|
|
|
|
|
|
|
var address = attrs.address;
|
|
|
|
var contact = scope.wallet.addressBook[address];
|
|
|
|
if (contact) {
|
|
|
|
element.append(contact.label);
|
|
|
|
attrs['tooltip'] = attrs.address;
|
|
|
|
} else {
|
|
|
|
element.append(address);
|
|
|
|
}
|
|
|
|
}
|
2014-06-24 08:36:32 -07:00
|
|
|
};
|
2014-06-23 13:34:54 -07:00
|
|
|
})
|
2014-06-11 13:49:14 -07:00
|
|
|
.directive('highlightOnChange', function() {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link: function(scope, element, attrs) {
|
2014-06-16 08:44:18 -07:00
|
|
|
scope.$watch(attrs.highlightOnChange, function(newValue, oldValue) {
|
2014-06-11 13:49:14 -07:00
|
|
|
element.addClass('highlight');
|
2014-06-16 08:44:18 -07:00
|
|
|
setTimeout(function() {
|
|
|
|
element.removeClass('highlight');
|
|
|
|
}, 500);
|
2014-06-11 13:49:14 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-05-26 11:03:39 -07:00
|
|
|
.directive('checkStrength', function() {
|
|
|
|
return {
|
|
|
|
replace: false,
|
|
|
|
restrict: 'EACM',
|
2014-06-02 10:39:12 -07:00
|
|
|
require: 'ngModel',
|
2014-05-26 11:03:39 -07:00
|
|
|
link: function(scope, element, attrs) {
|
|
|
|
var strength = {
|
2014-06-11 11:39:56 -07:00
|
|
|
messages: ['very weak', 'weak', 'weak', 'medium', 'strong'],
|
2014-05-26 11:03:39 -07:00
|
|
|
colors: ['#c0392b', '#e74c3c', '#d35400', '#f39c12', '#27ae60'],
|
2014-06-16 08:44:18 -07:00
|
|
|
mesureStrength: function(p) {
|
2014-06-11 11:39:56 -07:00
|
|
|
var force = 0;
|
|
|
|
var regex = /[$-/:-?{-~!"^_`\[\]]/g;
|
|
|
|
var lowerLetters = /[a-z]+/.test(p);
|
|
|
|
var upperLetters = /[A-Z]+/.test(p);
|
|
|
|
var numbers = /[0-9]+/.test(p);
|
|
|
|
var symbols = regex.test(p);
|
|
|
|
var flags = [lowerLetters, upperLetters, numbers, symbols];
|
2014-06-16 08:44:18 -07:00
|
|
|
var passedMatches = flags.filter(function(el) {
|
|
|
|
return !!el;
|
|
|
|
}).length;
|
|
|
|
|
2014-06-11 11:39:56 -07:00
|
|
|
force = 2 * p.length + (p.length >= 10 ? 1 : 0);
|
|
|
|
force += passedMatches * 10;
|
2014-06-16 08:44:18 -07:00
|
|
|
|
2014-05-26 11:03:39 -07:00
|
|
|
// penality (short password)
|
2014-06-11 11:39:56 -07:00
|
|
|
force = (p.length <= 6) ? Math.min(force, 10) : force;
|
2014-06-16 08:44:18 -07:00
|
|
|
|
2014-05-26 11:03:39 -07:00
|
|
|
// penality (poor variety of characters)
|
2014-06-11 11:39:56 -07:00
|
|
|
force = (passedMatches == 1) ? Math.min(force, 10) : force;
|
|
|
|
force = (passedMatches == 2) ? Math.min(force, 20) : force;
|
|
|
|
force = (passedMatches == 3) ? Math.min(force, 40) : force;
|
|
|
|
return force;
|
2014-05-26 11:03:39 -07:00
|
|
|
},
|
2014-06-16 08:44:18 -07:00
|
|
|
getColor: function(s) {
|
2014-05-26 11:03:39 -07:00
|
|
|
var idx = 0;
|
2014-06-16 08:44:18 -07:00
|
|
|
|
|
|
|
if (s <= 10) {
|
|
|
|
idx = 0;
|
|
|
|
} else if (s <= 20) {
|
|
|
|
idx = 1;
|
|
|
|
} else if (s <= 30) {
|
|
|
|
idx = 2;
|
|
|
|
} else if (s <= 40) {
|
|
|
|
idx = 3;
|
|
|
|
} else {
|
|
|
|
idx = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
idx: idx + 1,
|
|
|
|
col: this.colors[idx],
|
|
|
|
message: this.messages[idx]
|
|
|
|
};
|
2014-05-26 11:03:39 -07:00
|
|
|
}
|
|
|
|
};
|
2014-06-02 10:39:12 -07:00
|
|
|
|
2014-06-16 08:44:18 -07:00
|
|
|
scope.$watch(attrs.ngModel, function(newValue, oldValue) {
|
2014-05-26 11:03:39 -07:00
|
|
|
if (newValue && newValue !== '') {
|
|
|
|
var c = strength.getColor(strength.mesureStrength(newValue));
|
2014-06-16 08:44:18 -07:00
|
|
|
element.css({
|
|
|
|
'border-color': c.col
|
|
|
|
});
|
2014-06-02 10:39:12 -07:00
|
|
|
scope[attrs.checkStrength] = c.message;
|
2014-05-26 11:03:39 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2014-06-16 11:51:19 -07:00
|
|
|
})
|
|
|
|
// From https://gist.github.com/asafge/7430497
|
|
|
|
.directive('ngReallyClick', [
|
|
|
|
|
|
|
|
function() {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link: function(scope, element, attrs) {
|
|
|
|
element.bind('click', function() {
|
|
|
|
var message = attrs.ngReallyMessage;
|
|
|
|
if (message && confirm(message)) {
|
|
|
|
scope.$apply(attrs.ngReallyClick);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
;
|