2015-03-06 12:00:10 -03:00
'use strict' ;
angular . module ( 'copayApp.controllers' ) . controller ( 'importLegacyController' ,
2015-04-29 19:19:10 -03:00
function ( $rootScope , $scope , $log , $timeout , notification , legacyImportService , profileService , go , lodash , bitcore , gettext , gettextCatalog ) {
2015-03-06 12:00:10 -03:00
var self = this ;
self . messages = [ ] ;
self . fromCloud = true ;
self . server = "https://insight.bitpay.com:443/api/email" ;
$rootScope . $on ( 'Local/ImportStatusUpdate' , function ( event , status ) {
$timeout ( function ( ) {
$log . debug ( status ) ;
self . messages . unshift ( {
message : status ,
} ) ;
var op = 1 ;
lodash . each ( self . messages , function ( m ) {
if ( op < 0.1 ) op = 0.1 ;
m . opacity = op ;
op = op - 0.15 ;
} ) ;
} , 100 ) ;
} ) ;
self . scan = function ( ids ) {
2016-01-16 17:04:01 -06:00
$log . debug ( '### Scanning: ' + ids )
2015-03-06 12:00:10 -03:00
var i = 0 ;
lodash . each ( ids , function ( id ) {
$rootScope . $emit ( 'Local/WalletImported' , id ) ;
if ( ++ i == ids . length ) {
go . walletHome ( ) ;
} ;
} ) ;
} ;
self . import = function ( form ) {
var username = form . username . $modelValue ;
var password = form . password . $modelValue ;
var serverURL = form . server . $modelValue ;
var fromCloud = form . fromCloud . $modelValue ;
self . error = null ;
self . importing = true ;
$timeout ( function ( ) {
legacyImportService . import ( username , password , serverURL , fromCloud , function ( err , ids , toScanIds ) {
if ( err || ! ids || ! ids . length ) {
self . importing = false ;
2015-04-29 19:19:10 -03:00
self . error = err || gettext ( 'Failed to import wallets' ) ;
2015-03-06 12:00:10 -03:00
return ;
}
2015-04-29 19:19:10 -03:00
notification . success ( gettextCatalog . getString ( '{{len}} wallets imported. Funds scanning in progress. Hold on to see updated balance' , { len : ids . length } ) ) ;
2015-03-06 12:00:10 -03:00
self . scan ( toScanIds ) ;
} ) ;
} , 100 ) ;
} ;
// TODO destroy event...
} ) ;