+
-
diff --git a/src/js/controllers/backup.js b/src/js/controllers/backup.js
index d06c85aaa..9dc4dd011 100644
--- a/src/js/controllers/backup.js
+++ b/src/js/controllers/backup.js
@@ -1,11 +1,10 @@
'use strict';
angular.module('copayApp.controllers').controller('backupController',
- function($rootScope, $scope, $timeout, $log, lodash, profileService, gettext, bwcService, bwsError, walletService) {
+ function($rootScope, $scope, $timeout, $log, lodash, profileService, gettext, bwcService, bwsError, walletService, ongoingProcess) {
var self = this;
var fc = profileService.focusedClient;
- self.loading = false;
self.customWords = [];
self.walletName = fc.credentials.walletName;
@@ -59,9 +58,9 @@ angular.module('copayApp.controllers').controller('backupController',
finalStep();
function finalStep() {
- self.loading = true;
+ ongoingProcess.set('validatingWords', true);
confirm(function(err) {
- self.loading = false;
+ ongoingProcess.set('validatingWords', false);
if (err) {
backupError(err);
}
@@ -144,7 +143,6 @@ angular.module('copayApp.controllers').controller('backupController',
};
$scope.removeButton = function(index, item) {
- if (self.loading) return;
self.customWords.splice(index, 1);
self.shuffledMnemonicWords[item.prevIndex].selected = false;
self.shouldContinue();
@@ -194,7 +192,7 @@ angular.module('copayApp.controllers').controller('backupController',
};
function backupError(err) {
- self.loading = false;
+ ongoingProcess.set('validatingWords', false);
$log.debug('Failed to verify backup: ', err);
self.backupError = true;
diff --git a/src/js/controllers/buyCoinbase.js b/src/js/controllers/buyCoinbase.js
index bb2a9de8f..48115b4d7 100644
--- a/src/js/controllers/buyCoinbase.js
+++ b/src/js/controllers/buyCoinbase.js
@@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('buyCoinbaseController',
- function($scope, $modal, $log, $ionicModal, $timeout, lodash, profileService, coinbaseService, bwsError, addressService) {
+ function($scope, $modal, $log, $ionicModal, $timeout, lodash, profileService, coinbaseService, bwsError, addressService, ongoingProcess) {
var self = this;
this.init = function(testnet) {
@@ -73,9 +73,9 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController',
currency: currency,
payment_method: $scope.selectedPaymentMethod.id || null
};
- this.loading = 'Sending request...';
+ ongoingProcess.set('Sending request...', true);
coinbaseService.buyRequest(token, accountId, dataSrc, function(err, data) {
- self.loading = null;
+ ongoingProcess.set('Sending request...', false);
if (err) {
self.error = err;
return;
@@ -88,9 +88,9 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController',
self.error = null;
var accountId = account.id;
var buyId = buy.id;
- this.loading = 'Buying bitcoin...';
+ ongoingProcess.set('Buying Bitcoin...', true);
coinbaseService.buyCommit(token, accountId, buyId, function(err, b) {
- self.loading = null;
+ ongoingProcess.set('Buying Bitcoin...', false);
if (err) {
self.error = err;
return;
@@ -98,12 +98,12 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController',
var tx = b.data.transaction;
if (!tx) return;
- self.loading = 'Getting transaction...';
+ ongoingProcess.set('Fetching transaction...', true);
coinbaseService.getTransaction(token, accountId, tx.id, function(err, updatedTx) {
+ ongoingProcess.set('Fetching transaction...', false);
if (err) $log.debug(err);
addressService.getAddress(self.selectedWalletId, false, function(err, addr) {
if (err) {
- self.loading = null;
self.error = {
errors: [{
message: 'Could not create address'
@@ -113,7 +113,6 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController',
}
updatedTx.data['toAddr'] = addr;
coinbaseService.savePendingTransaction(updatedTx.data, {}, function(err) {
- self.loading = null;
if (err) $log.debug(err);
if (updatedTx.data.status == 'completed') {
self.sendToCopay(token, account, updatedTx.data);
@@ -134,7 +133,7 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController',
self.error = null;
var accountId = account.id;
- self.loading = 'Sending funds to Copay...';
+ ongoingProcess.set('Sending funds to Copay...', true);
var data = {
to: tx.toAddr,
amount: tx.amount.amount,
@@ -142,7 +141,7 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController',
description: 'Copay Wallet: ' + self.selectedWalletName
};
coinbaseService.sendTo(token, accountId, data, function(err, res) {
- self.loading = null;
+ ongoingProcess.set('Sending funds to Copay...', false);
if (err) {
self.error = err;
} else {
diff --git a/src/js/controllers/buyGlidera.js b/src/js/controllers/buyGlidera.js
index 207419a04..9a365ee28 100644
--- a/src/js/controllers/buyGlidera.js
+++ b/src/js/controllers/buyGlidera.js
@@ -1,13 +1,12 @@
'use strict';
angular.module('copayApp.controllers').controller('buyGlideraController',
- function($scope, $timeout, $modal, $ionicModal, profileService, addressService, glideraService, bwsError, lodash) {
+ function($scope, $timeout, $modal, $ionicModal, profileService, addressService, glideraService, bwsError, lodash, ongoingProcess) {
var self = this;
this.show2faCodeInput = null;
this.error = null;
this.success = null;
- this.loading = null;
this.init = function(testnet) {
self.allWallets = profileService.getWallets(testnet ? 'testnet' : 'livenet', 1)
@@ -62,10 +61,10 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
this.get2faCode = function(token) {
var self = this;
self.error = null;
- self.loading = 'Sending 2FA code...';
+ ongoingProcess.set('Sending 2FA code...', true);
$timeout(function() {
glideraService.get2faCode(token, function(err, sent) {
- self.loading = null;
+ ongoingProcess.set('Sending 2FA code...', false);
if (err) {
self.error = 'Could not send confirmation code to your phone';
return;
@@ -78,10 +77,11 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
this.sendRequest = function(token, permissions, twoFaCode) {
var self = this;
self.error = null;
- self.loading = 'Buying bitcoin...';
+ ongoingProcess.set('Buying Bitcoin...', true);
$timeout(function() {
addressService.getAddress(self.selectedWalletId, false, function(err, walletAddr) {
if (err) {
+ ongoingProcess.set('Buying Bitcoin...', false);
self.error = bwsError.cb(err, 'Could not create address');
return;
}
@@ -93,7 +93,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
ip: null
};
glideraService.buy(token, twoFaCode, data, function(err, data) {
- self.loading = null;
+ ongoingProcess.set('Buying Bitcoin...', false);
if (err) {
self.error = err;
return;
diff --git a/src/js/controllers/coinbase.js b/src/js/controllers/coinbase.js
index 61553b3e9..9d68404b2 100644
--- a/src/js/controllers/coinbase.js
+++ b/src/js/controllers/coinbase.js
@@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('coinbaseController',
- function($rootScope, $scope, $timeout, $modal, $ionicModal, profileService, configService, storageService, coinbaseService, lodash, platformInfo) {
+ function($rootScope, $scope, $timeout, $modal, $ionicModal, profileService, configService, storageService, coinbaseService, lodash, platformInfo, ongoingProcess) {
var isNW = platformInfo.isNW;
@@ -35,11 +35,11 @@ angular.module('copayApp.controllers').controller('coinbaseController',
var self = this;
var coinbaseTestnet = configService.getSync().coinbase.testnet;
var network = coinbaseTestnet ? 'testnet' : 'livenet';
- this.loading = true;
+ ongoingProcess.set('connectingCoinbase', true);
this.error = null;
$timeout(function() {
coinbaseService.getToken(code, function(err, data) {
- self.loading = null;
+ ongoingProcess.set('connectingCoinbase', false);
if (err) {
self.error = err;
$timeout(function() {
diff --git a/src/js/controllers/coinbaseUri.js b/src/js/controllers/coinbaseUri.js
index 2aff6d1fd..f402bce93 100644
--- a/src/js/controllers/coinbaseUri.js
+++ b/src/js/controllers/coinbaseUri.js
@@ -1,16 +1,16 @@
'use strict';
angular.module('copayApp.controllers').controller('coinbaseUriController',
- function($scope, $stateParams, $timeout, profileService, configService, coinbaseService, storageService, go) {
+ function($scope, $stateParams, $timeout, profileService, configService, coinbaseService, storageService, go, ongoingProcess) {
this.submitOauthCode = function(code) {
var self = this;
var coinbaseTestnet = configService.getSync().coinbase.testnet;
var network = coinbaseTestnet ? 'testnet' : 'livenet';
- this.loading = true;
+ ongoingProcess.set('connectingCoinbase', true);
this.error = null;
$timeout(function() {
coinbaseService.getToken(code, function(err, data) {
- self.loading = null;
+ ongoingProcess.set('connectingCoinbase', false);
if (err) {
self.error = err;
$timeout(function() {
diff --git a/src/js/controllers/create.js b/src/js/controllers/create.js
index c842e5127..8235fb256 100644
--- a/src/js/controllers/create.js
+++ b/src/js/controllers/create.js
@@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('createController',
- function($scope, $ionicScrollDelegate, $rootScope, $timeout, $log, lodash, go, profileService, configService, gettext, ledger, trezor, platformInfo, derivationPathHelper) {
+ function($scope, $ionicScrollDelegate, $rootScope, $timeout, $log, lodash, go, profileService, configService, gettext, ledger, trezor, platformInfo, derivationPathHelper, ongoingProcess) {
var isChromeApp = platformInfo.isChromeApp;
var isCordova = platformInfo.isCordova;
@@ -147,11 +147,12 @@ angular.module('copayApp.controllers').controller('createController',
account = account - 1;
opts.account = account;
- self.hwWallet = self.seedSourceId == 'ledger' ? 'Ledger' : 'Trezor';
+ ongoingProcess.set('connecting' + self.seedSourceId, true);
+
var src = self.seedSourceId == 'ledger' ? ledger : trezor;
src.getInfoForNewWallet(opts.n > 1, account, function(err, lopts) {
- self.hwWallet = false;
+ ongoingProcess.set('connecting' + self.seedSourceId, false);
if (err) {
self.error = err;
$ionicScrollDelegate.scrollTop();
@@ -167,11 +168,11 @@ angular.module('copayApp.controllers').controller('createController',
};
this._create = function(opts) {
- self.loading = true;
+ ongoingProcess.set('creatingWallet', true);
$timeout(function() {
profileService.createWallet(opts, function(err) {
- self.loading = false;
+ ongoingProcess.set('creatingWallet', false);
if (err) {
$log.warn(err);
self.error = err;
diff --git a/src/js/controllers/disclaimer.js b/src/js/controllers/disclaimer.js
index fb8b840d1..d125f8d06 100644
--- a/src/js/controllers/disclaimer.js
+++ b/src/js/controllers/disclaimer.js
@@ -1,10 +1,12 @@
'use strict';
angular.module('copayApp.controllers').controller('disclaimerController',
- function($scope, $timeout, $log, $ionicSideMenuDelegate, profileService, applicationService, gettextCatalog, uxLanguage, go, storageService) {
+ function($scope, $timeout, $log, $ionicSideMenuDelegate, profileService, applicationService, gettextCatalog, uxLanguage, go, storageService, gettext, platformInfo, ongoingProcess) {
var self = this;
self.tries = 0;
- self.creatingProfile = true;
+ var isCordova = platformInfo.isCordova;
+
+ ongoingProcess.set('creatingWallet', true);
var create = function(opts) {
opts = opts || {};
@@ -30,7 +32,7 @@ angular.module('copayApp.controllers').controller('disclaimerController',
};
$scope.error = "";
- self.creatingProfile = false;
+ ongoingProcess.set('creatingWallet', false);
});
};
@@ -43,7 +45,7 @@ angular.module('copayApp.controllers').controller('disclaimerController',
create(opts);
} else {
$log.info('There is already a profile');
- self.creatingProfile = false;
+ ongoingProcess.set('creatingWallet', false);
profileService.bindProfile(profile, function(err) {
if (!err || !err.message || !err.message.match('NONAGREEDDISCLAIMER')) {
$log.debug('Disclaimer already accepted at #disclaimer. Redirect to Wallet Home.');
diff --git a/src/js/controllers/glidera.js b/src/js/controllers/glidera.js
index 8fbffcf2c..ee51ceed9 100644
--- a/src/js/controllers/glidera.js
+++ b/src/js/controllers/glidera.js
@@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('glideraController',
- function($rootScope, $scope, $timeout, $modal, $ionicModal, profileService, configService, storageService, glideraService, lodash) {
+ function($rootScope, $scope, $timeout, $modal, $ionicModal, profileService, configService, storageService, glideraService, lodash, ongoingProcess) {
this.getAuthenticateUrl = function() {
return glideraService.getOauthCodeUrl();
@@ -11,11 +11,11 @@ angular.module('copayApp.controllers').controller('glideraController',
var self = this;
var glideraTestnet = configService.getSync().glidera.testnet;
var network = glideraTestnet ? 'testnet' : 'livenet';
- this.loading = true;
+ ongoingProcess.set('connectingGlidera', true);
this.error = null;
$timeout(function() {
glideraService.getToken(code, function(err, data) {
- self.loading = null;
+ ongoingProcess.set('connectingGlidera', false);
if (err) {
self.error = err;
$timeout(function() {
diff --git a/src/js/controllers/glideraUri.js b/src/js/controllers/glideraUri.js
index d7c27f832..2c1995373 100644
--- a/src/js/controllers/glideraUri.js
+++ b/src/js/controllers/glideraUri.js
@@ -1,17 +1,17 @@
'use strict';
angular.module('copayApp.controllers').controller('glideraUriController',
- function($scope, $log, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) {
+ function($scope, $log, $stateParams, $timeout, profileService, configService, glideraService, storageService, go, ongoingProcess) {
this.submitOauthCode = function(code) {
$log.debug('Glidera Oauth Code:' + code);
var self = this;
var glideraTestnet = configService.getSync().glidera.testnet;
var network = glideraTestnet ? 'testnet' : 'livenet';
- this.loading = true;
+ ongoingProcess.set('connectingGlidera', true);
this.error = null;
$timeout(function() {
glideraService.getToken(code, function(err, data) {
- self.loading = null;
+ ongoingProcess.set('connectingGlidera', false);
if (err) {
self.error = err;
$timeout(function() {
diff --git a/src/js/controllers/import.js b/src/js/controllers/import.js
index d44b487f1..ca72765f2 100644
--- a/src/js/controllers/import.js
+++ b/src/js/controllers/import.js
@@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('importController',
- function($scope, $rootScope, $ionicScrollDelegate, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, lodash, ledger, trezor, derivationPathHelper, platformInfo, bwsError, bwcService) {
+ function($scope, $rootScope, $ionicScrollDelegate, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, lodash, ledger, trezor, derivationPathHelper, platformInfo, bwsError, bwcService, ongoingProcess) {
var isChromeApp = platformInfo.isChromeApp;
var isDevel = platformInfo.isDevel;
@@ -60,13 +60,13 @@ angular.module('copayApp.controllers').controller('importController',
return;
}
- self.loading = true;
+ ongoingProcess.set('importingWallet', true);
opts.compressed = null;
opts.password = null;
$timeout(function() {
profileService.importWallet(str2, opts, function(err, walletId) {
- self.loading = false;
+ ongoingProcess.set('importingWallet', false);
if (err) {
self.error = err;
$ionicScrollDelegate.scrollTop();
@@ -80,11 +80,10 @@ angular.module('copayApp.controllers').controller('importController',
};
var _importExtendedPrivateKey = function(xPrivKey, opts) {
- self.loading = true;
-
+ ongoingProcess.set('importingWallet', true);
$timeout(function() {
profileService.importExtendedPrivateKey(xPrivKey, opts, function(err, walletId) {
- self.loading = false;
+ ongoingProcess.set('importingWallet', false);
if (err) {
if (err instanceof errors.NOT_AUTHORIZED) {
self.importErr = true;
@@ -105,11 +104,11 @@ angular.module('copayApp.controllers').controller('importController',
};
var _importMnemonic = function(words, opts) {
- self.loading = true;
+ ongoingProcess.set('importingWallet', true);
$timeout(function() {
profileService.importMnemonic(words, opts, function(err, walletId) {
- self.loading = false;
+ ongoingProcess.set('importingWallet', false);
if (err) {
if (err instanceof errors.NOT_AUTHORIZED) {
@@ -232,7 +231,7 @@ angular.module('copayApp.controllers').controller('importController',
this.importTrezor = function(account, isMultisig) {
var self = this;
trezor.getInfoForNewWallet(isMultisig, account, function(err, lopts) {
- self.hwWallet = false;
+ ongoingProcess.clear();
if (err) {
self.error = err;
$ionicScrollDelegate.scrollTop();
@@ -242,11 +241,11 @@ angular.module('copayApp.controllers').controller('importController',
lopts.externalSource = 'trezor';
lopts.bwsurl = $scope.bwsurl;
- self.loading = true;
+ ongoingProcess.set('importingWallet', true);
$log.debug('Import opts', lopts);
profileService.importExtendedPublicKey(lopts, function(err, walletId) {
- self.loading = false;
+ ongoingProcess.set('importingWallet', false);
if (err) {
self.error = err;
$ionicScrollDelegate.scrollTop();
@@ -287,11 +286,11 @@ angular.module('copayApp.controllers').controller('importController',
switch (self.seedSourceId) {
case ('ledger'):
- self.hwWallet = 'Ledger';
+ ongoingProcess.set('connectingledger', true);
self.importLedger(account);
break;
case ('trezor'):
- self.hwWallet = 'Trezor';
+ ongoingProcess.set('connectingtrezor', true);
self.importTrezor(account, isMultisig);
break;
default:
@@ -311,7 +310,7 @@ angular.module('copayApp.controllers').controller('importController',
this.importLedger = function(account) {
var self = this;
ledger.getInfoForNewWallet(true, account, function(err, lopts) {
- self.hwWallet = false;
+ ongoingProcess.clear();
if (err) {
self.error = err;
$ionicScrollDelegate.scrollTop();
@@ -321,11 +320,11 @@ angular.module('copayApp.controllers').controller('importController',
lopts.externalSource = 'ledger';
lopts.bwsurl = $scope.bwsurl;
- self.loading = true;
+ ongoingProcess.set('importingWallet', true);
$log.debug('Import opts', lopts);
profileService.importExtendedPublicKey(lopts, function(err, walletId) {
- self.loading = false;
+ ongoingProcess.set('importingWallet', false);
if (err) {
self.error = err;
$ionicScrollDelegate.scrollTop();
diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js
index 4a735ec34..f6e05baaa 100644
--- a/src/js/controllers/index.js
+++ b/src/js/controllers/index.js
@@ -1,6 +1,6 @@
'use strict';
-angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, $ionicScrollDelegate, $ionicPopup, latestReleaseService, feeService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwsError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, openURLService) {
+angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, $ionicScrollDelegate, $ionicPopup, latestReleaseService, feeService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwsError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, openURLService, ongoingProcess) {
var self = this;
var SOFT_CONFIRMATION_LIMIT = 12;
var errors = bwcService.getErrors();
@@ -14,7 +14,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
ret.isChromeApp = isChromeApp;
ret.isSafari = platformInfo.isSafari;
ret.isWindowsPhoneApp = platformInfo.isWP;
- ret.onGoingProcess = {};
ret.historyShowLimit = 10;
ret.historyShowMoreLimit = 10;
ret.isSearching = false;
@@ -81,24 +80,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
storageService.setHideBalanceFlag(self.walletId, self.shouldHideBalance, function() {});
}
- self.setOngoingProcess = function(processName, isOn) {
- $log.debug('onGoingProcess', processName, isOn);
- self[processName] = isOn;
- self.onGoingProcess[processName] = isOn;
-
- var name;
- self.anyOnGoingProcess = lodash.any(self.onGoingProcess, function(isOn, processName) {
- if (isOn)
- name = name || processName;
- return isOn;
- });
- // The first one
- self.onGoingProcessName = name;
- $timeout(function() {
- $rootScope.$apply();
- });
- };
-
self.cleanInstance = function() {
$log.debug('Cleaning Index Instance');
lodash.each(self, function(v, k) {
@@ -125,16 +106,17 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var fc = profileService.focusedClient;
if (!fc) return;
+ ongoingProcess.clear();
self.cleanInstance();
self.loadingWallet = true;
self.setSpendUnconfirmed();
$timeout(function() {
$rootScope.$apply();
+
self.hasProfile = true;
self.isSingleAddress = false;
self.noFocusedWallet = false;
- self.onGoingProcess = {};
// Credentials Shortcuts
self.m = fc.credentials.m;
@@ -303,7 +285,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
} else {
self.isSingleAddress = !!ret.wallet.singleAddress;
if (!opts.quiet)
- self.setOngoingProcess('scanning', ret.wallet.scanStatus == 'running');
+ ongoingProcess.set('scanning', ret.wallet.scanStatus == 'running');
}
return cb(err, ret);
});
@@ -320,7 +302,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$timeout(function() {
if (!opts.quiet)
- self.setOngoingProcess('updatingStatus', true);
+ ongoingProcess.set('updatingStatus', true);
$log.debug('Updating Status:', fc.credentials.walletName, tries);
get(function(err, walletStatus) {
@@ -340,8 +322,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (walletId != profileService.focusedClient.credentials.walletId)
return;
- if (!opts.quiet)
- self.setOngoingProcess('updatingStatus', false);
+ ongoingProcess.set('updatingStatus', false);
if (err) {
@@ -389,10 +370,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.updateBalance = function() {
var fc = profileService.focusedClient;
$timeout(function() {
- self.setOngoingProcess('updatingBalance', true);
+ ongoingProcess.set('updatingBalance', true);
$log.debug('Updating Balance');
fc.getBalance(function(err, balance) {
- self.setOngoingProcess('updatingBalance', false);
+ ongoingProcess.set('updatingBalance', false);
if (err) {
self.handleError(err);
return;
@@ -406,10 +387,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.updatePendingTxps = function() {
var fc = profileService.focusedClient;
$timeout(function() {
- self.setOngoingProcess('updatingPendingTxps', true);
+ ongoingProcess.set('updatingPendingTxps', true);
$log.debug('Updating PendingTxps');
fc.getTxProposals({}, function(err, txps) {
- self.setOngoingProcess('updatingPendingTxps', false);
+ ongoingProcess.set('updatingPendingTxps', false);
if (err) {
self.handleError(err);
} else {
@@ -445,10 +426,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var fc = profileService.focusedClient;
$timeout(function() {
$rootScope.$apply();
- self.setOngoingProcess('openingWallet', true);
+ ongoingProcess.set('openingWallet', true);
self.updateError = false;
fc.openWallet(function(err, walletStatus) {
- self.setOngoingProcess('openingWallet', false);
+ ongoingProcess.set('openingWallet', false);
if (err) {
self.updateError = true;
self.handleError(err);
@@ -997,10 +978,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.recreate = function(cb) {
var fc = profileService.focusedClient;
- self.setOngoingProcess('recreating', true);
+ ongoingProcess.set('recreating', true);
fc.recreateWallet(function(err) {
self.notAuthorized = false;
- self.setOngoingProcess('recreating', false);
+ ongoingProcess.set('recreating', false);
if (err) {
self.handleError(err);
@@ -1034,13 +1015,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (!c.isComplete()) return;
if (self.walletId == walletId)
- self.setOngoingProcess('scanning', true);
+ ongoingProcess.set('scanning', true);
c.startScan({
includeCopayerBranches: true,
}, function(err) {
if (err && self.walletId == walletId) {
- self.setOngoingProcess('scanning', false);
+ ongoingProcess.set('scanning', false);
self.handleError(err);
$rootScope.$apply();
}
@@ -1076,9 +1057,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
getToken(function(err, accessToken) {
if (err || !accessToken) return;
else {
- self.glideraLoading = 'Connecting to Glidera...';
+ ongoingProcess.set('connectingGlidera', true);
glideraService.getAccessTokenPermissions(accessToken, function(err, p) {
- self.glideraLoading = null;
+ ongoingProcess.set('connectingGlidera', false);
if (err) {
self.glideraError = err;
} else {
@@ -1109,24 +1090,24 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
if (permissions.transaction_history) {
- self.glideraLoadingHistory = 'Getting Glidera transactions...';
+ ongoingProcess.set('Fetching Glidera Transactions', true);
glideraService.getTransactions(accessToken, function(err, data) {
- self.glideraLoadingHistory = null;
+ ongoingProcess.set('Fetching Glidera Transactions', false);
self.glideraTxs = data;
});
}
if (permissions.view_email_address && opts.fullUpdate) {
- self.glideraLoadingEmail = 'Getting Glidera Email...';
+ ongoingProcess.set('connectingGlidera', true);
glideraService.getEmail(accessToken, function(err, data) {
- self.glideraLoadingEmail = null;
+ ongoingProcess.set('connectingGlidera', false);
self.glideraEmail = data.email;
});
}
if (permissions.personal_info && opts.fullUpdate) {
- self.glideraLoadingPersonalInfo = 'Getting Glidera Personal Information...';
+ ongoingProcess.set('connectingGlidera', true);
glideraService.getPersonalInfo(accessToken, function(err, data) {
- self.glideraLoadingPersonalInfo = null;
+ ongoingProcess.set('connectingGlidera', false);
self.glideraPersonalInfo = data;
});
}
@@ -1161,9 +1142,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
getToken(function(err, accessToken) {
if (err || !accessToken) return;
else {
- self.coinbaseLoading = 'Getting primary account...';
+ ongoingProcess.set('Getting primary account...', true);
coinbaseService.getAccounts(accessToken, function(err, a) {
- self.coinbaseLoading = null;
+ ongoingProcess.set('Getting primary account...', false);
if (err) {
self.coinbaseError = err;
if (err.errors[0] && err.errors[0].id == 'expired_token') {
@@ -1428,16 +1409,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
$rootScope.$on('Local/ValidatingWallet', function() {
- if (isCordova) {
- window.plugins.spinnerDialog.hide();
- window.plugins.spinnerDialog.show(null, gettext('Validating wallet integrity...'), true);
- }
+ ongoingProcess.set('validatingWallet', true);
});
$rootScope.$on('Local/ProfileBound', function() {
- if (isCordova) {
- window.plugins.spinnerDialog.hide();
- }
+ ongoingProcess.set('validatingWallet', false);
});
$rootScope.$on('Local/ClearHistory', function(event) {
@@ -1519,93 +1495,49 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}
};
-$rootScope.$on('Local/Resume', function(event) {
- $log.debug('### Resume event');
- profileService.isDisclaimerAccepted(function(v) {
- if (!v) {
- $log.debug('Disclaimer not accepted, resume to home');
- go.path('disclaimer');
- }
+ $rootScope.$on('Local/Resume', function(event) {
+ $log.debug('### Resume event');
+ profileService.isDisclaimerAccepted(function(v) {
+ if (!v) {
+ $log.debug('Disclaimer not accepted, resume to home');
+ go.path('disclaimer');
+ }
+ });
+ self.debouncedUpdate();
});
- self.debouncedUpdate();
-});
-$rootScope.$on('Local/BackupDone', function(event, walletId) {
- self.needsBackup = false;
- $log.debug('Backup done');
- storageService.setBackupFlag(walletId || self.walletId, function(err) {
- $log.debug('Backup stored');
- });
-});
-
-$rootScope.$on('Local/DeviceError', function(event, err) {
- self.showErrorPopup(err, function() {
- if (isCordova && navigator && navigator.app) {
- navigator.app.exitApp();
- }
- });
-});
-
-$rootScope.$on('Local/WalletImported', function(event, walletId) {
- self.needsBackup = false;
- storageService.setBackupFlag(walletId, function() {
- $log.debug('Backup done stored');
- addressService.expireAddress(walletId, function(err) {
- $timeout(function() {
- self.txHistory = self.completeHistory = self.txHistorySearchResults = [];
- storageService.removeTxHistory(walletId, function() {
- self.startScan(walletId);
- });
- }, 500);
+ $rootScope.$on('Local/BackupDone', function(event, walletId) {
+ self.needsBackup = false;
+ $log.debug('Backup done');
+ storageService.setBackupFlag(walletId || self.walletId, function(err) {
+ $log.debug('Backup stored');
});
});
-});
-$rootScope.$on('NewIncomingTx', function() {
- self.newTx = true;
- self.updateAll({
- walletStatus: null,
- untilItChanges: true,
- triggerTxUpdate: true,
+ $rootScope.$on('Local/DeviceError', function(event, err) {
+ self.showErrorPopup(err, function() {
+ if (isCordova && navigator && navigator.app) {
+ navigator.app.exitApp();
+ }
+ });
});
-});
-
-$rootScope.$on('NewBlock', function() {
- if (self.glideraEnabled) {
- $timeout(function() {
- self.updateGlidera();
+ $rootScope.$on('Local/WalletImported', function(event, walletId) {
+ self.needsBackup = false;
+ storageService.setBackupFlag(walletId, function() {
+ $log.debug('Backup done stored');
+ addressService.expireAddress(walletId, function(err) {
+ $timeout(function() {
+ self.txHistory = self.completeHistory = self.txHistorySearchResults = [];
+ storageService.removeTxHistory(walletId, function() {
+ self.startScan(walletId);
+ });
+ }, 500);
+ });
});
- }
- if (self.coinbaseEnabled) {
- $timeout(function() {
- self.updateCoinbase();
- });
- }
- if (self.pendingAmount) {
- self.updateAll({
- walletStatus: null,
- untilItChanges: null,
- triggerTxUpdate: true,
- });
- } else if (self.hasUnsafeConfirmed) {
- $log.debug('Wallet has transactions with few confirmations. Updating.')
- if (self.network == 'testnet') {
- self.throttledUpdateHistory();
- } else {
- self.debounceUpdateHistory();
- }
- }
-});
+ });
-$rootScope.$on('BalanceUpdated', function(e, n) {
- self.setBalance(n.data);
-});
-
-
-//untilItChange TRUE
-lodash.each(['NewOutgoingTx', 'NewOutgoingTxByThirdParty'], function(eventName) {
- $rootScope.$on(eventName, function(event) {
+ $rootScope.$on('NewIncomingTx', function() {
self.newTx = true;
self.updateAll({
walletStatus: null,
@@ -1613,200 +1545,245 @@ lodash.each(['NewOutgoingTx', 'NewOutgoingTxByThirdParty'], function(eventName)
triggerTxUpdate: true,
});
});
-});
-//untilItChange FALSE
-lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'NewOutgoingTxByThirdParty',
- 'Local/GlideraTx'
-], function(eventName) {
- $rootScope.$on(eventName, function(event) {
+
+ $rootScope.$on('NewBlock', function() {
+ if (self.glideraEnabled) {
+ $timeout(function() {
+ self.updateGlidera();
+ });
+ }
+ if (self.coinbaseEnabled) {
+ $timeout(function() {
+ self.updateCoinbase();
+ });
+ }
+ if (self.pendingAmount) {
+ self.updateAll({
+ walletStatus: null,
+ untilItChanges: null,
+ triggerTxUpdate: true,
+ });
+ } else if (self.hasUnsafeConfirmed) {
+ $log.debug('Wallet has transactions with few confirmations. Updating.')
+ if (self.network == 'testnet') {
+ self.throttledUpdateHistory();
+ } else {
+ self.debounceUpdateHistory();
+ }
+ }
+ });
+
+ $rootScope.$on('BalanceUpdated', function(e, n) {
+ self.setBalance(n.data);
+ });
+
+
+ //untilItChange TRUE
+ lodash.each(['NewOutgoingTx', 'NewOutgoingTxByThirdParty'], function(eventName) {
+ $rootScope.$on(eventName, function(event) {
+ self.newTx = true;
+ self.updateAll({
+ walletStatus: null,
+ untilItChanges: true,
+ triggerTxUpdate: true,
+ });
+ });
+ });
+
+ //untilItChange FALSE
+ lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'NewOutgoingTxByThirdParty',
+ 'Local/GlideraTx'
+ ], function(eventName) {
+ $rootScope.$on(eventName, function(event) {
+ self.updateAll({
+ walletStatus: null,
+ untilItChanges: null,
+ triggerTxUpdate: true,
+ });
+ });
+ });
+
+
+ //untilItChange Maybe
+ $rootScope.$on('Local/TxProposalAction', function(event, untilItChanges) {
+ self.newTx = untilItChanges;
self.updateAll({
walletStatus: null,
- untilItChanges: null,
+ untilItChanges: untilItChanges,
triggerTxUpdate: true,
});
});
-});
-
-//untilItChange Maybe
-$rootScope.$on('Local/TxProposalAction', function(event, untilItChanges) {
- self.newTx = untilItChanges;
- self.updateAll({
- walletStatus: null,
- untilItChanges: untilItChanges,
- triggerTxUpdate: true,
- });
-});
-
-$rootScope.$on('ScanFinished', function() {
- $log.debug('Scan Finished. Updating history');
- storageService.removeTxHistory(self.walletId, function() {
- self.updateAll({
- walletStatus: null,
- triggerTxUpdate: true,
+ $rootScope.$on('ScanFinished', function() {
+ $log.debug('Scan Finished. Updating history');
+ storageService.removeTxHistory(self.walletId, function() {
+ self.updateAll({
+ walletStatus: null,
+ triggerTxUpdate: true,
+ });
});
});
-});
-lodash.each(['TxProposalRejectedBy', 'TxProposalAcceptedBy'], function(eventName) {
- $rootScope.$on(eventName, function() {
- var f = function() {
- if (self.updatingStatus) {
- return $timeout(f, 200);
+ lodash.each(['TxProposalRejectedBy', 'TxProposalAcceptedBy'], function(eventName) {
+ $rootScope.$on(eventName, function() {
+ var f = function() {
+ if (self.updatingStatus) {
+ return $timeout(f, 200);
+ };
+ self.updatePendingTxps();
};
- self.updatePendingTxps();
- };
- f();
+ f();
+ });
});
-});
-$rootScope.$on('Local/NoWallets', function(event) {
- $timeout(function() {
- self.hasProfile = true;
- self.noFocusedWallet = true;
- self.isComplete = null;
- self.walletName = null;
+ $rootScope.$on('Local/NoWallets', function(event) {
+ $timeout(function() {
+ self.hasProfile = true;
+ self.noFocusedWallet = true;
+ self.isComplete = null;
+ self.walletName = null;
+ uxLanguage.update();
+
+ profileService.isDisclaimerAccepted(function(v) {
+ if (v) {
+ go.path('import');
+ }
+ });
+ });
+ });
+
+ $rootScope.$on('Local/NewFocusedWallet', function() {
uxLanguage.update();
+ self.setFocusedWallet();
+ self.updateHistory();
+ storageService.getCleanAndScanAddresses(function(err, walletId) {
- profileService.isDisclaimerAccepted(function(v) {
- if (v) {
- go.path('import');
+ if (walletId && profileService.walletClients[walletId]) {
+ $log.debug('Clear last address cache and Scan ', walletId);
+ addressService.expireAddress(walletId, function(err) {
+ self.startScan(walletId);
+ });
+ storageService.removeCleanAndScanAddresses(function() {
+ $rootScope.$emit('Local/NewFocusedWalletReady');
+ });
+ } else {
+ $rootScope.$emit('Local/NewFocusedWalletReady');
}
});
});
-});
-$rootScope.$on('Local/NewFocusedWallet', function() {
- uxLanguage.update();
- self.setFocusedWallet();
- self.updateHistory();
- storageService.getCleanAndScanAddresses(function(err, walletId) {
+ $rootScope.$on('Local/SetTab', function(event, tab, reset) {
+ self.setTab(tab, reset);
+ });
- if (walletId && profileService.walletClients[walletId]) {
- $log.debug('Clear last address cache and Scan ', walletId);
- addressService.expireAddress(walletId, function(err) {
- self.startScan(walletId);
+ $rootScope.$on('Local/NeedsConfirmation', function(event, txp, cb) {
+
+ function openConfirmationPopup(txp, cb) {
+
+ $scope.tx = txFormatService.processTx(txp);
+
+ self.confirmationPopup = $ionicPopup.show({
+ templateUrl: 'views/includes/confirm-tx.html',
+ scope: $scope,
});
- storageService.removeCleanAndScanAddresses(function() {
- $rootScope.$emit('Local/NewFocusedWalletReady');
- });
- } else {
- $rootScope.$emit('Local/NewFocusedWalletReady');
+
+ $scope.processFee = function(amount, fee) {
+ var walletSettings = configService.getSync().wallet.settings;
+ var feeAlternativeIsoCode = walletSettings.alternativeIsoCode;
+
+ $scope.feeLevel = feeService.feeOpts[feeService.getCurrentFeeLevel()];
+ $scope.feeAlternativeStr = parseFloat((rateService.toFiat(fee, feeAlternativeIsoCode)).toFixed(2), 10) + ' ' + feeAlternativeIsoCode;
+ $scope.feeRateStr = (fee / (amount + fee) * 100).toFixed(2) + '%';
+ };
+
+ $scope.cancel = function() {
+ return cb();
+ };
+
+ $scope.accept = function() {
+ return cb(true);
+ };
}
+
+ openConfirmationPopup(txp, function(accept) {
+ self.confirmationPopup.close();
+ return cb(accept);
+ });
});
-});
-$rootScope.$on('Local/SetTab', function(event, tab, reset) {
- self.setTab(tab, reset);
-});
+ $rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {
-$rootScope.$on('Local/NeedsConfirmation', function(event, txp, cb) {
+ function openPasswordPopup(isSetup, cb) {
+ $scope.data = {};
+ $scope.data.password = null;
+ $scope.isSetup = isSetup;
+ $scope.isVerification = false;
+ $scope.loading = false;
+ var pass = null;
- function openConfirmationPopup(txp, cb) {
+ self.passwordPopup = $ionicPopup.show({
+ templateUrl: 'views/includes/password.html',
+ scope: $scope,
+ });
- $scope.tx = txFormatService.processTx(txp);
+ $scope.cancel = function() {
+ return cb('No spending password given');
+ };
- self.confirmationPopup = $ionicPopup.show({
- templateUrl: 'views/includes/confirm-tx.html',
- scope: $scope,
+ $scope.set = function() {
+ $scope.loading = true;
+ $scope.error = null;
+
+ $timeout(function() {
+ if (isSetup && !$scope.isVerification) {
+ $scope.loading = false;
+ $scope.isVerification = true;
+ pass = $scope.data.password;
+ $scope.data.password = null;
+ return;
+ }
+ if (isSetup && pass != $scope.data.password) {
+ $scope.loading = false;
+ $scope.error = gettext('Spending Passwords do not match');
+ $scope.isVerification = false;
+ $scope.data.password = null;
+ pass = null;
+ return;
+ }
+ return cb(null, $scope.data.password);
+ }, 100);
+ };
+ };
+
+ openPasswordPopup(isSetup, function(err, pass) {
+ self.passwordPopup.close();
+ return cb(err, pass);
});
- $scope.processFee = function(amount, fee) {
- var walletSettings = configService.getSync().wallet.settings;
- var feeAlternativeIsoCode = walletSettings.alternativeIsoCode;
-
- $scope.feeLevel = feeService.feeOpts[feeService.getCurrentFeeLevel()];
- $scope.feeAlternativeStr = parseFloat((rateService.toFiat(fee, feeAlternativeIsoCode)).toFixed(2), 10) + ' ' + feeAlternativeIsoCode;
- $scope.feeRateStr = (fee / (amount + fee) * 100).toFixed(2) + '%';
- };
-
- $scope.cancel = function() {
- return cb();
- };
-
- $scope.accept = function() {
- return cb(true);
- };
- }
-
- openConfirmationPopup(txp, function(accept) {
- self.confirmationPopup.close();
- return cb(accept);
});
-});
-$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {
+ $rootScope.$on('Local/EmailUpdated', function(event, email) {
+ self.preferences.email = email;
+ });
- function openPasswordPopup(isSetup, cb) {
- $scope.data = {};
- $scope.data.password = null;
- $scope.isSetup = isSetup;
- $scope.isVerification = false;
- $scope.loading = false;
- var pass = null;
-
- self.passwordPopup = $ionicPopup.show({
- templateUrl: 'views/includes/password.html',
- scope: $scope,
+ lodash.each(['NewCopayer', 'CopayerUpdated'], function(eventName) {
+ $rootScope.$on(eventName, function() {
+ // Re try to open wallet (will triggers)
+ self.setFocusedWallet();
});
-
- $scope.cancel = function() {
- return cb('No spending password given');
- };
-
- $scope.set = function() {
- $scope.loading = true;
- $scope.error = null;
-
- $timeout(function() {
- if (isSetup && !$scope.isVerification) {
- $scope.loading = false;
- $scope.isVerification = true;
- pass = $scope.data.password;
- $scope.data.password = null;
- return;
- }
- if (isSetup && pass != $scope.data.password) {
- $scope.loading = false;
- $scope.error = gettext('Spending Passwords do not match');
- $scope.isVerification = false;
- $scope.data.password = null;
- pass = null;
- return;
- }
- return cb(null, $scope.data.password);
- }, 100);
- };
- };
-
- openPasswordPopup(isSetup, function(err, pass) {
- self.passwordPopup.close();
- return cb(err, pass);
});
-});
-
-$rootScope.$on('Local/EmailUpdated', function(event, email) {
- self.preferences.email = email;
-});
-
-lodash.each(['NewCopayer', 'CopayerUpdated'], function(eventName) {
- $rootScope.$on(eventName, function() {
- // Re try to open wallet (will triggers)
- self.setFocusedWallet();
+ $rootScope.$on('Local/NewEncryptionSetting', function() {
+ var fc = profileService.focusedClient;
+ self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted();
+ $timeout(function() {
+ $rootScope.$apply();
+ });
});
-});
-
-$rootScope.$on('Local/NewEncryptionSetting', function() {
- var fc = profileService.focusedClient;
- self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted();
- $timeout(function() {
- $rootScope.$apply();
- });
-});
-/* Start setup */
-lodash.assign(self, vanillaScope); openURLService.init();
+ /* Start setup */
+ lodash.assign(self, vanillaScope);
+ openURLService.init();
});
diff --git a/src/js/controllers/join.js b/src/js/controllers/join.js
index f65e80d0a..9e7c56f0a 100644
--- a/src/js/controllers/join.js
+++ b/src/js/controllers/join.js
@@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('joinController',
- function($scope, $rootScope, $timeout, $ionicScrollDelegate, go, notification, profileService, configService, storageService, applicationService, $modal, gettext, lodash, ledger, trezor, platformInfo, derivationPathHelper) {
+ function($scope, $rootScope, $timeout, $ionicScrollDelegate, go, notification, profileService, configService, storageService, applicationService, $modal, gettext, lodash, ledger, trezor, platformInfo, derivationPathHelper, ongoingProcess) {
var isChromeApp = platformInfo.isChromeApp;
var isDevel = platformInfo.isDevel;
@@ -108,11 +108,11 @@ angular.module('copayApp.controllers').controller('joinController',
account = account - 1;
opts.account = account;
- self.hwWallet = self.seedSourceId == 'ledger' ? 'Ledger' : 'Trezor';
+ ongoingProcess.set('connecting' + self.seedSourceId, true);
var src = self.seedSourceId == 'ledger' ? ledger : trezor;
src.getInfoForNewWallet(true, account, function(err, lopts) {
- self.hwWallet = false;
+ ongoingProcess.set('connecting' + self.seedSourceId, false);
if (err) {
self.error = err;
$ionicScrollDelegate.scrollTop();
@@ -129,11 +129,11 @@ angular.module('copayApp.controllers').controller('joinController',
};
this._join = function(opts) {
- self.loading = true;
+ ongoingProcess.set('joiningWallet', true);
$timeout(function() {
profileService.joinWallet(opts, function(err) {
if (err) {
- self.loading = false;
+ ongoingProcess.set('joiningWallet', false);
self.error = err;
$ionicScrollDelegate.scrollTop();
$rootScope.$apply();
diff --git a/src/js/controllers/paperWallet.js b/src/js/controllers/paperWallet.js
index 1ccaffdeb..e0f7c143f 100644
--- a/src/js/controllers/paperWallet.js
+++ b/src/js/controllers/paperWallet.js
@@ -1,5 +1,5 @@
angular.module('copayApp.controllers').controller('paperWalletController',
- function($scope, $http, $timeout, $log, configService, profileService, go, addressService, txStatus, bitcore) {
+ function($scope, $http, $timeout, $log, configService, profileService, go, addressService, txStatus, bitcore, ongoingProcess) {
var self = this;
var fc = profileService.focusedClient;
var rawTx;
@@ -46,14 +46,14 @@ angular.module('copayApp.controllers').controller('paperWalletController',
}
self.scanFunds = function() {
- self.scanning = true;
self.privateKey = '';
self.balanceSat = 0;
self.error = '';
+ ongoingProcess.set('scanning', true);
$timeout(function() {
self._scanFunds(function(err, privateKey, balance) {
- self.scanning = false;
+ ongoingProcess.set('scanning', false);
if (err) {
$log.error(err);
self.error = err.message || err.toString();
@@ -88,12 +88,13 @@ angular.module('copayApp.controllers').controller('paperWalletController',
};
self.sweepWallet = function() {
+ ongoingProcess.set('sweepingWallet', true);
self.sending = true;
self.error = '';
$timeout(function() {
self._sweepWallet(function(err, destinationAddress, txid) {
- self.sending = false;
+ ongoingProcess.set('sweepingWallet', false);
if (err) {
self.error = err.message || err.toString();
diff --git a/src/js/controllers/preferencesDelete.js b/src/js/controllers/preferencesDelete.js
index e6f823580..9f6ab6fa0 100644
--- a/src/js/controllers/preferencesDelete.js
+++ b/src/js/controllers/preferencesDelete.js
@@ -1,11 +1,10 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesDeleteWalletController',
- function($scope, $rootScope, $filter, $timeout, $modal, $log, $ionicModal, storageService, notification, profileService, platformInfo, go, gettext, gettextCatalog, applicationService) {
+ function($scope, $rootScope, $filter, $timeout, $modal, $log, $ionicModal, storageService, notification, profileService, platformInfo, go, gettext, gettextCatalog, applicationService, ongoingProcess) {
var isCordova = platformInfo.isCordova;
this.isCordova = isCordova;
this.error = null;
- $scope.isDeletingWallet = false;
var delete_msg = gettextCatalog.getString('Are you sure you want to delete this wallet?');
var accept_msg = gettextCatalog.getString('Accept');
@@ -30,14 +29,14 @@ angular.module('copayApp.controllers').controller('preferencesDeleteWalletContro
};
var doDeleteWallet = function() {
- $scope.isDeletingWallet = true;
+ ongoingProcess.set('deletingWallet', true);
var fc = profileService.focusedClient;
var name = fc.credentials.walletName;
var walletName = (fc.alias || '') + ' [' + name + ']';
var self = this;
profileService.deleteWalletClient(fc, function(err) {
- $scope.isDeletingWallet = false;
+ ongoingProcess.set('deletingWallet', false);
if (err) {
self.error = err.message || err;
} else {
@@ -50,7 +49,6 @@ angular.module('copayApp.controllers').controller('preferencesDeleteWalletContro
};
this.deleteWallet = function() {
- if ($scope.isDeletingWallet) return;
if (isCordova) {
navigator.notification.confirm(
delete_msg,
diff --git a/src/js/controllers/preferencesEmail.js b/src/js/controllers/preferencesEmail.js
index 036cb7a74..b41981e13 100644
--- a/src/js/controllers/preferencesEmail.js
+++ b/src/js/controllers/preferencesEmail.js
@@ -7,17 +7,14 @@ angular.module('copayApp.controllers').controller('preferencesEmailController',
this.error = null;
var fc = profileService.focusedClient;
- this.saving = true;
var email = self.email || '';
walletService.updateRemotePreferences(fc, {
email: email,
}, function(err) {
-
if (!err)
$rootScope.$emit('Local/EmailUpdated', email);
- self.saving = false;
go.path('preferences');
});
};
diff --git a/src/js/controllers/sellCoinbase.js b/src/js/controllers/sellCoinbase.js
index d66a7f359..a9023c620 100644
--- a/src/js/controllers/sellCoinbase.js
+++ b/src/js/controllers/sellCoinbase.js
@@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('sellCoinbaseController',
- function($rootScope, $scope, $modal, $log, $timeout, $ionicModal, lodash, profileService, coinbaseService, bwsError, configService, walletService, fingerprintService) {
+ function($rootScope, $scope, $modal, $log, $timeout, $ionicModal, lodash, profileService, coinbaseService, bwsError, configService, walletService, fingerprintService, ongoingProcess) {
var self = this;
var client;
@@ -112,9 +112,9 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
var accountId = account.id;
var data = ctx.amount;
data['payment_method'] = $scope.selectedPaymentMethod.id || null;
- this.loading = 'Sending request...';
+ ongoingProcess.set('Sending request...', true);
coinbaseService.sellRequest(token, accountId, data, function(err, sell) {
- self.loading = null;
+ ongoingProcess.set('Sending request...', false);
if (err) {
self.error = err;
return;
@@ -127,9 +127,9 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
self.error = null;
var accountId = account.id;
var sellId = sell.id;
- this.loading = 'Selling bitcoin...';
+ ongoingProcess.set('Selling Bitcoin...', true);
coinbaseService.sellCommit(token, accountId, sellId, function(err, data) {
- self.loading = null;
+ ongoingProcess.set('Selling Bitcoin...', false);
if (err) {
self.error = err;
return;
@@ -157,12 +157,12 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
var walletSettings = configWallet.settings;
- self.loading = 'Creating transaction...';
+ ongoingProcess.set('Creating Transaction...', true);
$timeout(function() {
coinbaseService.createAddress(token, accountId, dataSrc, function(err, data) {
if (err) {
- self.loading = null;
+ ongoingProcess.set('Creating Transaction...', false);
self.error = err;
return;
}
@@ -192,7 +192,7 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
walletService.createTx(client, txp, function(err, createdTxp) {
if (err) {
$log.debug(err);
- self.loading = null;
+ ongoingProcess.set('Creating Transaction...', false);
self.error = {
errors: [{
message: 'Could not create transaction: ' + err.message
@@ -201,8 +201,8 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
$scope.$apply();
return;
}
+ ongoingProcess.set('Creating Transaction...', false);
$scope.$emit('Local/NeedsConfirmation', createdTxp, function(accept) {
- self.loading = null;
if (accept) {
self.confirmTx(createdTxp, function(err, tx) {
if (err) {
@@ -213,7 +213,7 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
};
return;
}
- self.loading = 'Checking transaction...';
+ ongoingProcess.set('Checking Transaction...', false);
coinbaseService.getTransactions(token, accountId, function(err, ctxs) {
if (err) {
$log.debug(err);
@@ -225,7 +225,7 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
self.sellRequest(token, account, ctx);
} else {
// Save to localstorage
- self.loading = null;
+ ongoingProcess.clear();
ctx['price_sensitivity'] = $scope.selectedPriceSensitivity;
ctx['sell_price_amount'] = self.sellPrice.amount;
ctx['sell_price_currency'] = self.sellPrice.currency;
@@ -264,10 +264,10 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
return cb(err);
}
- self.loading = 'Sending bitcoin to Coinbase...';
+ ongoingProcess.set('Sending Bitcoin to Coinbase...', true);
walletService.publishTx(client, txp, function(err, publishedTxp) {
if (err) {
- self.loading = null;
+ ongoingProcess.set('Sending Bitcoin to Coinbase...', false);
$log.debug(err);
return cb({
errors: [{
@@ -279,7 +279,7 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
walletService.signTx(client, publishedTxp, function(err, signedTxp) {
walletService.lock(client);
if (err) {
- self.loading = null;
+ ongoingProcess.set('Sending Bitcoin to Coinbase...', false);
$log.debug(err);
walletService.removeTx(client, signedTxp, function(err) {
if (err) $log.debug(err);
@@ -292,8 +292,8 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
}
walletService.broadcastTx(client, signedTxp, function(err, broadcastedTxp) {
+ ongoingProcess.set('Sending Bitcoin to Coinbase...', false);
if (err) {
- self.loading = null;
$log.debug(err);
walletService.removeTx(client, broadcastedTxp, function(err) {
if (err) $log.debug(err);
@@ -305,7 +305,6 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController',
});
}
$timeout(function() {
- self.loading = null;
return cb(null, broadcastedTxp);
}, 5000);
});
diff --git a/src/js/controllers/sellGlidera.js b/src/js/controllers/sellGlidera.js
index 31afbdb91..8e203a18f 100644
--- a/src/js/controllers/sellGlidera.js
+++ b/src/js/controllers/sellGlidera.js
@@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('sellGlideraController',
- function($rootScope, $scope, $timeout, $ionicModal, $log, $modal, configService, profileService, addressService, feeService, glideraService, bwsError, lodash, walletService, fingerprintService) {
+ function($rootScope, $scope, $timeout, $ionicModal, $log, $modal, configService, profileService, addressService, feeService, glideraService, bwsError, lodash, walletService, fingerprintService, ongoingProcess) {
var self = this;
var config = configService.getSync();
@@ -9,7 +9,6 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
this.show2faCodeInput = null;
this.success = null;
this.error = null;
- this.loading = null;
var client;
var handleEncryptedWallet = function(client, cb) {
@@ -74,10 +73,10 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
this.get2faCode = function(token) {
var self = this;
- self.loading = 'Sending 2FA code...';
+ ongoingProcess.set('Sending 2FA code...', true);
$timeout(function() {
glideraService.get2faCode(token, function(err, sent) {
- self.loading = null;
+ ongoingProcess.set('Sending 2FA code...', false);
if (err) {
self.error = 'Could not send confirmation code to your phone';
} else {
@@ -99,15 +98,17 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
return;
}
+ ongoingProcess.set('creatingTx', true);
addressService.getAddress(client.credentials.walletId, null, function(err, refundAddress) {
if (!refundAddress) {
- self.loading = null;
+
+ ongoingProcess.clear();
self.error = bwsError.msg(err, 'Could not create address');
return;
}
glideraService.getSellAddress(token, function(error, sellAddress) {
if (!sellAddress) {
- self.loading = null;
+ ongoingProcess.clear();
self.error = 'Could not get the destination bitcoin address';
return;
}
@@ -133,9 +134,8 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
}
};
- self.loading = 'Creating transaction...';
walletService.createTx(client, txp, function(err, createdTxp) {
- self.loading = null;
+ ongoingProcess.clear();
if (err) {
self.error = err.message || bwsError.msg(err);
return;
@@ -154,11 +154,10 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
return;
}
- self.loading = 'Signing transaction...';
-
+ ongoingProcess.set('signingTx', true);
walletService.publishTx(client, createdTxp, function(err, publishedTxp) {
if (err) {
- self.loading = null;
+ ongoingProcess.clear();
self.error = err.message || bwsError.msg(err);
}
@@ -167,8 +166,8 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
walletService.removeTx(client, signedTxp, function(err) {
if (err) $log.debug(err);
});
+ ongoingProcess.clear();
if (err) {
- self.loading = null;
self.error = err.message || bwsError.msg(err);
return;
}
@@ -180,9 +179,9 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
useCurrentPrice: self.sellPrice.priceUuid ? false : true,
ip: null
};
- self.loading = 'Selling bitcoin...';
+ ongoingProcess.set('Seling Bitcoin', true);
glideraService.sell(token, twoFaCode, data, function(err, data) {
- self.loading = null;
+ ongoingProcess.clear();
if (err) {
self.error = err.message || bwsError.msg(err);
$timeout(function() {
diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js
index d3bb4f61d..91a4640b0 100644
--- a/src/js/controllers/walletHome.js
+++ b/src/js/controllers/walletHome.js
@@ -1,6 +1,6 @@
'use strict';
-angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, $ionicModal, notification, txStatus, profileService, lodash, configService, rateService, storageService, bitcore, gettext, gettextCatalog, platformInfo, addressService, ledger, bwsError, confirmDialog, txFormatService, addressbookService, go, feeService, walletService, fingerprintService, nodeWebkit) {
+angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, $ionicModal, notification, txStatus, profileService, lodash, configService, rateService, storageService, bitcore, gettext, gettextCatalog, platformInfo, addressService, ledger, bwsError, confirmDialog, txFormatService, addressbookService, go, feeService, walletService, fingerprintService, nodeWebkit, ongoingProcess) {
var isCordova = platformInfo.isCordova;
var isWP = platformInfo.isWP;
@@ -93,10 +93,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
};
});
- var disableOngoingProcessListener = $rootScope.$on('Addon/OngoingProcess', function(e, name) {
- self.setOngoingProcess(name);
- });
-
$scope.$on('$destroy', function() {
disableAddrListener();
disableScannerListener();
@@ -104,7 +100,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
disableTabListener();
disableFocusListener();
disableResumeListener();
- disableOngoingProcessListener();
$rootScope.shouldHideMenuBar = false;
});
@@ -398,26 +393,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}, 1);
};
- // subscription
- this.setOngoingProcess = function(name) {
- var self = this;
- self.blockUx = !!name;
-
- if (isCordova) {
- if (name) {
- window.plugins.spinnerDialog.hide();
- window.plugins.spinnerDialog.show(null, name + '...', true);
- } else {
- window.plugins.spinnerDialog.hide();
- }
- } else {
- self.onGoingProcess = name;
- $timeout(function() {
- $rootScope.$apply();
- });
- };
- };
-
this.submitForm = function() {
if (!$scope._amount || !$scope._address) return;
var client = profileService.focusedClient;
@@ -473,9 +448,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
txp.excludeUnconfirmedUtxos = configWallet.spendUnconfirmed ? false : true;
txp.feeLevel = walletSettings.feeLevel || 'normal';
- self.setOngoingProcess(gettextCatalog.getString('Creating transaction'));
+ ongoingProcess.set('creatingTx', true);
walletService.createTx(client, txp, function(err, createdTxp) {
- self.setOngoingProcess();
+ ongoingProcess.set('creatingTx', false);
if (err) {
return self.setSendError(err);
}
@@ -511,16 +486,16 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
return self.setSendError(err);
}
- self.setOngoingProcess(gettextCatalog.getString('Sending transaction'));
+ ongoingProcess.set('sendingTx', true);
walletService.publishTx(client, txp, function(err, publishedTxp) {
if (err) {
- self.setOngoingProcess();
+ ongoingProcess.set('sendingTx', false);
return self.setSendError(err);
}
- self.setOngoingProcess(gettextCatalog.getString('Signing transaction'));
+ ongoingProcess.set('signingTx', true);
walletService.signTx(client, publishedTxp, function(err, signedTxp) {
- self.setOngoingProcess();
+ ongoingProcess.set('signingTx', false);
walletService.lock(client);
if (err) {
$scope.$emit('Local/TxProposalAction');
@@ -531,9 +506,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}
if (signedTxp.status == 'accepted') {
- self.setOngoingProcess(gettextCatalog.getString('Broadcasting transaction'));
+ ongoingProcess.set('broadcastingTx', true);
walletService.broadcastTx(client, signedTxp, function(err, broadcastedTxp) {
- self.setOngoingProcess();
+ ongoingProcess.set('broadcastingTx', false);
if (err) {
return self.setSendError(err);
}
@@ -652,14 +627,14 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var satToUnit = 1 / this.unitToSatoshi;
var self = this;
/// Get information of payment if using Payment Protocol
- self.setOngoingProcess(gettextCatalog.getString('Fetching Payment Information'));
+ ongoingProcess.set('fetchingPayPro', true);
$log.debug('Fetch PayPro Request...', uri);
$timeout(function() {
fc.fetchPayPro({
payProUrl: uri,
}, function(err, paypro) {
- self.setOngoingProcess();
+ ongoingProcess.set('fetchingPayPro', false);
if (err) {
$log.warn('Could not fetch payment request:', err);
@@ -836,11 +811,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var self = this;
var fc = profileService.focusedClient;
this.error = null;
- this.setOngoingProcess(gettextCatalog.getString('Calculating fee'));
+ ongoingProcess.set('calculatingFee', true);
feeService.getCurrentFeeValue(function(err, feePerKb) {
+ ongoingProcess.set('calculatingFee', false);
if (err || !lodash.isNumber(feePerKb)) {
- self.setOngoingProcess();
self.error = gettext('Could not get fee value');
return;
}
@@ -850,10 +825,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
opts.returnInputs = true;
var config = configService.getSync();
opts.excludeUnconfirmedUtxos = !config.wallet.spendUnconfirmed;
- self.setOngoingProcess(gettextCatalog.getString('Retrieving inputs information'));
+ ongoingProcess.set('retrivingInputs', true);
fc.getSendMaxInfo(opts, function(err, resp) {
- self.setOngoingProcess();
+ ongoingProcess.set('retrivingInputs', false);
+
if (err) {
self.error = err;
$scope.$apply();
diff --git a/src/js/services/onGoingProcess.js b/src/js/services/onGoingProcess.js
new file mode 100644
index 000000000..6208660b7
--- /dev/null
+++ b/src/js/services/onGoingProcess.js
@@ -0,0 +1,75 @@
+'use strict';
+
+angular.module('copayApp.services').factory('ongoingProcess', function($log, $timeout, lodash, $ionicLoading, gettextCatalog, platformInfo) {
+ var root = {};
+ var isCordova = platformInfo.isCordova;
+
+ var ongoingProcess = {};
+
+ var processNames = {
+ 'openingWallet': gettextCatalog.getString('Updating Wallet...'),
+ 'updatingStatus': gettextCatalog.getString('Updating Wallet...'),
+ 'updatingBalance': gettextCatalog.getString('Updating Wallet...'),
+ 'updatingPendingTxps': gettextCatalog.getString('Updating Wallet...'),
+ 'scanning': gettextCatalog.getString('Scanning Wallet funds...'),
+ 'recreating': gettextCatalog.getString('Recreating Wallet...'),
+ 'generatingCSV': gettextCatalog.getString('Generating .csv file...'),
+ 'creatingTx': gettextCatalog.getString('Creating transaction'),
+ 'sendingTx': gettextCatalog.getString('Sending transaction'),
+ 'signingTx': gettextCatalog.getString('Signing transaction'),
+ 'broadcastingTx': gettextCatalog.getString('Broadcasting transaction'),
+ 'fetchingPayPro': gettextCatalog.getString('Fetching Payment Information'),
+ 'calculatingFee': gettextCatalog.getString('Calculating fee'),
+ 'joiningWallet': gettextCatalog.getString('Joining Wallet...'),
+ 'retrivingInputs': gettextCatalog.getString('Retrieving inputs information'),
+ 'creatingWallet': gettextCatalog.getString('Creating Wallet...'),
+ 'validatingWallet': gettextCatalog.getString('Validating wallet integrity...'),
+ 'connectingledger': gettextCatalog.getString('Waiting for Ledger...'),
+ 'connectingtrezor': gettextCatalog.getString('Waiting for Trezor...'),
+ 'validatingWords': gettextCatalog.getString('Validating recovery phrase...'),
+ 'connectingCoinbase': gettextCatalog.getString('Connecting to Coinbase...'),
+ 'connectingGlidera': gettextCatalog.getString('Connecting to Glidera...'),
+ 'importingWallet': gettextCatalog.getString('Importing Wallet...'),
+ 'sweepingWallet': gettextCatalog.getString('Sweeping Wallet...'),
+ 'deletingWallet': gettextCatalog.getString('Deleting Wallet...'),
+ };
+
+ root.clear = function() {
+ ongoingProcess = {};
+ };
+
+ root.set = function(processName, isOn) {
+ $log.debug('ongoingProcess', processName, isOn);
+ root[processName] = isOn;
+ ongoingProcess[processName] = isOn;
+
+ var name;
+ root.any = lodash.any(ongoingProcess, function(isOn, processName) {
+ if (isOn)
+ name = name || processName;
+ return isOn;
+ });
+ // The first one
+ root.onGoingProcessName = name;
+
+ var showName = processNames[name] || gettextCatalog.getString(name);
+
+ if (root.onGoingProcessName) {
+ if (isCordova) {
+ window.plugins.spinnerDialog.show(null, showName, true);
+ } else {
+ $ionicLoading.show({
+ template: showName,
+ });
+ }
+ } else {
+ if (isCordova) {
+ window.plugins.spinnerDialog.hide();
+ } else {
+ $ionicLoading.hide();
+ }
+ }
+ };
+
+ return root;
+});
diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js
index 39d5d33f0..6daf48900 100644
--- a/src/js/services/profileService.js
+++ b/src/js/services/profileService.js
@@ -329,7 +329,7 @@ angular.module('copayApp.services')
return cb(null, walletClient, secret);
});
});
- }, 5);
+ }, 50);
};
// Creates the default Copay profile and its wallet
diff --git a/test/controllers/create.test.js b/test/controllers/create.test.js
index 8010fde85..bc908cf87 100644
--- a/test/controllers/create.test.js
+++ b/test/controllers/create.test.js
@@ -117,6 +117,7 @@ describe('createController', function() {
it('should create a 1-1 wallet from mnemonic', function(done) {
var fakeForm = {};
+console.log('[create.test.js.119]'); //TODO
// FROM DATA
scope.seedSource = {
id: 'set'
@@ -131,8 +132,12 @@ describe('createController', function() {
scope._walletPrivKey = 'Kz4CFSTgLzoYfMkt97BTBotUbZYXjMts6Ej9HbVfCf5oLmun1BXy';
ctrl.setSeedSource();
+
+console.log('[create.test.js.135]'); //TODO
ctrl.create(fakeForm);
+console.log('[create.test.js.138]'); //TODO
+
should.not.exist(ctrl.error);
mocks.go.walletHome.calledOnce.should.equal(true);
//
diff --git a/test/controllers/disclaimer.test.js b/test/controllers/disclaimer.test.js
index 52452b026..c508d35a8 100644
--- a/test/controllers/disclaimer.test.js
+++ b/test/controllers/disclaimer.test.js
@@ -74,7 +74,8 @@ describe('disclaimerController', function() {
mnemonic: 'tunnel fork scare industry noble snow tank bullet over gesture nuclear next',
});
setTimeout(function() {
- ctrl.creatingProfile.should.equal(false);
+ mocks.ongoingProcess.set.getCall(1).args[0].should.equal('creatingWallet');
+ mocks.ongoingProcess.set.getCall(1).args[1].should.equal(false);
done();
}, 100);
});
diff --git a/test/helpers.js b/test/helpers.js
index 001a164d3..ab3effb29 100644
--- a/test/helpers.js
+++ b/test/helpers.js
@@ -42,6 +42,10 @@ mocks.$timeout = function(cb) {
};
mocks.modal = function() {};
+mocks.ongoingProcess = {
+ set: sinon.stub(),
+ clear: sinon.stub(),
+};
mocks.setProfile = function(profile) {};
@@ -192,6 +196,7 @@ mocks.init = function(fixtures, controllerName, opts, done) {
ctrl = $controller(controllerName, {
$scope: scope,
$modal: mocks.modal,
+ ongoingProcess: mocks.ongoingProcess,
notification: mocks.notification,
configService: _configService_,
profileService: _profileService_,