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

54 lines
1.4 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-30 15:43:17 -03:00
if (!wallet) {
2016-08-24 11:21:07 -03:00
$log.debug('No wallet provided');
return;
}
2016-08-30 15:43:17 -03:00
$scope.wallet = wallet;
2016-08-23 12:57:58 -03:00
$log.debug('Wallet changed: ' + wallet.name);
2016-08-30 17:07:49 -03:00
$scope.setAddress(wallet);
2016-08-23 12:57:58 -03:00
});
2016-08-12 16:04:17 -03:00
$scope.shareAddress = function(addr) {
2016-08-30 17:07:49 -03:00
if ($scope.generatingAddress) return;
2016-08-12 16:04:17 -03:00
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-15 11:56:59 -03:00
if ($scope.generatingAddress) return;
2016-08-30 15:43:17 -03:00
var wallet = wallet || $scope.wallet;
$scope.error = null;
2016-08-30 15:43:17 -03:00
$scope.addr = null;
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;
}
2016-08-30 15:43:17 -03:00
$scope.$apply();
2016-08-12 16:04:17 -03:00
});
2016-08-30 15:43:17 -03:00
}, 1);
2016-08-12 16:04:17 -03:00
};
});