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-08-12 16:04:17 -03:00
|
|
|
|
|
|
|
|
$scope.init = function() {
|
2016-08-24 19:32:49 -03:00
|
|
|
$scope.wallets = profileService.getWallets({
|
|
|
|
|
onlyComplete: true
|
|
|
|
|
});
|
2016-08-12 16:04:17 -03:00
|
|
|
$scope.isCordova = platformInfo.isCordova;
|
|
|
|
|
$scope.isNW = platformInfo.isNW;
|
2016-09-12 16:41:04 -03:00
|
|
|
$scope.checkTips();
|
|
|
|
|
}
|
2016-09-12 15:04:12 -03:00
|
|
|
|
2016-09-12 16:41:04 -03:00
|
|
|
$scope.checkTips = function() {
|
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);
|
|
|
|
|
if (accepted) 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();
|
|
|
|
|
});
|
|
|
|
|
}, 1000);
|
|
|
|
|
});
|
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-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.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) {
|
2016-09-01 10:56:13 -03:00
|
|
|
popupService.showAlert(gettextCatalog.getString('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
|
|
|
};
|
|
|
|
|
});
|