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

87 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-08-12 16:04:17 -03:00
'use strict';
2016-09-26 11:26:10 -03:00
angular.module('copayApp.controllers').controller('tabReceiveController', function($scope, $timeout, $log, $ionicModal, $state, $ionicHistory, 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
$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-09-26 11:26:10 -03:00
if ($scope.generatingAddress || !$scope.wallet.isComplete()) return;
2016-08-15 11:56:59 -03:00
2016-08-30 15:43:17 -03:00
$scope.addr = null;
2016-08-12 16:04:17 -03:00
$scope.generatingAddress = true;
2016-09-29 19:52:26 -03:00
walletService.getAddress($scope.wallet, forceNew, function(err, addr) {
$scope.generatingAddress = false;
if (err) popupService.showAlert(gettextCatalog.getString('Error'), err);
$scope.addr = addr;
if ($scope.wallet.showBackupNeededModal) $scope.openBackupNeededModal();
2016-09-30 16:55:30 -03:00
$scope.$apply();
2016-09-23 12:07:56 -03:00
});
2016-09-29 19:52:26 -03:00
};
2016-09-26 11:26:10 -03:00
$scope.goCopayers = function() {
$ionicHistory.removeBackView();
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$state.go('tabs.home');
$timeout(function() {
$state.transitionTo('tabs.copayers', {
walletId: $scope.wallet.credentials.walletId
});
}, 100);
};
2016-09-26 16:11:45 -03:00
$scope.openBackupNeededModal = function() {
2016-09-27 10:59:08 -03:00
$ionicModal.fromTemplateUrl('views/includes/backupNeededPopup.html', {
scope: $scope,
backdropClickToClose: false,
hardwareBackButtonClose: false
}).then(function(modal) {
$scope.BackupNeededModal = modal;
$scope.BackupNeededModal.show();
});
2016-09-26 13:05:15 -03:00
};
2016-09-26 16:11:45 -03:00
$scope.close = function() {
$scope.BackupNeededModal.hide();
$scope.BackupNeededModal.remove();
profileService.setBackupNeededModalFlag($scope.wallet.credentials.walletId);
};
$scope.doBackup = function() {
$scope.close();
$scope.goToBackupFlow();
2016-09-26 13:05:15 -03:00
};
$scope.goToBackupFlow = function() {
2016-09-26 16:11:45 -03:00
$state.go('tabs.receive.backupWarning', {
from: 'tabs.receive',
2016-09-26 13:05:15 -03:00
walletId: $scope.wallet.credentials.walletId
});
2016-09-29 19:52:26 -03:00
};
$scope.$on('Wallet/Changed', function(event, wallet) {
if (!wallet) {
$log.debug('No wallet provided');
return;
}
$scope.wallet = wallet;
$log.debug('Wallet changed: ' + wallet.name);
$timeout(function() {
2016-09-30 16:55:30 -03:00
$scope.setAddress();
2016-09-29 19:52:26 -03:00
}, 100);
});
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.wallets = profileService.getWallets();
});
2016-08-12 16:04:17 -03:00
});