bp to walletService

This commit is contained in:
Matias Alejo Garcia 2016-08-29 15:49:05 -03:00
parent 410153a2da
commit aa42db1458
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
3 changed files with 25 additions and 89 deletions

View File

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('bitpayCardController', function($scope, $rootScope, $timeout, $log, $ionicModal, lodash, bitpayCardService, configService, profileService, walletService, fingerprintService, ongoingProcess, bwcError, bitcore, pbkdf2Service, moment, platformInfo) {
angular.module('copayApp.controllers').controller('bitpayCardController', function($scope, $rootScope, $timeout, $log, $ionicModal, lodash, bitpayCardService, configService, profileService, walletService, ongoingProcess, pbkdf2Service, moment, platformInfo) {
var self = this;
var wallet;
@ -205,7 +205,6 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
};
walletService.createTx(wallet, txp, function(err, createdTxp) {
ongoingProcess.set('Processing Transaction...', false);
if (err) {
self.error = bwcError.msg(err);
$timeout(function() {
@ -213,10 +212,9 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
});
return;
}
self.confirmTx(createdTxp, function(err, tx) {
ongoingProcess.set('Processing Transaction...', false);
walletService.publishAndSign(createdTxp, function(err, tx) {
if (err) {
self.error = bwcError.msg(err);
self.error = err;
$timeout(function() {
$scope.$digest();
});
@ -234,55 +232,6 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
}, 100);
};
this.confirmTx = function(txp, cb) {
fingerprintService.check(wallet, function(err) {
if (err) {
$log.debug(err);
return cb(err);
}
walletService.handleEncryptedWallet(wallet, function(err) {
if (err) {
$log.debug(err);
return bwcError.cb(err, null, cb);
}
ongoingProcess.set('Processing Transaction...', true);
walletService.publishTx(wallet, txp, function(err, publishedTxp) {
if (err) {
$log.debug(err);
return bwcError.cb(err, null, cb);
}
walletService.signTx(wallet, publishedTxp, function(err, signedTxp) {
walletService.lock(wallet);
if (err) {
$log.debug(err);
walletService.removeTx(wallet, signedTxp, function(err) {
if (err) $log.debug(err);
});
return bwcError.cb(err, null, cb);
}
walletService.broadcastTx(wallet, signedTxp, function(err, broadcastedTxp) {
if (err) {
$log.debug(err);
walletService.removeTx(wallet, broadcastedTxp, function(err) {
if (err) $log.debug(err);
});
return bwcError.cb(err, null, cb);
}
$timeout(function() {
return cb(null, broadcastedTxp);
}, 5000);
});
});
});
});
});
};
this.authenticate = function() {
self.error = null;

View File

@ -48,10 +48,6 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
}, 10);
};
$scope.$on('$destroy', function() {
walletService.lock($scope.wallet);
});
$scope.reject = function(txp) {
$scope.loading = true;
$scope.error = null;

View File

@ -208,53 +208,44 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
self.error = err.message ||  bwcError.msg(err);
return;
}
fingerprintService.check(wallet, function(err) {
walletService.prepare(wallet, txp, function(err, password) {
if (err) {
self.error = err.message ||  bwcError.msg(err);
return;
}
walletService.handleEncryptedWallet(wallet, function(err) {
ongoingProcess.set('signingTx', true);
walletService.publishTx(wallet, createdTxp, function(err, publishedTxp) {
if (err) {
ongoingProcess.clear();
self.error = err.message ||  bwcError.msg(err);
return;
}
ongoingProcess.set('signingTx', true);
walletService.publishTx(wallet, createdTxp, function(err, publishedTxp) {
walletService.signTx(wallet, publishedTxp, function(err, password, signedTxp) {
walletService.removeTx(wallet, signedTxp, function(err) {
if (err) $log.debug(err);
});
ongoingProcess.clear();
if (err) {
ongoingProcess.clear();
self.error = err.message ||  bwcError.msg(err);
return;
}
walletService.signTx(wallet, publishedTxp, function(err, signedTxp) {
walletService.lock(wallet);
walletService.removeTx(wallet, signedTxp, function(err) {
if (err) $log.debug(err);
});
var rawTx = signedTxp.raw;
var data = {
refundAddress: refundAddress,
signedTransaction: rawTx,
priceUuid: self.sellPrice.priceUuid,
useCurrentPrice: self.sellPrice.priceUuid ? false : true,
ip: null
};
ongoingProcess.set('Seling Bitcoin', true);
glideraService.sell(token, twoFaCode, data, function(err, data) {
ongoingProcess.clear();
if (err) {
self.error = err.message ||  bwcError.msg(err);
return;
}
var rawTx = signedTxp.raw;
var data = {
refundAddress: refundAddress,
signedTransaction: rawTx,
priceUuid: self.sellPrice.priceUuid,
useCurrentPrice: self.sellPrice.priceUuid ? false : true,
ip: null
};
ongoingProcess.set('Seling Bitcoin', true);
glideraService.sell(token, twoFaCode, data, function(err, data) {
ongoingProcess.clear();
if (err) {
self.error = err.message ||  bwcError.msg(err);
return;
}
self.success = data;
$scope.update();
});
self.success = data;
$scope.update();
});
});
});