2015-03-06 12:00:10 -03:00
'use strict' ;
angular . module ( 'copayApp.controllers' ) . controller ( 'copayersController' ,
2015-04-29 19:19:10 -03:00
function ( $scope , $rootScope , $timeout , $log , $modal , profileService , go , notification , isCordova , gettext , gettextCatalog ) {
2015-03-06 12:00:10 -03:00
var self = this ;
2015-07-29 20:12:37 +09:00
var delete _msg = gettextCatalog . getString ( 'Are you sure you want to delete this wallet?' ) ;
2015-07-29 12:37:51 -03:00
var accept _msg = gettextCatalog . getString ( 'Accept' ) ;
2015-07-29 20:12:37 +09:00
var cancel _msg = gettextCatalog . getString ( 'Cancel' ) ;
var confirm _msg = gettextCatalog . getString ( 'Confirm' ) ;
2015-03-06 12:00:10 -03:00
self . init = function ( ) {
var fc = profileService . focusedClient ;
if ( fc . isComplete ( ) ) {
$log . debug ( 'Wallet Complete...redirecting' )
go . walletHome ( ) ;
return ;
}
self . loading = false ;
self . isCordova = isCordova ;
} ;
var _modalDeleteWallet = function ( ) {
2015-04-29 19:19:10 -03:00
var ModalInstanceCtrl = function ( $scope , $modalInstance , gettext ) {
2015-07-29 20:12:37 +09:00
$scope . title = delete _msg ;
2015-03-06 12:00:10 -03:00
$scope . loading = false ;
$scope . ok = function ( ) {
$scope . loading = true ;
2015-07-29 12:37:51 -03:00
$modalInstance . close ( accept _msg ) ;
2015-03-06 12:00:10 -03:00
} ;
$scope . cancel = function ( ) {
2015-07-29 20:12:37 +09:00
$modalInstance . dismiss ( cancel _msg ) ;
2015-03-06 12:00:10 -03:00
} ;
} ;
var modalInstance = $modal . open ( {
templateUrl : 'views/modals/confirmation.html' ,
windowClass : 'full' ,
controller : ModalInstanceCtrl
} ) ;
modalInstance . result . then ( function ( ok ) {
if ( ok ) {
_deleteWallet ( ) ;
}
} ) ;
} ;
var _deleteWallet = function ( ) {
var fc = profileService . focusedClient ;
$timeout ( function ( ) {
var fc = profileService . focusedClient ;
var walletName = fc . credentials . walletName ;
profileService . deleteWalletFC ( { } , function ( err ) {
if ( err ) {
this . error = err . message || err ;
console . log ( err ) ;
$timeout ( function ( ) {
$scope . $digest ( ) ;
} ) ;
} else {
go . walletHome ( ) ;
$timeout ( function ( ) {
2015-07-29 20:12:37 +09:00
notification . success ( gettextCatalog . getString ( 'Success' ) , gettextCatalog . getString ( 'The wallet "{{walletName}}" was deleted' , { walletName : walletName } ) ) ;
2015-03-06 12:00:10 -03:00
} ) ;
}
} ) ;
} , 100 ) ;
} ;
self . deleteWallet = function ( ) {
var fc = profileService . focusedClient ;
if ( isCordova ) {
navigator . notification . confirm (
2015-07-29 20:12:37 +09:00
delete _msg ,
2015-03-06 12:00:10 -03:00
function ( buttonIndex ) {
2015-07-29 12:37:51 -03:00
if ( buttonIndex == 1 ) {
2015-03-06 12:00:10 -03:00
_deleteWallet ( ) ;
}
} ,
2015-07-29 12:37:51 -03:00
confirm _msg , [ accept _msg , cancel _msg ]
2015-03-06 12:00:10 -03:00
) ;
} else {
_modalDeleteWallet ( ) ;
}
} ;
self . copySecret = function ( secret ) {
if ( isCordova ) {
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
}
} ;
self . shareSecret = function ( secret ) {
if ( isCordova ) {
if ( isMobile . Android ( ) || isMobile . Windows ( ) ) {
window . ignoreMobilePause = true ;
}
2015-07-29 20:12:37 +09: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 } ) ;
window . plugins . socialsharing . share ( message , gettextCatalog . getString ( 'Invitation to share a Copay Wallet' ) , null , null ) ;
2015-03-06 12:00:10 -03:00
}
} ;
2015-07-29 12:37:51 -03:00
} ) ;