Catch error when creating new TXP
This commit is contained in:
parent
152ab7aa44
commit
cef93325f4
5 changed files with 35 additions and 2 deletions
|
|
@ -117,6 +117,14 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
|
|
||||||
function done(err, ntxid, merchantData) {
|
function done(err, ntxid, merchantData) {
|
||||||
|
if (err) {
|
||||||
|
var message = 'The transaction' + (w.isShared() ? ' proposal' : '') + ' could not be created';
|
||||||
|
notification.error('Error', message);
|
||||||
|
$scope.loading = false;
|
||||||
|
$scope.loadTxs();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If user is granted the privilege of choosing
|
// If user is granted the privilege of choosing
|
||||||
// their own amount, add it to the tx.
|
// their own amount, add it to the tx.
|
||||||
if (merchantData && +merchantData.total === 0) {
|
if (merchantData && +merchantData.total === 0) {
|
||||||
|
|
|
||||||
|
|
@ -2045,7 +2045,7 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getUnspent(function(err, safeUnspent) {
|
this.getUnspent(function(err, safeUnspent) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(new Error('Could not get list of UTXOs'));
|
||||||
|
|
||||||
var ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts);
|
var ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts);
|
||||||
if (!ntxid) {
|
if (!ntxid) {
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ var FakeWallet = function() {
|
||||||
|
|
||||||
FakeWallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb) {
|
FakeWallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb) {
|
||||||
var callback = cb || opts;
|
var callback = cb || opts;
|
||||||
callback({});
|
callback(null, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeWallet.prototype.sendTx = function(ntxid, cb) {
|
FakeWallet.prototype.sendTx = function(ntxid, cb) {
|
||||||
|
|
|
||||||
|
|
@ -792,6 +792,19 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#createTx', function () {
|
||||||
|
it('should fail if insight server is down', function (done) {
|
||||||
|
var w = cachedCreateW2();
|
||||||
|
var utxo = createUTXO(w);
|
||||||
|
w.blockchain.fixUnspent(utxo);
|
||||||
|
sinon.stub(w, 'getUnspent').yields('error', null);
|
||||||
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
|
chai.expect(err.message).to.equal('Could not get list of UTXOs');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('#createTxSync', function() {
|
describe('#createTxSync', function() {
|
||||||
it('should fail if amount below min value', function() {
|
it('should fail if amount below min value', function() {
|
||||||
var w = cachedCreateW2();
|
var w = cachedCreateW2();
|
||||||
|
|
|
||||||
|
|
@ -285,6 +285,18 @@ describe("Unit: Controllers", function() {
|
||||||
sinon.assert.callCount(scope.loadTxs, 1);
|
sinon.assert.callCount(scope.loadTxs, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not send txp when there is an error at creation', function() {
|
||||||
|
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
||||||
|
sendForm.amount.$setViewValue(1000);
|
||||||
|
scope.wallet.totalCopayers = scope.wallet.requiredCopayers = 1;
|
||||||
|
sinon.stub(scope.wallet, 'createTx').yields('error');
|
||||||
|
var spySendTx = sinon.spy(scope.wallet, 'sendTx');
|
||||||
|
scope.loadTxs = sinon.spy();
|
||||||
|
|
||||||
|
scope.submitForm(sendForm);
|
||||||
|
sinon.assert.callCount(spySendTx, 0);
|
||||||
|
sinon.assert.callCount(scope.loadTxs, 1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Unit: Version Controller", function() {
|
describe("Unit: Version Controller", function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue