2015-03-06 12:00:10 -03:00
'use strict' ;
angular . module ( 'copayApp.controllers' ) . controller ( 'backupController' ,
2015-04-29 19:19:10 -03:00
function ( $rootScope , $scope , $timeout , backupService , profileService , isMobile , isCordova , notification , go , gettext ) {
2015-03-06 12:00:10 -03:00
this . isSafari = isMobile . Safari ( ) ;
this . isCordova = isCordova ;
this . error = null ;
this . success = null ;
var fc = profileService . focusedClient ;
this . isEncrypted = fc . isPrivKeyEncrypted ( ) ;
this . downloadWalletBackup = function ( ) {
backupService . walletDownload ( this . password , function ( ) {
$rootScope . $emit ( 'Local/BackupDone' ) ;
2015-04-29 19:19:10 -03:00
notification . success ( gettext ( 'Backup created' ) , gettext ( 'Encrypted backup file saved' ) ) ;
2015-03-06 12:00:10 -03:00
go . walletHome ( ) ;
} ) ;
} ;
this . getBackup = function ( ) {
return backupService . walletExport ( this . password ) ;
} ;
this . viewWalletBackup = function ( ) {
var self = this ;
$timeout ( function ( ) {
self . backupWalletPlainText = self . getBackup ( ) ;
$rootScope . $emit ( 'Local/BackupDone' ) ;
} , 100 ) ;
} ;
this . copyWalletBackup = function ( ) {
var ew = this . getBackup ( ) ;
window . cordova . plugins . clipboard . copy ( ew ) ;
window . plugins . toast . showShortCenter ( 'Copied to clipboard' ) ;
$rootScope . $emit ( 'Local/BackupDone' ) ;
} ;
this . sendWalletBackup = function ( ) {
var fc = profileService . focusedClient ;
if ( isMobile . Android ( ) || isMobile . Windows ( ) ) {
window . ignoreMobilePause = true ;
}
window . plugins . toast . showShortCenter ( 'Preparing backup...' ) ;
var name = ( fc . credentials . walletName || fc . credentials . walletId ) ;
var ew = this . getBackup ( ) ;
var properties = {
subject : 'Copay Wallet Backup: ' + name ,
body : 'Here is the encrypted backup of the wallet ' + name + ': \n\n' + ew + '\n\n To import this backup, copy all text between {...}, including the symbols {}' ,
isHtml : false
} ;
$rootScope . $emit ( 'Local/BackupDone' ) ;
window . plugin . email . open ( properties ) ;
} ;
} ) ;