go from create new shared to copayers

This commit is contained in:
Gabriel Bazán 2016-09-22 16:04:05 -03:00
commit b713d26173
6 changed files with 65 additions and 45 deletions

View file

@ -2,23 +2,43 @@
angular.module('copayApp.controllers').controller('copayersController',
function($scope, $log, $ionicNavBarDelegate, $timeout, $stateParams, $state, $rootScope, lodash, profileService, walletService, popupService, platformInfo, gettextCatalog, ongoingProcess) {
if (!$stateParams.walletId) {
$log.debug('No wallet provided...back to home');
return $state.go('tabs.home');
}
var wallet = profileService.getWallet($stateParams.walletId);
$ionicNavBarDelegate.title(wallet.name);
$scope.$on("$ionicView.enter", function(event, data) {
init();
});
var secret;
try {
secret = wallet.status.wallet.secret;
} catch (e) {};
var init = function() {
$scope.fromAddShared = $stateParams.fromAddShared;
$scope.isCordova = platformInfo.isCordova;
$scope.wallet = profileService.getWallet($stateParams.walletId);
updateWallet();
};
$scope.wallet = wallet;
$scope.secret = secret;
$scope.copayers = wallet.status.wallet.copayers;
$scope.isCordova = platformInfo.isCordova;
$rootScope.$on('bwsEvent', function() {
updateWallet();
});
var updateWallet = function() {
$log.debug('Updating wallet:' + $scope.wallet.name)
walletService.getStatus($scope.wallet, {}, function(err, status) {
if (err) {
$log.error(err); //TODO
return;
}
$scope.wallet.status = status;
$scope.copayers = $scope.wallet.status.wallet.copayers;
$scope.secret = $scope.wallet.status.wallet.secret;
$timeout(function() {
$scope.$apply();
});
if (status.wallet.status == 'complete') {
$scope.wallet.openWallet(function(err, status) {
if (err) $log.error(err);
$scope.goHome();
});
}
});
};
$scope.showDeletePopup = function() {
popupService.showConfirm(gettextCatalog.getString('Confirm'), gettextCatalog.getString('Are you sure you want to delete this wallet?'), null, null, function(res) {
@ -28,19 +48,19 @@ angular.module('copayApp.controllers').controller('copayersController',
function deleteWallet() {
ongoingProcess.set('deletingWallet', true);
profileService.deleteWalletClient(wallet, function(err) {
profileService.deleteWalletClient($scope.wallet, function(err) {
ongoingProcess.set('deletingWallet', false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err.message || err);
} else {
$state.go('tabs.home');
$scope.goHome();
}
});
};
$scope.copySecret = function() {
if ($scope.isCordova) {
window.cordova.plugins.clipboard.copy(secret);
window.cordova.plugins.clipboard.copy($scope.secret);
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
}
};
@ -48,28 +68,14 @@ angular.module('copayApp.controllers').controller('copayersController',
$scope.shareSecret = function() {
if ($scope.isCordova) {
var message = gettextCatalog.getString('Join my Copay wallet. Here is the invitation code: {{secret}} You can download Copay for your phone or desktop at https://copay.io', {
secret: secret
secret: $scope.secret
});
window.plugins.socialsharing.share(message, gettextCatalog.getString('Invitation to share a Copay Wallet'), null, null);
}
};
$rootScope.$on('bwsEvent', function() {
updateWallet();
});
var updateWallet = function() {
$log.debug('Updating wallet:' + wallet.name)
walletService.getStatus(wallet, {}, function(err, status) {
if (err) {
$log.error(err); //TODO
return;
}
wallet.status = status;
$scope.copayers = wallet.status.wallet.copayers;
$timeout(function() {
$scope.$apply();
});
});
$scope.goHome = function() {
$state.go('tabs.home');
};
});