2015-03-06 12:00:10 -03:00
'use strict' ;
angular . module ( 'copayApp.controllers' ) . controller ( 'copayersController' ,
2016-06-10 15:16:02 -03:00
function ( $scope , $rootScope , $timeout , $log , $modal , $ionicModal , profileService , go , notification , platformInfo , gettext , gettextCatalog ) {
2015-03-06 12:00:10 -03:00
var self = this ;
2016-05-31 18:56:02 -03:00
var isCordova = platformInfo . isCordova ;
2016-06-01 16:07:25 -03:00
var isWP = platformInfo . isWP ;
var isAndroid = platformInfo . isAndroid ;
2015-03-06 12:00:10 -03:00
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
2016-03-09 11:53:47 -03:00
// Note that this is ONLY triggered when the page is opened
2016-06-09 10:11:37 -03:00
// IF a wallet is incomplete and copay is at /#copayers
2016-03-09 11:53:47 -03:00
// and the user switch to an other complete wallet
// THIS IS NOT TRIGGERED.
//
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 ;
}
} ;
var _modalDeleteWallet = function ( ) {
2016-06-10 15:16:02 -03:00
$scope . title = delete _msg ;
$scope . accept _msg = accept _msg ;
$scope . cancel _msg = cancel _msg ;
$scope . confirm _msg = confirm _msg ;
$scope . okAction = doDeleteWallet ;
$scope . loading = false ;
2015-03-06 12:00:10 -03:00
2016-06-10 15:16:02 -03:00
$ionicModal . fromTemplateUrl ( 'views/modals/confirmation.html' , {
scope : $scope ,
animation : 'slide-in-up'
} ) . then ( function ( modal ) {
$scope . confirmationModal = modal ;
$scope . confirmationModal . show ( ) ;
2015-03-06 12:00:10 -03:00
} ) ;
} ;
2016-06-06 12:21:15 -03:00
var doDeleteWallet = function ( ) {
2015-03-06 12:00:10 -03:00
var fc = profileService . focusedClient ;
2016-01-28 16:49:31 -03:00
var walletName = fc . credentials . walletName ;
2016-06-06 12:21:15 -03:00
profileService . deleteWalletClient ( fc , function ( err ) {
2016-01-28 16:49:31 -03:00
if ( err ) {
self . error = err . message || err ;
$timeout ( function ( ) {
$scope . $digest ( ) ;
} ) ;
} else {
go . walletHome ( ) ;
$timeout ( function ( ) {
notification . success (
2016-06-09 10:11:37 -03:00
gettextCatalog . getString ( 'Success' ) ,
gettextCatalog . getString ( 'The wallet "{{walletName}}" was deleted' , {
walletName : walletName
} )
2016-01-28 16:49:31 -03:00
) ;
} ) ;
}
} ) ;
2015-03-06 12:00:10 -03:00
} ;
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 ) {
2016-06-09 10:11:37 -03:00
doDeleteWallet ( ) ;
2015-03-06 12:00:10 -03:00
}
} ,
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 ) {
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
}
} ;
2015-07-29 12:37:51 -03:00
} ) ;