2014-07-24 15:31:07 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('CopayersController',
|
2015-02-06 13:23:10 -03:00
|
|
|
function($scope, $rootScope, $timeout, go, identityService, notification, isCordova) {
|
2015-01-14 14:53:20 -03:00
|
|
|
var w = $rootScope.wallet;
|
2015-02-12 17:26:30 -03:00
|
|
|
|
|
|
|
|
|
2014-12-08 18:26:18 -03:00
|
|
|
$scope.init = function() {
|
2014-12-12 15:13:37 -03:00
|
|
|
$rootScope.title = 'Share this secret with your copayers';
|
2014-12-08 18:26:18 -03:00
|
|
|
$scope.loading = false;
|
|
|
|
|
$scope.secret = $rootScope.wallet.getSecret();
|
2015-02-06 13:23:10 -03:00
|
|
|
$scope.isCordova = isCordova;
|
2014-12-09 11:52:01 -03:00
|
|
|
|
|
|
|
|
w.on('publicKeyRingUpdated', $scope.updateList);
|
|
|
|
|
w.on('ready', $scope.updateList);
|
2015-02-12 17:26:30 -03:00
|
|
|
|
2014-12-09 11:52:01 -03:00
|
|
|
$scope.updateList();
|
2014-07-24 15:31:07 -03:00
|
|
|
};
|
|
|
|
|
|
2014-12-09 11:52:01 -03:00
|
|
|
$scope.updateList = function() {
|
|
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
|
|
|
|
|
$scope.copayers = $rootScope.wallet.getRegisteredPeerIds();
|
|
|
|
|
if (w.isComplete()) {
|
|
|
|
|
|
|
|
|
|
w.removeListener('publicKeyRingUpdated', $scope.updateList);
|
|
|
|
|
w.removeListener('ready', $scope.updateList);
|
|
|
|
|
go.walletHome();
|
2014-10-21 14:26:58 -03:00
|
|
|
}
|
2014-12-09 11:52:01 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
}, 1);
|
|
|
|
|
};
|
2015-01-14 14:53:20 -03:00
|
|
|
|
|
|
|
|
$scope.deleteWallet = function() {
|
2015-02-19 17:02:07 -03:00
|
|
|
$rootScope.starting = true;
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
identityService.deleteWallet(w, function(err) {
|
|
|
|
|
$rootScope.starting = false;
|
|
|
|
|
if (err) {
|
|
|
|
|
$scope.error = err.message || err;
|
|
|
|
|
copay.logger.warn(err);
|
|
|
|
|
$timeout(function () { $scope.$digest(); });
|
|
|
|
|
} else {
|
|
|
|
|
if ($rootScope.wallet) {
|
|
|
|
|
go.walletHome();
|
|
|
|
|
}
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
notification.success('Success', 'The wallet "' + (w.name || w.id) + '" was deleted');
|
|
|
|
|
});
|
2015-01-14 14:53:20 -03:00
|
|
|
}
|
2015-02-19 17:02:07 -03:00
|
|
|
});
|
|
|
|
|
}, 100);
|
2015-01-14 14:53:20 -03:00
|
|
|
};
|
|
|
|
|
|
2015-02-06 13:23:10 -03:00
|
|
|
$scope.copySecret = function(secret) {
|
|
|
|
|
if (isCordova) {
|
|
|
|
|
window.cordova.plugins.clipboard.copy(secret);
|
|
|
|
|
window.plugins.toast.showShortCenter('Copied to clipboard');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.shareSecret = function(secret) {
|
|
|
|
|
if (isCordova) {
|
|
|
|
|
if (isMobile.Android() || isMobile.Windows()) {
|
|
|
|
|
window.ignoreMobilePause = true;
|
|
|
|
|
}
|
|
|
|
|
window.plugins.socialsharing.share(secret, null, null, null);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-12 13:25:52 -03:00
|
|
|
});
|