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

65 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-08-12 16:04:17 -03:00
'use strict';
2016-09-12 15:04:12 -03:00
angular.module('copayApp.controllers').controller('tabReceiveController', function($scope, $timeout, $log, $ionicModal, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService) {
2016-08-15 11:56:59 -03:00
$scope.isCordova = platformInfo.isCordova;
2016-09-21 17:12:25 -03:00
$scope.isNW = platformInfo.isNW;
2016-08-12 16:04:17 -03:00
2016-09-21 17:12:25 -03:00
$scope.wallets = profileService.getWallets({
onlyComplete: true
});
2016-09-12 15:04:12 -03:00
2016-09-15 09:58:57 -03:00
$scope.checkTips = function(force) {
2016-09-12 15:04:12 -03:00
storageService.getReceiveTipsAccepted(function(err, accepted) {
2016-09-12 16:41:04 -03:00
if (err) $log.warn(err);
2016-09-15 09:58:57 -03:00
if (accepted && !force) return;
2016-09-12 15:04:12 -03:00
$timeout(function() {
$ionicModal.fromTemplateUrl('views/modals/receive-tips.html', {
scope: $scope
}).then(function(modal) {
$scope.receiveTipsModal = modal;
$scope.receiveTipsModal.show();
});
2016-09-15 09:58:57 -03:00
}, force ? 1 : 1000);
2016-09-12 15:04:12 -03:00
});
2016-09-12 16:41:04 -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-09-21 17:12:25 -03:00
$scope.setAddress();
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-09-21 17:12:25 -03:00
$scope.setAddress = function(forceNew) {
2016-08-15 11:56:59 -03:00
if ($scope.generatingAddress) return;
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-09-21 17:12:25 -03:00
walletService.getAddress($scope.wallet, forceNew, function(err, addr) {
2016-08-12 16:04:17 -03:00
$scope.generatingAddress = false;
2016-09-21 17:12:25 -03:00
if (err || lodash.isEmpty(addr)) {
popupService.showAlert(gettextCatalog.getString('Error'), err || gettextCatalog.getString('Address is empty'));
return;
2016-08-12 16:04:17 -03:00
}
2016-09-21 17:12:25 -03:00
$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
};
2016-09-21 17:12:25 -03:00
if (!$scope.isCordova) $scope.checkTips();
2016-08-12 16:04:17 -03:00
});