Wallet/src/js/controllers/tab-receive.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-08-12 16:04:17 -03:00
'use strict';
angular.module('copayApp.controllers').controller('tabReceiveController', function($scope, $timeout, $log, platformInfo, walletService, profileService, configService, lodash, gettextCatalog) {
2016-08-15 11:56:59 -03:00
$scope.isCordova = platformInfo.isCordova;
2016-08-12 16:04:17 -03:00
$scope.init = function() {
$scope.wallets = profileService.getWallets({
onlyComplete: true
});
2016-08-12 16:04:17 -03:00
$scope.isCordova = platformInfo.isCordova;
$scope.isNW = platformInfo.isNW;
2016-08-23 12:57:58 -03:00
}
2016-08-12 16:04:17 -03:00
2016-08-23 12:57:58 -03:00
$scope.$on('Wallet/Changed', function(event, wallet) {
2016-08-25 10:19:39 -03:00
if (lodash.isEmpty(wallet)) {
2016-08-24 11:21:07 -03:00
$log.debug('No wallet provided');
return;
}
2016-08-24 12:29:22 -03:00
$scope.defaultWallet = wallet;
2016-08-23 12:57:58 -03:00
$log.debug('Wallet changed: ' + wallet.name);
$scope.setAddress(wallet);
});
2016-08-12 16:04:17 -03:00
$scope.shareAddress = function(addr) {
if ($scope.isCordova) {
window.plugins.socialsharing.share('bitcoin:' + addr, null, null, null);
}
};
2016-08-23 12:57:58 -03:00
$scope.setAddress = function(wallet, forceNew) {
2016-08-23 15:13:51 -03:00
var wallet = wallet || $scope.defaultWallet;
2016-08-15 11:56:59 -03:00
if ($scope.generatingAddress) return;
$scope.addr = null;
$scope.error = null;
2016-08-15 11:56:59 -03:00
2016-08-23 15:13:51 -03:00
if (wallet && !wallet.isComplete()) {
2016-08-15 11:56:59 -03:00
$timeout(function() {
$scope.$digest();
});
return;
}
2016-08-12 16:04:17 -03:00
$scope.generatingAddress = true;
2016-08-23 12:57:58 -03:00
2016-08-12 16:04:17 -03:00
$timeout(function() {
2016-08-23 12:57:58 -03:00
walletService.getAddress(wallet, forceNew, function(err, addr) {
2016-08-12 16:04:17 -03:00
$scope.generatingAddress = false;
if (err) {
$scope.error = err;
2016-08-12 16:04:17 -03:00
} else {
if (addr)
$scope.addr = addr;
}
$scope.$digest();
});
});
};
});