show first 5 addresses with balance

This commit is contained in:
Javier 2016-11-15 17:40:44 -03:00
commit b676c5e37e
3 changed files with 31 additions and 13 deletions

View file

@ -1,11 +1,22 @@
'use strict';
angular.module('copayApp.controllers').controller('addressesController', function($scope, $stateParams, $timeout, $ionicScrollDelegate, ongoingProcess, lodash, profileService, walletService) {
angular.module('copayApp.controllers').controller('addressesController', function($scope, $stateParams, $timeout, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService) {
var ADDRESS_LIMIT = 5;
var config;
var unitName;
var unitToSatoshi;
var satToUnit;
var unitDecimals;
$scope.wallet = profileService.getWallet($stateParams.walletId);
$scope.showInfo = false;
$scope.$on("$ionicView.beforeEnter", function(event, data) {
config = configService.getSync().wallet.settings;
unitToSatoshi = config.unitToSatoshi;
satToUnit = 1 / unitToSatoshi;
unitName = config.unitName;
unitDecimals = config.unitDecimals;
// $scope.unusedAddresses = getUnusedAddreses(); No backend support TODO
$scope.unusedAddresses = [{
createdOn: 1479138140,
@ -14,17 +25,17 @@ angular.module('copayApp.controllers').controller('addressesController', functio
}];
ongoingProcess.set('extractingWalletInfo', true);
walletService.getMainAddresses($scope.wallet, ADDRESS_LIMIT, function(err, addresses) {
walletService.getBalance($scope.wallet, {}, function(err, resp) {
ongoingProcess.set('extractingWalletInfo', false);
$scope.addresses = lodash.map(addresses, function(addr) {
return {
createdOn: addr.createdOn,
address: addr.address,
path: addr.path.replace(/^m/g, 'xpub')
};
});
if (err) {
return popupService.showAlert(gettextCatalog.getString('Error'), err);
}
console.log($scope.addresses);
$scope.addresses = lodash.slice(resp.byAddress, 0, ADDRESS_LIMIT);
lodash.each($scope.addresses, function(a) {
a.balanceStr = (a.amount * satToUnit).toFixed(unitDecimals) + ' ' + unitName;
});
$scope.$digest();
});
});

View file

@ -784,6 +784,13 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
});
};
root.getBalance = function(wallet, opts, cb) {
opts = opts || {};
wallet.getBalance(opts, function(err, resp) {
return cb(err, resp);
});
};
root.getAddress = function(wallet, forceNew, cb) {
storageService.getLastAddress(wallet.id, function(err, addr) {
if (err) return cb(err);

View file

@ -25,10 +25,10 @@
</div>
<div ng-if="unusedAddresses[0]">
<div class="item" ng-repeat="uAddr in unusedAddresses track by $index">
{{uAddr.address}}
<div class="item" ng-repeat="uAddress in unusedAddresses track by $index">
{{uAddress.address}}
<span class="item-note">
{{uAddr.path}} {{uAddr.createdOn * 1000 | amDateFormat:'MMMM Do YYYY, hh:mm a'}}
{{uAddress.path}} {{uAddress.createdOn * 1000 | amDateFormat:'MMMM Do YYYY, hh:mm a'}}
</span>
</div>
</div>