inform the user of "too big" tx

This commit is contained in:
Matias Alejo Garcia 2014-11-03 16:06:17 -03:00
commit 4821567b1d
3 changed files with 24 additions and 15 deletions

View file

@ -77,8 +77,7 @@ angular.module('copayApp.controllers').controller('SendController',
$scope.submitForm = function(form) { $scope.submitForm = function(form) {
if (form.$invalid) { if (form.$invalid) {
var message = 'Unable to send transaction proposal'; $scope.error = 'Unable to send transaction proposal';
notification.error('Error', message);
return; return;
} }
@ -90,8 +89,15 @@ angular.module('copayApp.controllers').controller('SendController',
function done(err, ntxid, merchantData) { function done(err, ntxid, merchantData) {
if (err) { if (err) {
var message = 'The transaction' + (w.isShared() ? ' proposal' : '') + ' could not be created'; copay.logger.error(err);
notification.error('Error', message);
var msg = err.toString();
if (msg.match('BIG'))
msg = 'The transaction have too many inputs. Try creating many transactions for smaller amounts.'
var message = 'The transaction' + (w.isShared() ? ' proposal' : '') + ' could not be created: ' + msg;
$scope.error = message;
$scope.loading = false; $scope.loading = false;
$scope.loadTxs(); $scope.loadTxs();
return; return;
@ -135,7 +141,7 @@ angular.module('copayApp.controllers').controller('SendController',
} }
notification.success('Transaction broadcasted', message); notification.success('Transaction broadcasted', message);
} else { } else {
notification.error('Error', 'There was an error sending the transaction'); $scope.error = 'There was an error sending the transaction';
} }
$scope.loading = false; $scope.loading = false;
$scope.loadTxs(); $scope.loadTxs();
@ -374,10 +380,8 @@ angular.module('copayApp.controllers').controller('SendController',
// Each signature takes // Each signature takes
var estimatedFee = copay.Wallet.estimatedFee($rootScope.safeUnspentCount); var estimatedFee = copay.Wallet.estimatedFee($rootScope.safeUnspentCount);
console.log('[send.js.376:estimatedFee:]',estimatedFee); //TODO
var amount = ((($rootScope.availableBalance * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi); var amount = ((($rootScope.availableBalance * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi);
console.log('[send.js.402:amount:]',amount); //TODO
return amount > 0 ? amount : 0; return amount > 0 ? amount : 0;
}; };
@ -391,7 +395,7 @@ console.log('[send.js.402:amount:]',amount); //TODO
$rootScope.txAlertCount = 0; $rootScope.txAlertCount = 0;
w.sendTx(ntxid, function(txid, merchantData) { w.sendTx(ntxid, function(txid, merchantData) {
if (!txid) { if (!txid) {
notification.error('Error', 'There was an error sending the transaction'); $scope.error = 'There was an error sending the transaction';
} else { } else {
if (!merchantData) { if (!merchantData) {
notification.success('Transaction broadcasted', 'Transaction id: ' + txid); notification.success('Transaction broadcasted', 'Transaction id: ' + txid);
@ -415,7 +419,7 @@ console.log('[send.js.402:amount:]',amount); //TODO
$scope.loading = true; $scope.loading = true;
w.sign(ntxid, function(ret) { w.sign(ntxid, function(ret) {
if (!ret) { if (!ret) {
notification.error('Error', 'There was an error signing the transaction'); $scope.error = 'There was an error signing the transaction';
$scope.loadTxs(); $scope.loadTxs();
} else { } else {
var p = w.txProposals.getTxProposal(ntxid); var p = w.txProposals.getTxProposal(ntxid);

View file

@ -30,8 +30,8 @@ var Async = require('./Async');
var Insight = module.exports.Insight = require('./Insight'); var Insight = module.exports.Insight = require('./Insight');
var copayConfig = require('../../config'); var copayConfig = require('../../config');
var TX_MAX_SIZE_KB = 60; var TX_MAX_SIZE_KB = 50;
var TX_MAX_INS = 100; var TX_MAX_INS = 70;
/** /**
* @desc * @desc
* Wallet manages a private key for Copay, network, storage of the wallet for * Wallet manages a private key for Copay, network, storage of the wallet for
@ -2337,6 +2337,7 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb)
ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts); ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts);
log.debub('TX Created: ntxid', ntxid); //TODO log.debub('TX Created: ntxid', ntxid); //TODO
} catch (e) { } catch (e) {
console.log('[Wallet.js.2340]', e); //TODO
return cb(e); return cb(e);
} }
@ -2384,7 +2385,6 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
opts[k] = Wallet.builderOpts[k]; opts[k] = Wallet.builderOpts[k];
} }
console.log('[Wallet.js.2386]'); //TODO
var b = new Builder(opts) var b = new Builder(opts)
.setUnspent(utxos) .setUnspent(utxos)
.setOutputs([{ .setOutputs([{
@ -2395,10 +2395,9 @@ console.log('[Wallet.js.2386]'); //TODO
log.debug('Creating TX: Builder ready'); log.debug('Creating TX: Builder ready');
var selectedUtxos = b.getSelectedUnspent(); var selectedUtxos = b.getSelectedUnspent();
console.log('[Wallet.js.2397:selectedUtxos:]',selectedUtxos); //TODO
if (selectedUtxos.size > TX_MAX_INS) if (selectedUtxos.length > TX_MAX_INS)
throw new Error('BIG: Resulting TX is too big:' + selectedUtxos.size + ' inputs. Aborting'); throw new Error('BIG: Resulting TX is too big:' + selectedUtxos.length + ' inputs. Aborting');
var inputChainPaths = selectedUtxos.map(function(utxo) { var inputChainPaths = selectedUtxos.map(function(utxo) {

View file

@ -11,6 +11,12 @@
<div class="row collapse m0"> <div class="row collapse m0">
<div class="large-6 columns"> <div class="large-6 columns">
<form name="sendForm" ng-submit="submitForm(sendForm)" novalidate> <form name="sendForm" ng-submit="submitForm(sendForm)" novalidate>
<p class="text-warning size-12"
ng-show="error">
<i class="fi-x"></i>
{{error|translate}}
</p>
<div class="row collapse"> <div class="row collapse">
<div class="large-12 columns"> <div class="large-12 columns">
<div class="row collapse"> <div class="row collapse">