2015-03-06 12:00:10 -03:00
'use strict' ;
angular . module ( 'copayApp.controllers' ) . controller ( 'copayersController' ,
2016-08-15 16:07:30 -03:00
function ( $scope , $rootScope , $timeout , $log , $ionicModal , profileService , go , notification , platformInfo , gettext , gettextCatalog , $stateParams , $state ) {
2015-03-06 12:00:10 -03:00
var self = this ;
2016-08-15 16:07:30 -03:00
$scope . 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
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
} ;
2016-08-15 16:07:30 -03:00
$scope . deleteWallet = function ( ) {
2015-03-06 12:00:10 -03:00
var fc = profileService . focusedClient ;
2016-08-15 16:07:30 -03:00
if ( $scope . isCordova ) {
2015-03-06 12:00:10 -03:00
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 ( ) ;
}
} ;
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-15 16:07:30 -03:00
if ( ! $stateParams . walletId ) {
$log . debug ( 'No wallet provided...back to home' ) ;
return $state . transitionTo ( 'tabs.home' )
}
var wallet = profileService . getWallet ( $stateParams . walletId ) ;
var secret = wallet . status . wallet . secret ;
try {
secret = wallet . status . wallet . secret ;
} catch ( e ) { } ;
$scope . wallet = wallet ;
$scope . secret = secret ;
} ) ;