Wallet/src/js/controllers/copayers.js

70 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('copayersController',
2016-08-25 13:09:50 -03:00
function($scope, $log, $ionicPopup, profileService, platformInfo, gettextCatalog, $stateParams, ongoingProcess, $state) {
if (!$stateParams.walletId) {
$log.debug('No wallet provided...back to home');
return $state.transitionTo('tabs.home');
}
2015-03-06 12:00:10 -03:00
2016-08-25 13:09:50 -03:00
var wallet = profileService.getWallet($stateParams.walletId);
var secret;
try {
secret = wallet.status.wallet.secret;
} catch (e) {};
2015-03-06 12:00:10 -03:00
2016-08-25 13:09:50 -03:00
$scope.wallet = wallet;
$scope.secret = secret;
$scope.isCordova = platformInfo.isCordova;
2015-03-06 12:00:10 -03:00
2016-08-25 13:09:50 -03:00
$scope.showDeletePopup = function() {
var popup = $ionicPopup.show({
template: '<span>' + gettextCatalog.getString('Are you sure you want to delete this wallet?') + '</span>',
title: gettextCatalog.getString('Confirm'),
buttons: [
{
text: gettextCatalog.getString('Cancel'),
onTap: function(e) {
popup.close();
}
},
{
text: gettextCatalog.getString('Accept'),
type: 'button-positive',
onTap: function(e) {
deleteWallet();
popup.close();
}
}
]
2015-03-06 12:00:10 -03:00
});
};
2016-08-25 13:09:50 -03:00
function deleteWallet() {
ongoingProcess.set('deletingWallet', true);
2016-08-19 13:09:27 -03:00
profileService.deleteWalletClient(wallet, function(err) {
2016-08-25 13:09:50 -03:00
ongoingProcess.set('deletingWallet', false);
2016-01-28 16:49:31 -03:00
if (err) {
2016-08-25 13:09:50 -03:00
$scope.error = err.message || err;
2016-01-28 16:49:31 -03:00
} else {
2016-08-25 13:09:50 -03:00
$state.transitionTo('tabs.home');
2016-01-28 16:49:31 -03:00
}
});
2015-03-06 12:00:10 -03:00
};
2016-08-15 16:07:30 -03:00
$scope.copySecret = function() {
if ($scope.isCordova) {
2015-03-06 12:00:10 -03:00
window.cordova.plugins.clipboard.copy(secret);
2015-07-29 20:12:37 +09:00
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
2015-03-06 12:00:10 -03:00
}
};
2016-08-15 16:07:30 -03:00
$scope.shareSecret = function() {
if ($scope.isCordova) {
2016-06-09 10:11:37 -03:00
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
});
2015-07-29 20:12:37 +09:00
window.plugins.socialsharing.share(message, gettextCatalog.getString('Invitation to share a Copay Wallet'), null, null);
2015-03-06 12:00:10 -03:00
}
};
2016-08-19 13:09:27 -03:00
});