Wallet/src/js/controllers/addresses.js

48 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-11-14 14:52:10 -03:00
'use strict';
2016-11-15 17:40:44 -03:00
angular.module('copayApp.controllers').controller('addressesController', function($scope, $stateParams, $timeout, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService) {
2016-11-14 16:51:11 -03:00
var ADDRESS_LIMIT = 5;
2016-11-15 17:40:44 -03:00
var config;
var unitName;
var unitToSatoshi;
var satToUnit;
var unitDecimals;
2016-11-14 14:52:10 -03:00
$scope.wallet = profileService.getWallet($stateParams.walletId);
2016-11-14 16:51:11 -03:00
$scope.showInfo = false;
2016-11-14 14:52:10 -03:00
2016-11-14 16:51:11 -03:00
$scope.$on("$ionicView.beforeEnter", function(event, data) {
2016-11-15 17:40:44 -03:00
config = configService.getSync().wallet.settings;
unitToSatoshi = config.unitToSatoshi;
satToUnit = 1 / unitToSatoshi;
unitName = config.unitName;
unitDecimals = config.unitDecimals;
2016-11-14 16:51:11 -03:00
// $scope.unusedAddresses = getUnusedAddreses(); No backend support TODO
$scope.unusedAddresses = [{
createdOn: 1479138140,
address: "0m9sad00810m0m1d2192d9u12d9",
path: 'xpub/0/1'
}];
ongoingProcess.set('extractingWalletInfo', true);
2016-11-15 17:40:44 -03:00
walletService.getBalance($scope.wallet, {}, function(err, resp) {
2016-11-14 16:51:11 -03:00
ongoingProcess.set('extractingWalletInfo', false);
2016-11-15 17:40:44 -03:00
if (err) {
return popupService.showAlert(gettextCatalog.getString('Error'), err);
}
2016-11-14 16:51:11 -03:00
2016-11-15 17:40:44 -03:00
$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();
2016-11-14 16:51:11 -03:00
});
});
$scope.showInformation = function() {
$timeout(function() {
$scope.showInfo = !$scope.showInfo;
$ionicScrollDelegate.resize();
});
};
2016-11-14 14:52:10 -03:00
});