Fixes show all/show less button on address list
This commit is contained in:
parent
5c1935e04b
commit
12adaa64d2
8 changed files with 110 additions and 161 deletions
|
|
@ -3,6 +3,7 @@
|
|||
angular.module('copayApp.controllers').controller('AddressesController',
|
||||
function($scope, $rootScope, $timeout, $modal, controllerUtils) {
|
||||
$scope.loading = false;
|
||||
$scope.showAll = false;
|
||||
var w = $rootScope.wallet;
|
||||
|
||||
$scope.newAddr = function() {
|
||||
|
|
@ -16,7 +17,7 @@ angular.module('copayApp.controllers').controller('AddressesController',
|
|||
};
|
||||
|
||||
$scope.openAddressModal = function(address) {
|
||||
var ModalInstanceCtrl = function ($scope, $modalInstance, address) {
|
||||
var ModalInstanceCtrl = function($scope, $modalInstance, address) {
|
||||
$scope.address = address;
|
||||
$scope.isMobile = !!window.cordova;
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ angular.module('copayApp.controllers').controller('AddressesController',
|
|||
window.plugins.toast.showShortBottom('Copied to clipboard');
|
||||
}
|
||||
|
||||
$scope.cancel = function () {
|
||||
$scope.cancel = function() {
|
||||
$modalInstance.dismiss('cancel');
|
||||
};
|
||||
};
|
||||
|
|
@ -35,7 +36,9 @@ angular.module('copayApp.controllers').controller('AddressesController',
|
|||
windowClass: 'tiny',
|
||||
controller: ModalInstanceCtrl,
|
||||
resolve: {
|
||||
address: function() { return address; }
|
||||
address: function() {
|
||||
return address;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -44,20 +47,45 @@ angular.module('copayApp.controllers').controller('AddressesController',
|
|||
$scope.addressList();
|
||||
});
|
||||
|
||||
$scope.toggleShowAll = function() {
|
||||
$scope.showAll = !$scope.showAll;
|
||||
$scope.addressList();
|
||||
};
|
||||
|
||||
$scope.limitAddress = function(elements) {
|
||||
|
||||
elements = elements.sort(function(a, b) {
|
||||
return (+a.isChange - +b.isChange);
|
||||
});
|
||||
|
||||
if (elements.length <= 1 || $scope.showAll) {
|
||||
return elements;
|
||||
}
|
||||
|
||||
// Show last 3 non-change addresses plus those with balance
|
||||
var addrs = elements.filter(function(e, i) {
|
||||
return (!e.isChange && i < 3) || (e.balance && e.balance > 0);
|
||||
});
|
||||
|
||||
return addrs;
|
||||
};
|
||||
|
||||
$scope.addressList = function() {
|
||||
$scope.addresses = [];
|
||||
var addrInfos = $rootScope.addrInfos;
|
||||
if (addrInfos) {
|
||||
|
||||
if ($rootScope.addrInfos) {
|
||||
var addrInfos = $rootScope.addrInfos;
|
||||
for (var i = 0; i < addrInfos.length; i++) {
|
||||
var addrinfo = addrInfos[i];
|
||||
$scope.addresses.push({
|
||||
'address': addrinfo.addressStr,
|
||||
'balance': $rootScope.balanceByAddr ? $rootScope.balanceByAddr[addrinfo.addressStr] : 0,
|
||||
'isChange': addrinfo.isChange,
|
||||
'owned': addrinfo.owned
|
||||
'owned': addrinfo.owned,
|
||||
});
|
||||
}
|
||||
$scope.addresses = $scope.limitAddress($scope.addresses);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -14,32 +14,15 @@ angular.module('copayApp.controllers').controller('OpenController', function($sc
|
|||
};
|
||||
$rootScope.fromSetup = false;
|
||||
$scope.loading = false;
|
||||
$scope.retreiving = true;
|
||||
|
||||
walletFactory.getWallets(function(err, wallets) {
|
||||
|
||||
if (err || !wallets || !wallets.length) {
|
||||
$location.path('/');
|
||||
} else {
|
||||
$scope.retreiving = false;
|
||||
$scope.wallets = wallets.sort(cmp);
|
||||
|
||||
walletFactory.storage.getLastOpened(function(ret) {
|
||||
if (ret && _.indexOf(_.pluck($scope.wallets, 'id')) == -1)
|
||||
ret = null;
|
||||
|
||||
$scope.selectedWalletId = ret || ($scope.wallets[0] && $scope.wallets[0].id);
|
||||
|
||||
setTimeout(function() {
|
||||
$rootScope.$digest();
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$scope.wallets = walletFactory.getWallets().sort(cmp);
|
||||
$scope.selectedWalletId = walletFactory.storage.getLastOpened() || ($scope.wallets[0] && $scope.wallets[0].id);
|
||||
$scope.openPassword = '';
|
||||
$scope.isMobile = !!window.cordova;
|
||||
|
||||
if (!$scope.wallets.length) {
|
||||
$location.path('/');
|
||||
}
|
||||
|
||||
$scope.open = function(form) {
|
||||
if (form && form.$invalid) {
|
||||
notification.error('Error', 'Please enter the required fields');
|
||||
|
|
@ -51,16 +34,19 @@ angular.module('copayApp.controllers').controller('OpenController', function($sc
|
|||
|
||||
Passphrase.getBase64Async(password, function(passphrase) {
|
||||
var w, errMsg;
|
||||
walletFactory.open($scope.selectedWalletId, passphrase, function(err, w) {
|
||||
if (!w) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', err.errMsg || 'Wrong password');
|
||||
$rootScope.$digest();
|
||||
} else {
|
||||
$rootScope.updatingBalance = true;
|
||||
controllerUtils.startNetwork(w, $scope);
|
||||
}
|
||||
});
|
||||
try {
|
||||
w = walletFactory.open($scope.selectedWalletId, passphrase);
|
||||
} catch (e) {
|
||||
errMsg = e.message;
|
||||
};
|
||||
if (!w) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', errMsg || 'Wrong password');
|
||||
$rootScope.$digest();
|
||||
return;
|
||||
}
|
||||
$rootScope.updatingBalance = true;
|
||||
controllerUtils.startNetwork(w, $scope);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue