From 112c1adc11438c8131d142607c6580967f422c91 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 13 Feb 2015 13:05:56 -0300 Subject: [PATCH 1/4] Fixes loading message after press a button --- js/controllers/home.js | 5 ++-- js/controllers/import.js | 47 ++++++++++++++++++--------------- js/controllers/importProfile.js | 13 +++++---- js/controllers/send.js | 4 +-- views/home.html | 4 +-- views/import.html | 2 +- views/importProfile.html | 2 +- 7 files changed, 42 insertions(+), 35 deletions(-) diff --git a/js/controllers/home.js b/js/controllers/home.js index 35fe74d76..5dd6f1b2a 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -127,7 +127,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc return; } - $scope.open(form.email.$modelValue, form.password.$modelValue); + $timeout(function() { + $scope.open(form.email.$modelValue, form.password.$modelValue); + }, 100); }; @@ -165,7 +167,6 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc } else { $scope.error = 'Unknown error'; } - $rootScope.starting = false; $timeout(function() { $rootScope.$digest(); }, 1) diff --git a/js/controllers/import.js b/js/controllers/import.js index 1e177ee09..933d7f16c 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -70,33 +70,36 @@ angular.module('copayApp.controllers').controller('ImportController', $rootScope.starting = true; - $scope.importOpts = {}; + $timeout(function() { - var skipFields = []; + $scope.importOpts = {}; - if ($scope.skipPublicKeyRing) - skipFields.push('publicKeyRing'); + var skipFields = []; - if ($scope.skipTxProposals) - skipFields.push('txProposals'); + if ($scope.skipPublicKeyRing) + skipFields.push('publicKeyRing'); - if (skipFields) - $scope.importOpts.skipFields = skipFields; + if ($scope.skipTxProposals) + skipFields.push('txProposals'); - if (backupFile) { - reader.readAsBinaryString(backupFile); - } else { - updateStatus('Importing wallet - Procesing backup...'); - identityService.importWallet(backupText, $scope.password, $scope.importOpts, function(err) { - if (err) { - $rootScope.starting = false; - $scope.error = 'Could not read wallet. Please check your password'; - $timeout(function() { - $rootScope.$digest(); - }, 1); - } - }); - } + if (skipFields) + $scope.importOpts.skipFields = skipFields; + + if (backupFile) { + reader.readAsBinaryString(backupFile); + } else { + updateStatus('Importing wallet - Procesing backup...'); + identityService.importWallet(backupText, $scope.password, $scope.importOpts, function(err) { + if (err) { + $rootScope.starting = false; + $scope.error = 'Could not read wallet. Please check your password'; + $timeout(function() { + $rootScope.$digest(); + }, 1); + } + }); + } + }, 100); }; diff --git a/js/controllers/importProfile.js b/js/controllers/importProfile.js index 4b978e2e9..ffbef560b 100644 --- a/js/controllers/importProfile.js +++ b/js/controllers/importProfile.js @@ -70,10 +70,13 @@ angular.module('copayApp.controllers').controller('ImportProfileController', $rootScope.starting = true; - if (backupFile) { - reader.readAsBinaryString(backupFile); - } else { - _importBackup(backupText); - } + $timeout(function() { + + if (backupFile) { + reader.readAsBinaryString(backupFile); + } else { + _importBackup(backupText); + } + }, 100); }; }); diff --git a/js/controllers/send.js b/js/controllers/send.js index 67871c33f..c5a8b0793 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -185,7 +185,7 @@ angular.module('copayApp.controllers').controller('SendController', $scope.loading = true; $scope.creatingTX = true; if ($scope.isWindowsPhoneApp) - $rootScope.wpInputFocused = true; + $rootScope.wpInputFocused = true; $timeout(function () { var comment = form.comment.$modelValue; @@ -212,7 +212,7 @@ angular.module('copayApp.controllers').controller('SendController', txStatus.notify(status); $scope.resetForm(); }); - }, 1); + }, 100); }; // QR code Scanner diff --git a/views/home.html b/views/home.html index 86ac11e78..638cede5d 100644 --- a/views/home.html +++ b/views/home.html @@ -121,9 +121,9 @@ -
diff --git a/views/import.html b/views/import.html index a47532a6e..176fc5709 100644 --- a/views/import.html +++ b/views/import.html @@ -86,7 +86,7 @@
diff --git a/views/importProfile.html b/views/importProfile.html index 4008a5572..12f0816fb 100644 --- a/views/importProfile.html +++ b/views/importProfile.html @@ -47,7 +47,7 @@ From 575e99b490e44370aaf2e4ef8bfeac8bb033293f Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 13 Feb 2015 16:34:12 -0300 Subject: [PATCH 2/4] Disable Sendform when sending a transaction --- js/controllers/send.js | 44 ++++++++++++++++++++---------------------- views/send.html | 27 ++++++-------------------- 2 files changed, 27 insertions(+), 44 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index c5a8b0793..100531945 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -183,35 +183,33 @@ angular.module('copayApp.controllers').controller('SendController', } $scope.loading = true; - $scope.creatingTX = true; if ($scope.isWindowsPhoneApp) $rootScope.wpInputFocused = true; $timeout(function () { - var comment = form.comment.$modelValue; - var merchantData = $scope._merchantData; - var address, amount; - if (!merchantData) { - address = form.address.$modelValue; - amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0)); - } + var comment = form.comment.$modelValue; + var merchantData = $scope._merchantData; + var address, amount; + if (!merchantData) { + address = form.address.$modelValue; + amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0)); + } - w.spend({ - merchantData: merchantData, - toAddress: address, - amountSat: amount, - comment: comment, - }, function (err, txid, status) { - $scope.loading = false; - $scope.creatingTX = false; - if ($scope.isWindowsPhoneApp) - $rootScope.wpInputFocused = false; + w.spend({ + merchantData: merchantData, + toAddress: address, + amountSat: amount, + comment: comment, + }, function (err, txid, status) { + $scope.loading = false; + if ($scope.isWindowsPhoneApp) + $rootScope.wpInputFocused = false; - if (err) - return $scope.setError(err); - txStatus.notify(status); - $scope.resetForm(); - }); + if (err) + return $scope.setError(err); + txStatus.notify(status); + $scope.resetForm(); + }); }, 100); }; diff --git a/views/send.html b/views/send.html index fe173d962..f3a6fdd3d 100644 --- a/views/send.html +++ b/views/send.html @@ -1,5 +1,5 @@
-
+
@@ -32,25 +32,9 @@
-
-
-
-
-
- -
- - Creating Transaction... - -
-
-
-
- - -
+
-
+
@@ -159,7 +143,7 @@
@@ -171,7 +155,8 @@
- Cancel + Cancel
From 7ffd48380786b0a029d0a29a321d86a7faaa8157 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 13 Feb 2015 17:39:30 -0300 Subject: [PATCH 3/4] Catch error when transaction could not be sent. Update locked balance if transaction failed --- js/controllers/send.js | 16 +++++++++++----- js/models/Wallet.js | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 100531945..fa5d49d07 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -163,6 +163,9 @@ angular.module('copayApp.controllers').controller('SendController', if (msg.match('expired')) msg = 'The payment request has expired'; + if (msg.match('XMLHttpRequest')) + msg = 'Error when sending to the blockchain. Resend it from Home'; + var message = 'The transaction' + ($scope.requiresMultipleSignatures ? ' proposal' : '') + ' could not be created: ' + msg; @@ -203,12 +206,15 @@ angular.module('copayApp.controllers').controller('SendController', }, function (err, txid, status) { $scope.loading = false; if ($scope.isWindowsPhoneApp) - $rootScope.wpInputFocused = false; + $rootScope.wpInputFocused = false; - if (err) - return $scope.setError(err); - txStatus.notify(status); - $scope.resetForm(); + if (err) { + $scope.setError(err); + } + else { + txStatus.notify(status); + $scope.resetForm(); + } }); }, 100); }; diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 4f272f6d4..5f757a149 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -1651,6 +1651,7 @@ Wallet.prototype.broadcastToBitcoinNetwork = function(ntxid, cb) { log.debug('Wallet:' + self.getName() + ' Send failed:' + err); self._checkIfTxIsSent(ntxid, function(err, txid) { + self.emitAndKeepAlive('balanceUpdated'); return cb(err, txid); }); } else { From 010f1d03c3bf029cae83aebc9a0866faa530fdf8 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 13 Feb 2015 18:05:09 -0300 Subject: [PATCH 4/4] Display loading spinner on mobile devices --- cordova/build.sh | 3 +++ js/controllers/homeWallet.js | 20 +++++++++++++++++++- js/controllers/send.js | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cordova/build.sh b/cordova/build.sh index 95fa23754..cc4b684ed 100755 --- a/cordova/build.sh +++ b/cordova/build.sh @@ -112,6 +112,9 @@ if [ ! -d $PROJECT ]; then cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git && cordova prepare checkOK + cordova plugin add hu.dpal.phonegap.plugins.spinnerdialog + checkOK + fi if $DBGJS diff --git a/js/controllers/homeWallet.js b/js/controllers/homeWallet.js index a4efbe719..5fd1f22bf 100644 --- a/js/controllers/homeWallet.js +++ b/js/controllers/homeWallet.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope, $timeout, $filter, $modal, rateService, notification, txStatus, identityService) { +angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope, $timeout, $filter, $modal, rateService, notification, txStatus, identityService, isCordova) { $scope.openTxModal = function(tx) { var ModalInstanceCtrl = function($scope, $modalInstance) { @@ -9,9 +9,15 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi $scope.loading = null; $scope.sign = function(ntxid) { + if (isCordova) { + window.plugins.spinnerDialog.show(null, 'Signing transaction...', true); + } $scope.loading = true; $timeout(function() { w.signAndSend(ntxid, function(err, id, status) { + if (isCordova) { + window.plugins.spinnerDialog.hide(); + } $scope.loading = false; if (err) $scope.error = err; @@ -22,9 +28,15 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi }; $scope.reject = function(ntxid) { + if (isCordova) { + window.plugins.spinnerDialog.show(null, 'Rejecting transaction...', true); + } $scope.loading = true; $timeout(function() { w.reject(ntxid, function(err, status) { + if (isCordova) { + window.plugins.spinnerDialog.hide(); + } $scope.loading = false; if (err) $scope.error = err; @@ -35,9 +47,15 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi }; $scope.broadcast = function(ntxid) { + if (isCordova) { + window.plugins.spinnerDialog.show(null, 'Sending transaction...', true); + } $scope.loading = true; $timeout(function() { w.issueTx(ntxid, function(err, txid, status) { + if (isCordova) { + window.plugins.spinnerDialog.hide(); + } $scope.loading = false; if (err) $scope.error = err; diff --git a/js/controllers/send.js b/js/controllers/send.js index fa5d49d07..7989d1ac7 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -185,6 +185,10 @@ angular.module('copayApp.controllers').controller('SendController', return; } + if (isCordova) { + window.plugins.spinnerDialog.show(null, 'Creating transaction...', true); + } + $scope.loading = true; if ($scope.isWindowsPhoneApp) $rootScope.wpInputFocused = true; @@ -204,6 +208,9 @@ angular.module('copayApp.controllers').controller('SendController', amountSat: amount, comment: comment, }, function (err, txid, status) { + if (isCordova) { + window.plugins.spinnerDialog.hide(); + } $scope.loading = false; if ($scope.isWindowsPhoneApp) $rootScope.wpInputFocused = false;