2016-08-12 16:04:17 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-08-23 12:57:58 -03:00
|
|
|
angular.module('copayApp.controllers').controller('tabReceiveController', function($scope, $ionicPopover, $timeout, $log, platformInfo, nodeWebkit, 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.index = 0;
|
|
|
|
|
$scope.isCordova = platformInfo.isCordova;
|
|
|
|
|
$scope.isNW = platformInfo.isNW;
|
2016-08-23 12:57:58 -03:00
|
|
|
// $scope.setWallets();
|
2016-08-12 16:04:17 -03:00
|
|
|
$scope.setAddress(false);
|
2016-08-23 12:57:58 -03:00
|
|
|
// $scope.options = {
|
|
|
|
|
// loop: false,
|
|
|
|
|
// effect: 'flip',
|
|
|
|
|
// speed: 500,
|
|
|
|
|
// spaceBetween: 100
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// $scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
|
|
|
|
|
// // data.slider is the instance of Swiper
|
|
|
|
|
// $scope.slider = data.slider;
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// $scope.$on("$ionicSlides.slideChangeStart", function(event, data) {
|
|
|
|
|
// console.log('Slide change is beginning');
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// $scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
|
|
|
|
|
// $scope.index = data.slider.activeIndex;
|
|
|
|
|
// $scope.setAddress();
|
|
|
|
|
// });
|
|
|
|
|
}
|
2016-08-12 16:04:17 -03:00
|
|
|
|
2016-08-23 12:57:58 -03:00
|
|
|
$scope.copyToClipboard = function(addr, $event) {
|
2016-08-12 16:04:17 -03:00
|
|
|
|
2016-08-23 12:57:58 -03:00
|
|
|
var showPopover = function() {
|
2016-08-12 16:04:17 -03:00
|
|
|
|
2016-08-23 12:57:58 -03:00
|
|
|
$ionicPopover.fromTemplateUrl('views/includes/copyToClipboard.html', {
|
|
|
|
|
scope: $scope
|
|
|
|
|
}).then(function(popover) {
|
|
|
|
|
$scope.popover = popover;
|
|
|
|
|
$scope.popover.show($event);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$scope.close = function() {
|
|
|
|
|
$scope.popover.hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.popover.hide(); //close the popover after 0.7 seconds
|
|
|
|
|
}, 700);
|
|
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
|
$scope.popover.remove();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if ($scope.isCordova) {
|
|
|
|
|
window.cordova.plugins.clipboard.copy(addr);
|
|
|
|
|
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
|
|
|
|
|
} else if ($scope.isNW) {
|
|
|
|
|
nodeWebkit.writeToClipboard(addr);
|
|
|
|
|
showPopover($event);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.$on('Wallet/Changed', function(event, wallet) {
|
|
|
|
|
console.log(wallet);
|
|
|
|
|
$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) {
|
|
|
|
|
if (!wallet) return;
|
2016-08-15 11:56:59 -03:00
|
|
|
if ($scope.generatingAddress) return;
|
|
|
|
|
|
|
|
|
|
$scope.addr = null;
|
2016-08-12 16:04:17 -03:00
|
|
|
$scope.addrError = null;
|
2016-08-15 11:56:59 -03:00
|
|
|
|
|
|
|
|
if (!wallet.isComplete()) {
|
|
|
|
|
$scope.incomplete = true;
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.incomplete = false;
|
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.addrError = err;
|
|
|
|
|
} else {
|
|
|
|
|
if (addr)
|
|
|
|
|
$scope.addr = addr;
|
|
|
|
|
}
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$scope.setWallets = function() {
|
2016-08-15 11:56:59 -03:00
|
|
|
$scope.wallets = profileService.getWallets();
|
2016-08-12 16:04:17 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
});
|