refactor sign
This commit is contained in:
parent
6d35fe1239
commit
bef3e5789c
4 changed files with 139 additions and 340 deletions
|
|
@ -1463,20 +1463,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.setTab(tab, reset);
|
self.setTab(tab, reset);
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/RequestTouchid', function(event, cb) {
|
|
||||||
window.plugins.touchid.verifyFingerprint(
|
|
||||||
gettextCatalog.getString('Scan your fingerprint please'),
|
|
||||||
function(msg) {
|
|
||||||
// OK
|
|
||||||
return cb();
|
|
||||||
},
|
|
||||||
function(msg) {
|
|
||||||
// ERROR
|
|
||||||
return cb(gettext('Error with Touch ID:') + msg);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {
|
$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {
|
||||||
self.askPassword = {
|
self.askPassword = {
|
||||||
isSetup: isSetup,
|
isSetup: isSetup,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('sellGlideraController',
|
angular.module('copayApp.controllers').controller('sellGlideraController',
|
||||||
function($scope, $timeout, $log, $modal, configService, profileService, addressService, feeService, glideraService, bwsError, lodash, isChromeApp, animationService) {
|
function($scope, $timeout, $log, $modal, configService, profileService, addressService, feeService, glideraService, bwsError, lodash, isChromeApp, animationService, txSignService) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
|
|
@ -38,7 +38,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
$log.debug(e);
|
$log.debug(e);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -57,7 +57,9 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
||||||
|
|
||||||
$scope.selectWallet = function(walletId, walletName) {
|
$scope.selectWallet = function(walletId, walletName) {
|
||||||
if (!profileService.getClient(walletId).isComplete()) {
|
if (!profileService.getClient(walletId).isComplete()) {
|
||||||
self.error = bwsError.msg({'code': 'WALLET_NOT_COMPLETE'}, 'Could not choose the wallet');
|
self.error = bwsError.msg({
|
||||||
|
'code': 'WALLET_NOT_COMPLETE'
|
||||||
|
}, 'Could not choose the wallet');
|
||||||
$modalInstance.dismiss('cancel');
|
$modalInstance.dismiss('cancel');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -70,8 +72,8 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
||||||
|
|
||||||
var modalInstance = $modal.open({
|
var modalInstance = $modal.open({
|
||||||
templateUrl: 'views/modals/glidera-wallets.html',
|
templateUrl: 'views/modals/glidera-wallets.html',
|
||||||
windowClass: animationService.modalAnimated.slideUp,
|
windowClass: animationService.modalAnimated.slideUp,
|
||||||
controller: ModalInstanceCtrl,
|
controller: ModalInstanceCtrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
modalInstance.result.finally(function() {
|
modalInstance.result.finally(function() {
|
||||||
|
|
@ -101,8 +103,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
||||||
self.gettingSellPrice = false;
|
self.gettingSellPrice = false;
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = 'Could not get exchange information. Please, try again.';
|
self.error = 'Could not get exchange information. Please, try again.';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
self.error = null;
|
self.error = null;
|
||||||
self.sellPrice = sellPrice;
|
self.sellPrice = sellPrice;
|
||||||
}
|
}
|
||||||
|
|
@ -117,8 +118,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
||||||
self.loading = null;
|
self.loading = null;
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = 'Could not send confirmation code to your phone';
|
self.error = 'Could not send confirmation code to your phone';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
self.show2faCodeInput = sent;
|
self.show2faCodeInput = sent;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -129,107 +129,86 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
||||||
var self = this;
|
var self = this;
|
||||||
self.error = null;
|
self.error = null;
|
||||||
|
|
||||||
this.loading = 'Selling Bitcoin...';
|
|
||||||
$timeout(function() {
|
txSignService.prepare(function(err) {
|
||||||
addressService.getAddress(fc.credentials.walletId, null, function(err, refundAddress) {
|
if (err) {
|
||||||
if (!refundAddress) {
|
self.error = err;
|
||||||
self.loading = null;
|
return;
|
||||||
self.error = bwsError.msg(err, 'Could not create address');
|
}
|
||||||
return;
|
this.loading = 'Selling Bitcoin...';
|
||||||
}
|
$timeout(function() {
|
||||||
glideraService.getSellAddress(token, function(error, sellAddress) {
|
addressService.getAddress(fc.credentials.walletId, null, function(err, refundAddress) {
|
||||||
if (!sellAddress) {
|
if (!refundAddress) {
|
||||||
self.loading = null;
|
self.loading = null;
|
||||||
self.error = 'Could not get the destination bitcoin address';
|
self.error = bwsError.msg(err, 'Could not create address');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var amount = parseInt((self.sellPrice.qty * 100000000).toFixed(0));
|
glideraService.getSellAddress(token, function(error, sellAddress) {
|
||||||
|
if (!sellAddress) {
|
||||||
|
self.loading = null;
|
||||||
|
self.error = 'Could not get the destination bitcoin address';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var amount = parseInt((self.sellPrice.qty * 100000000).toFixed(0));
|
||||||
|
|
||||||
feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) {
|
feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) {
|
||||||
if (err) $log.debug(err);
|
if (err) $log.debug(err);
|
||||||
fc.sendTxProposal({
|
fc.sendTxProposal({
|
||||||
toAddress: sellAddress,
|
toAddress: sellAddress,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
message: 'Glidera transaction',
|
message: 'Glidera transaction',
|
||||||
customData: {'glideraToken': token},
|
customData: {
|
||||||
payProUrl: null,
|
'glideraToken': token
|
||||||
feePerKb: feePerKb,
|
},
|
||||||
excludeUnconfirmedUtxos: self.currentSpendUnconfirmed ? false : true
|
payProUrl: null,
|
||||||
}, function(err, txp) {
|
feePerKb: feePerKb,
|
||||||
if (err) {
|
excludeUnconfirmedUtxos: self.currentSpendUnconfirmed ? false : true
|
||||||
profileService.lockFC();
|
}, function(err, txp) {
|
||||||
$log.error(err);
|
|
||||||
$timeout(function() {
|
|
||||||
self.loading = null;
|
|
||||||
self.error = bwsError.msg(err, 'Error');
|
|
||||||
}, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fc.canSign()) {
|
|
||||||
self.loading = null;
|
|
||||||
$log.info('No signing proposal: No private key');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_signTx(txp, function(err, txp, rawTx) {
|
|
||||||
profileService.lockFC();
|
|
||||||
if (err) {
|
if (err) {
|
||||||
self.loading = null;
|
profileService.lockFC();
|
||||||
self.error = err;
|
$log.error(err);
|
||||||
$scope.$apply();
|
$timeout(function() {
|
||||||
}
|
|
||||||
else {
|
|
||||||
var data = {
|
|
||||||
refundAddress: refundAddress,
|
|
||||||
signedTransaction: rawTx,
|
|
||||||
priceUuid: self.sellPrice.priceUuid,
|
|
||||||
useCurrentPrice: self.sellPrice.priceUuid ? false : true,
|
|
||||||
ip: null
|
|
||||||
};
|
|
||||||
glideraService.sell(token, twoFaCode, data, function(err, data) {
|
|
||||||
self.loading = null;
|
self.loading = null;
|
||||||
if (err) {
|
self.error = bwsError.msg(err, 'Error');
|
||||||
self.error = err;
|
}, 1);
|
||||||
fc.removeTxProposal(txp, function(err, txpb) {
|
return;
|
||||||
$timeout(function() {
|
|
||||||
$scope.$emit('Local/GlideraError');
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.success = data;
|
|
||||||
$scope.$emit('Local/GlideraTx');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
txSignService.sign(tx, function(err, txp) {
|
||||||
|
if (err) {
|
||||||
|
self.loading = null;
|
||||||
|
self.error = err;
|
||||||
|
$scope.$apply();
|
||||||
|
} else {
|
||||||
|
var rawTx = txp.raw;
|
||||||
|
var data = {
|
||||||
|
refundAddress: refundAddress,
|
||||||
|
signedTransaction: rawTx,
|
||||||
|
priceUuid: self.sellPrice.priceUuid,
|
||||||
|
useCurrentPrice: self.sellPrice.priceUuid ? false : true,
|
||||||
|
ip: null
|
||||||
|
};
|
||||||
|
glideraService.sell(token, twoFaCode, data, function(err, data) {
|
||||||
|
self.loading = null;
|
||||||
|
if (err) {
|
||||||
|
self.error = err;
|
||||||
|
fc.removeTxProposal(txp, function(err, txpb) {
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$emit('Local/GlideraError');
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
self.success = data;
|
||||||
|
$scope.$emit('Local/GlideraTx');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}, 100);
|
||||||
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
var _signTx = function(txp, cb) {
|
|
||||||
var self = this;
|
|
||||||
fc.signTxProposal(txp, function(err, signedTx) {
|
|
||||||
profileService.lockFC();
|
|
||||||
if (err) {
|
|
||||||
err = bwsError.msg(err, 'Could not accept payment');
|
|
||||||
return cb(err);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (signedTx.status == 'accepted') {
|
|
||||||
return cb(null, txp, signedTx.raw);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return cb('The transaction could not be signed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService) {
|
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService, txSignService) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
window.ignoreMobilePause = false;
|
window.ignoreMobilePause = false;
|
||||||
|
|
@ -87,16 +87,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
$rootScope.hideMenuBar = false;
|
$rootScope.hideMenuBar = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
var requestTouchid = function(cb) {
|
|
||||||
var fc = profileService.focusedClient;
|
|
||||||
config.touchIdFor = config.touchIdFor || {};
|
|
||||||
if (window.touchidAvailable && config.touchIdFor[fc.credentials.walletId]) {
|
|
||||||
$rootScope.$emit('Local/RequestTouchid', cb);
|
|
||||||
} else {
|
|
||||||
return cb();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.onQrCodeScanned = function(data) {
|
this.onQrCodeScanned = function(data) {
|
||||||
if (data) go.send();
|
if (data) go.send();
|
||||||
$rootScope.$emit('dataScanned', data);
|
$rootScope.$emit('dataScanned', data);
|
||||||
|
|
@ -336,72 +326,25 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
$scope.sign = function(txp) {
|
$scope.sign = function(txp) {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
$scope.error = null;
|
$scope.error = null;
|
||||||
|
|
||||||
if (!fc.canSign() && !fc.isPrivKeyExternal())
|
|
||||||
return;
|
|
||||||
|
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
$timeout(function() {
|
|
||||||
|
|
||||||
requestTouchid(function(err) {
|
txSignService.prepareAndSignAndBroadcast(txp, {
|
||||||
if (err) {
|
reporterFn: self.setOngoingProcess.bind(self)
|
||||||
$scope.loading = false;
|
}, function(err, txp) {
|
||||||
$scope.error = err;
|
$scope.loading = false;
|
||||||
$timeout(function() {
|
$scope.$emit('UpdateTx');
|
||||||
$scope.$digest();
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
profileService.unlockFC(function(err) {
|
if (err) {
|
||||||
if (err) {
|
$scope.error = err;
|
||||||
$scope.loading = false;
|
$timeout(function() {
|
||||||
$scope.error = bwsError.msg(err);
|
$scope.$digest();
|
||||||
$timeout(function() {
|
|
||||||
$scope.$digest();
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self._setOngoingForSigning();
|
|
||||||
profileService.signTxProposal(txp, function(err, txpsi) {
|
|
||||||
self.setOngoingProcess();
|
|
||||||
if (err) {
|
|
||||||
$scope.$emit('UpdateTx');
|
|
||||||
$scope.loading = false;
|
|
||||||
$scope.error = bwsError.msg(err, gettextCatalog.getString('Could not accept payment'));
|
|
||||||
$scope.$digest();
|
|
||||||
} else {
|
|
||||||
//if txp has required signatures then broadcast it
|
|
||||||
var txpHasRequiredSignatures = txpsi.status == 'accepted';
|
|
||||||
if (txpHasRequiredSignatures) {
|
|
||||||
self.setOngoingProcess(gettextCatalog.getString('Broadcasting transaction'));
|
|
||||||
$scope.loading = true;
|
|
||||||
fc.broadcastTxProposal(txpsi, function(err, txpsb, memo) {
|
|
||||||
self.setOngoingProcess();
|
|
||||||
$scope.loading = false;
|
|
||||||
if (err) {
|
|
||||||
$scope.$emit('UpdateTx');
|
|
||||||
$scope.error = bwsError.msg(err, gettextCatalog.getString('Could not broadcast payment'));
|
|
||||||
$scope.$digest();
|
|
||||||
} else {
|
|
||||||
$log.debug('Transaction signed and broadcasted')
|
|
||||||
if (memo)
|
|
||||||
$log.info(memo);
|
|
||||||
|
|
||||||
refreshUntilItChanges = true;
|
|
||||||
$modalInstance.close(txpsb);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$scope.loading = false;
|
|
||||||
$modalInstance.close(txpsi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
return;
|
||||||
}, 100);
|
}
|
||||||
|
refreshUntilItChanges = true;
|
||||||
|
$modalInstance.close(txp);
|
||||||
|
return;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.reject = function(txp) {
|
$scope.reject = function(txp) {
|
||||||
|
|
@ -871,57 +814,52 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
address = form.address.$modelValue;
|
address = form.address.$modelValue;
|
||||||
amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0));
|
amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0));
|
||||||
|
|
||||||
requestTouchid(function(err) {
|
txSignService.prepare(function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err;
|
return self.setSendError(err);
|
||||||
$timeout(function() {
|
|
||||||
$scope.$digest();
|
|
||||||
}, 1);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
self.setOngoingProcess(gettextCatalog.getString('Creating transaction'));
|
||||||
|
getFee(function(err, feePerKb) {
|
||||||
|
if (err) $log.debug(err);
|
||||||
|
fc.sendTxProposal({
|
||||||
|
toAddress: address,
|
||||||
|
amount: amount,
|
||||||
|
message: comment,
|
||||||
|
payProUrl: paypro ? paypro.url : null,
|
||||||
|
feePerKb: feePerKb,
|
||||||
|
excludeUnconfirmedUtxos: currentSpendUnconfirmed ? false : true
|
||||||
|
}, function(err, txp) {
|
||||||
|
if (err) {
|
||||||
|
self.setOngoingProcess();
|
||||||
|
return self.setSendError(err);
|
||||||
|
}
|
||||||
|
|
||||||
profileService.unlockFC(function(err) {
|
if (!fc.canSign() && !fc.isPrivKeyExternal()) {
|
||||||
if (err) {
|
self.setOngoingProcess();
|
||||||
return self.setSendError(err);
|
$log.info('No signing proposal: No private key')
|
||||||
}
|
self.resetForm();
|
||||||
|
txStatus.notify(txp, function() {
|
||||||
self.setOngoingProcess(gettextCatalog.getString('Creating transaction'));
|
return $scope.$emit('Local/TxProposalAction');
|
||||||
getFee(function(err, feePerKb) {
|
|
||||||
if (err) $log.debug(err);
|
|
||||||
fc.sendTxProposal({
|
|
||||||
toAddress: address,
|
|
||||||
amount: amount,
|
|
||||||
message: comment,
|
|
||||||
payProUrl: paypro ? paypro.url : null,
|
|
||||||
feePerKb: feePerKb,
|
|
||||||
excludeUnconfirmedUtxos: currentSpendUnconfirmed ? false : true
|
|
||||||
}, function(err, txp) {
|
|
||||||
if (err) {
|
|
||||||
self.setOngoingProcess();
|
|
||||||
return self.setSendError(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fc.canSign() && !fc.isPrivKeyExternal()) {
|
|
||||||
$log.info('No signing proposal: No private key')
|
|
||||||
self.setOngoingProcess();
|
|
||||||
self.resetForm();
|
|
||||||
txStatus.notify(txp, function() {
|
|
||||||
return $scope.$emit('Local/TxProposalAction');
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.signAndBroadcast(txp, function(err) {
|
|
||||||
self.setOngoingProcess();
|
|
||||||
self.resetForm();
|
|
||||||
if (err) {
|
|
||||||
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
|
|
||||||
$scope.$emit('Local/TxProposalAction');
|
|
||||||
$timeout(function() {
|
|
||||||
$scope.$digest();
|
|
||||||
}, 1);
|
|
||||||
} else go.walletHome();
|
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
txSignService.signAndBroadcast(txp, {
|
||||||
|
reporterFn: self.setOngoingProcess.bind(self)
|
||||||
|
}, function(err, txp) {
|
||||||
|
self.resetForm();
|
||||||
|
if (err) {
|
||||||
|
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
|
||||||
|
$scope.$emit('Local/TxProposalAction');
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$digest();
|
||||||
|
}, 1);
|
||||||
|
} else {
|
||||||
|
go.walletHome();
|
||||||
|
txStatus.notify(txp, function() {
|
||||||
|
$scope.$emit('Local/TxProposalAction', true);
|
||||||
|
});
|
||||||
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -929,56 +867,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
this._setOngoingForSigning = function() {
|
|
||||||
var fc = profileService.focusedClient;
|
|
||||||
|
|
||||||
if (fc.isPrivKeyExternal() && fc.getPrivKeyExternalSourceName() == 'ledger') {
|
|
||||||
self.setOngoingProcess(gettextCatalog.getString('Requesting Ledger Wallet to sign'));
|
|
||||||
} else {
|
|
||||||
self.setOngoingProcess(gettextCatalog.getString('Signing payment'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.signAndBroadcast = function(txp, cb) {
|
|
||||||
var fc = profileService.focusedClient;
|
|
||||||
|
|
||||||
this._setOngoingForSigning();
|
|
||||||
profileService.signTxProposal(txp, function(err, signedTx) {
|
|
||||||
self.setOngoingProcess();
|
|
||||||
if (err) {
|
|
||||||
if (!lodash.isObject(err)) {
|
|
||||||
err = { message: err};
|
|
||||||
}
|
|
||||||
err.message = bwsError.msg(err, gettextCatalog.getString('The payment was created but could not be signed. Please try again from home screen'));
|
|
||||||
return cb(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signedTx.status == 'accepted') {
|
|
||||||
self.setOngoingProcess(gettextCatalog.getString('Broadcasting transaction'));
|
|
||||||
fc.broadcastTxProposal(signedTx, function(err, btx, memo) {
|
|
||||||
self.setOngoingProcess();
|
|
||||||
if (err) {
|
|
||||||
err.message = bwsError.msg(err, gettextCatalog.getString('The payment was signed but could not be broadcasted. Please try again from home screen'));
|
|
||||||
return cb(err);
|
|
||||||
}
|
|
||||||
if (memo)
|
|
||||||
$log.info(memo);
|
|
||||||
|
|
||||||
txStatus.notify(btx, function() {
|
|
||||||
$scope.$emit('Local/TxProposalAction', true);
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
self.setOngoingProcess();
|
|
||||||
txStatus.notify(signedTx, function() {
|
|
||||||
$scope.$emit('Local/TxProposalAction');
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
this.setForm = function(to, amount, comment) {
|
this.setForm = function(to, amount, comment) {
|
||||||
var form = $scope.sendForm;
|
var form = $scope.sendForm;
|
||||||
if (to) {
|
if (to) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, isChromeApp, isCordova, gettext, gettextCatalog, nodeWebkit, bwsError, uxLanguage, ledger, bitcore, trezor) {
|
.factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, isChromeApp, isCordova, gettext, gettextCatalog, nodeWebkit, bwsError, uxLanguage, bitcore) {
|
||||||
|
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
|
|
@ -683,59 +683,5 @@ angular.module('copayApp.services')
|
||||||
return lodash.sortBy(ret, 'name');
|
return lodash.sortBy(ret, 'name');
|
||||||
};
|
};
|
||||||
|
|
||||||
root._signWithLedger = function(txp, cb) {
|
|
||||||
var fc = root.focusedClient;
|
|
||||||
$log.info('Requesting Ledger Chrome app to sign the transaction');
|
|
||||||
|
|
||||||
ledger.signTx(txp, fc.credentials.account, function(result) {
|
|
||||||
$log.debug('Ledger response', result);
|
|
||||||
if (!result.success)
|
|
||||||
return cb(result.message || result.error);
|
|
||||||
|
|
||||||
txp.signatures = lodash.map(result.signatures, function(s) {
|
|
||||||
return s.substring(0, s.length - 2);
|
|
||||||
});
|
|
||||||
return fc.signTxProposal(txp, cb);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
root._signWithTrezor = function(txp, cb) {
|
|
||||||
var fc = root.focusedClient;
|
|
||||||
$log.info('Requesting Trezor to sign the transaction');
|
|
||||||
|
|
||||||
var xPubKeys = lodash.pluck(fc.credentials.publicKeyRing, 'xPubKey');
|
|
||||||
trezor.signTx(xPubKeys, txp, fc.credentials.account, function(err, result) {
|
|
||||||
if (err) return cb(err);
|
|
||||||
|
|
||||||
$log.debug('Trezor response', result);
|
|
||||||
txp.signatures = result.signatures;
|
|
||||||
return fc.signTxProposal(txp, cb);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
root.signTxProposal = function(txp, cb) {
|
|
||||||
var fc = root.focusedClient;
|
|
||||||
|
|
||||||
if (fc.isPrivKeyExternal()) {
|
|
||||||
switch (fc.getPrivKeyExternalSourceName()) {
|
|
||||||
case 'ledger':
|
|
||||||
return root._signWithLedger(txp, cb);
|
|
||||||
case 'trezor':
|
|
||||||
return root._signWithTrezor(txp, cb);
|
|
||||||
default:
|
|
||||||
var msg = 'Unsupported External Key:' + fc.getPrivKeyExternalSourceName();
|
|
||||||
$log.error(msg);
|
|
||||||
return cb(msg);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return fc.signTxProposal(txp, function(err, signedTxp) {
|
|
||||||
root.lockFC();
|
|
||||||
return cb(err, signedTxp);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue