<commit_before>angular.module("omniServices")
	.service("Wallet",["Address", "Asset", "BalanceSocket","$injector","$rootScope",
		function WalletService(Address, Asset, BalanceSocket,$injector,$rootScope){
			var self = this;

			var appraiser = null;
			self.loaded = false;
			self.initialize =function(wallet){
	            BalanceSocket.connect();
				appraiser = $injector.get('appraiser');

	            self.addresses = [];
	            self.assets = [];
	            self.loader = {
	            	totalAddresses: wallet.addresses.length,
	            	totalAssets:0,
	            	addresses:0,
	            	assets:0,
	            	loadedAddresses:false,
	            	loadedAssets:false
	            }
	            wallet.addresses.forEach(function(raw){
	                self._addAddress(raw);
	            });

	            appraiser.start();

				$rootScope.$on("address:loaded", function(address){
					self.loader.addresses +=1;
						check_load()
				});

				$rootScope.$on("asset:loaded", function(asset){
					self.loader.assets +=1;
						check_load()
				});

				function check_load(){
					if(self.loader.addresses==self.loader.totalAddresses)
						self.loader.loadedAddresses = true;

					if(self.loader.assets==self.loader.totalAssets)
						self.loader.loadedAssets = true;

					if(self.loader.loadedAddresses && self.loader.loadedAssets)
						self.loaded = true;
				}
	        };


	        self.destroy = function(){
	        	self.addresses = [];
	            self.assets = [];
	        	BalanceSocket.disconnect();
	        	
	        }

	        self._addAddress = function(raw){
	        	var address = new Address(raw.address,raw.privkey,raw.pubkey);

                BalanceSocket.on("address:"+address.address, function(data){
                    var update = false;
                    if(self.loader.totalAssets < data.balance.length)
                    	self.loader.totalAssets = data.balance.length;
                    
                    data.balance.forEach(function(balanceItem) {
                        var tradable = ((address.privkey && address.privkey.length == 58) || address.pubkey) && balanceItem.value > 0;
                        var asset = null;
                        for (var j = 0; j < self.assets.length; j++) {
                          var currencyItem = self.assets[j];
                          if (currencyItem.symbol == balanceItem.symbol) {
                            asset = currencyItem;<commit_msg>Sort Assets by name<commit_after>angular.module("omniServices")
	.service("Wallet",["Address", "Asset", "BalanceSocket","$injector","$rootScope",
		function WalletService(Address, Asset, BalanceSocket,$injector,$rootScope){
			var self = this;

			var appraiser = null;
			self.loaded = false;
			self.initialize =function(wallet){
	            BalanceSocket.connect();
				appraiser = $injector.get('appraiser');

	            self.addresses = [];
	            self.assets = [];
	            self.loader = {
	            	totalAddresses: wallet.addresses.length,
	            	totalAssets:0,
	            	addresses:0,
	            	assets:0,
	            	loadedAddresses:false,
	            	loadedAssets:false
	            }
	            wallet.addresses.forEach(function(raw){
	                self._addAddress(raw);
	            });

	            appraiser.start();

				$rootScope.$on("address:loaded", function(address){
					self.loader.addresses +=1;
						check_load()
				});

				$rootScope.$on("asset:loaded", function(asset){
					self.loader.assets +=1;
						check_load()
				});

				function check_load(){
					if(self.loader.addresses==self.loader.totalAddresses)
						self.loader.loadedAddresses = true;

					if(self.loader.assets==self.loader.totalAssets){
						self.loader.loadedAssets = true;
						self.assets = self.assets.sort(function(itemA, itemB){
							nameA = itemA.name;
							nameB = itemB.name;

							var order = 0;
							if(nameA == "Bitcoin")
								order = 1;
							else if(nameB == "Bitcoin")
								order = -1;
							else
								order = nameA < nameB ? -1 : nameA > nameB ? 1 : 0;

							return order;

						});
					}

					if(self.loader.loadedAddresses && self.loader.loadedAssets)
						self.loaded = true;
				}
	        };


	        self.destroy = function(){
	        	self.addresses = [];
	            self.assets = [];
	        	BalanceSocket.disconnect();
	        	
	        }

	        self._addAddress = function(raw){
	        	var address = new Address(raw.address,raw.privkey,raw.pubkey);

                BalanceSocket.on("address:"+address.address, function(data){
                    var update = false;
                    if(self.loader.totalAssets < data.balance.length)
                    	self.loader.totalAssets = data.balance.length;
                    
                    data.balance.forEach(function(balanceItem) {
                        var tradable = ((address.privkey && address.privkey.length == 58) || address.pubkey) && balanceItem.value > 0;
                        var asset = null;
                        for (var j = 0; j < self.assets.length; j++) {
                          var currencyItem = self.assets[j];
                          if (currencyItem.symbol == balanceItem.symbol) {
                            asset = currencyItem;
{'fraction_non_alphanumeric': 0.12370551685181698, 'fraction_numerical': 0.004518922990020712, 'mean_word_length': 1.7480600103466115, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4101635', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1438, 'n_words': 238}