angular.module('copayApp.controllers').controller('paperWalletController',
  function($scope, $http, $timeout, $log, configService, profileService, go, addressService, bitcore) {
    self = this;
    var fc = profileService.focusedClient;
    var rawTx;

    self.onQrCodeScanned = function(data) {
      $scope.inputData = data;
      self.onData(data);
    }

    self.onData = function(data) {
      self.error = '';
      self.scannedKey = data;
      self.isPkEncrypted = (data.charAt(0) == '6');
    }

    self._scanFunds = function(cb) {
      function getPrivateKey(scannedKey, isPkEncrypted, passphrase, cb) {
        if (!isPkEncrypted) return cb(null, scannedKey);
        fc.decryptBIP38PrivateKey(scannedKey, passphrase, null, cb);
      };

      function getBalance(privateKey, cb) {
        fc.getBalanceFromPrivateKey(privateKey, cb);
      };

      function checkPrivateKey(privateKey) {
        try {
          new bitcore.PrivateKey(privateKey, 'livenet');
        } catch (err) {
          return false;
        }
        return true;
      }

      getPrivateKey(self.scannedKey, self.isPkEncrypted, $scope.passphrase, function(err, privateKey) {
        if (err) return cb(err);
        if (!checkPrivateKey(privateKey)) return cb(new Error('Invalid private key'));

        getBalance(privateKey, function(err, balance) {
          if (err) return cb(err);
          return cb(null, privateKey, balance);
        });
      });
    }

    self.scanFunds = function() {
      self.scanning = true;
      self.privateKey = '';
      self.balanceSat = 0;
      self.error = '';

      $timeout(function() {
        self._scanFunds(function(err, privateKey, balance) {
          if (err) {
            $log.error(err);
            self.error = err.message || err.toString();
          } else {
            self.privateKey = privateKey;
            self.balanceSat = balance;
            var config = configService.getSync().wallet.settings;
            self.balance = profileService.formatAmount(balance) + ' ' + config.unitName;
          }

          self.scanning = false;
          $timeout(function() {
            $scope.$apply();
          }, 1);
        });
      }, 100);
    }

    self._sweepWallet = function(cb) {
      addressService.getAddress(fc.credentials.walletId, true, function(err, destinationAddress) {
        if (err) return cb(err);

        fc.buildTxFromPrivateKey(self.privateKey, destinationAddress, null, function(err, tx) {
          if (err) return cb(err);

          fc.broadcastRawTx({
            rawTx: tx.serialize(),
            network: 'livenet'
          }, function(err, txid) {
            if (err) return cb(err);
            return cb(null, destinationAddress, txid);
          });
        });
      });
    };

    self.sweepWallet = function() {
      self.sending = true;
      self.error = '';

      $timeout(function() {
        self._sweepWallet(function(err, destinationAddress, txid) {
          if (err) {
            self.error = err.message || err.toString();
            $log.error(err);
          }
          self.sending = false;
          $timeout(function() {
            $scope.$apply();
            if (!err) go.walletHome();
          }, 1);
        });
      }, 100);
    }
  });

@@ -160,16 +160,26 @@
 Service,
+ txStatus,
  bitcore
@@ -1685,32 +1685,65 @@
 Key, balance) %7B%0A
+          self.scanning = false;%0A
           if (er
@@ -2114,106 +2114,22 @@
     
-self.scanning = false;%0A          $timeout(function() %7B%0A            $scope.$apply();%0A          %7D, 1
+$scope.$apply(
 );%0A 
@@ -2907,32 +2907,65 @@
 ddress, txid) %7B%0A
+          self.sending = false;%0A%0A
           if (er
@@ -3057,32 +3057,39 @@
 rr);%0A          %7D
+ else %7B
 %0A          self.
@@ -3087,90 +3087,91 @@
     
-self.sending = false;%0A          $timeout(function() %7B%0A            $scope.$apply();
+  txStatus.notify(%7B%0A              status: 'broadcasted'%0A            %7D, function() %7B
 %0A   
@@ -3183,17 +3183,9 @@
     
-if (!err)
+ 
  go.
@@ -3208,20 +3208,59 @@
         
-%7D, 1
+  %7D);%0A          %7D%0A%0A          $scope.$apply(
 );%0A     

add feedback print after sweep funds