From 4821567b1def807b906aa7b8319ed8e65eabd347 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 3 Nov 2014 16:06:17 -0300 Subject: [PATCH] inform the user of "too big" tx --- js/controllers/send.js | 22 +++++++++++++--------- js/models/Wallet.js | 11 +++++------ views/send.html | 6 ++++++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index eb6c7b25b..dd3df7441 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -77,8 +77,7 @@ angular.module('copayApp.controllers').controller('SendController', $scope.submitForm = function(form) { if (form.$invalid) { - var message = 'Unable to send transaction proposal'; - notification.error('Error', message); + $scope.error = 'Unable to send transaction proposal'; return; } @@ -90,8 +89,15 @@ angular.module('copayApp.controllers').controller('SendController', function done(err, ntxid, merchantData) { if (err) { - var message = 'The transaction' + (w.isShared() ? ' proposal' : '') + ' could not be created'; - notification.error('Error', message); + copay.logger.error(err); + + 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.loadTxs(); return; @@ -135,7 +141,7 @@ angular.module('copayApp.controllers').controller('SendController', } notification.success('Transaction broadcasted', message); } else { - notification.error('Error', 'There was an error sending the transaction'); + $scope.error = 'There was an error sending the transaction'; } $scope.loading = false; $scope.loadTxs(); @@ -374,10 +380,8 @@ angular.module('copayApp.controllers').controller('SendController', // Each signature takes 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); -console.log('[send.js.402:amount:]',amount); //TODO return amount > 0 ? amount : 0; }; @@ -391,7 +395,7 @@ console.log('[send.js.402:amount:]',amount); //TODO $rootScope.txAlertCount = 0; w.sendTx(ntxid, function(txid, merchantData) { if (!txid) { - notification.error('Error', 'There was an error sending the transaction'); + $scope.error = 'There was an error sending the transaction'; } else { if (!merchantData) { notification.success('Transaction broadcasted', 'Transaction id: ' + txid); @@ -415,7 +419,7 @@ console.log('[send.js.402:amount:]',amount); //TODO $scope.loading = true; w.sign(ntxid, function(ret) { if (!ret) { - notification.error('Error', 'There was an error signing the transaction'); + $scope.error = 'There was an error signing the transaction'; $scope.loadTxs(); } else { var p = w.txProposals.getTxProposal(ntxid); diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 83ef55582..15c378742 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -30,8 +30,8 @@ var Async = require('./Async'); var Insight = module.exports.Insight = require('./Insight'); var copayConfig = require('../../config'); -var TX_MAX_SIZE_KB = 60; -var TX_MAX_INS = 100; +var TX_MAX_SIZE_KB = 50; +var TX_MAX_INS = 70; /** * @desc * 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); log.debub('TX Created: ntxid', ntxid); //TODO } catch (e) { +console.log('[Wallet.js.2340]', e); //TODO return cb(e); } @@ -2384,7 +2385,6 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos opts[k] = Wallet.builderOpts[k]; } -console.log('[Wallet.js.2386]'); //TODO var b = new Builder(opts) .setUnspent(utxos) .setOutputs([{ @@ -2395,10 +2395,9 @@ console.log('[Wallet.js.2386]'); //TODO log.debug('Creating TX: Builder ready'); var selectedUtxos = b.getSelectedUnspent(); -console.log('[Wallet.js.2397:selectedUtxos:]',selectedUtxos); //TODO - if (selectedUtxos.size > TX_MAX_INS) - throw new Error('BIG: Resulting TX is too big:' + selectedUtxos.size + ' inputs. Aborting'); + if (selectedUtxos.length > TX_MAX_INS) + throw new Error('BIG: Resulting TX is too big:' + selectedUtxos.length + ' inputs. Aborting'); var inputChainPaths = selectedUtxos.map(function(utxo) { diff --git a/views/send.html b/views/send.html index 539e68905..5aac3faf1 100644 --- a/views/send.html +++ b/views/send.html @@ -11,6 +11,12 @@
+

+ + {{error|translate}} +

+