From 8e928646276f5a4e82d660d36d54bdd40d334baa Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 13 Nov 2014 16:32:26 -0300 Subject: [PATCH 1/4] pointing to new Insight api for retrieving txs --- js/models/Insight.js | 36 ++++++------------------------------ test/blockchain.Insight.js | 23 +++++------------------ 2 files changed, 11 insertions(+), 48 deletions(-) diff --git a/js/models/Insight.js b/js/models/Insight.js index 439aced7f..b62181117 100644 --- a/js/models/Insight.js +++ b/js/models/Insight.js @@ -269,39 +269,15 @@ Insight.prototype.getTransaction = function(txid, cb) { }); }; -Insight.prototype.getTransactions = function(addresses, cb) { +Insight.prototype.getTransactions = function (addresses, cb) { preconditions.shouldBeArray(addresses); preconditions.shouldBeFunction(cb); - var self = this; - if (!addresses.length) return cb(null, []); - - // Iterator: get a list of transaction ids for an address - function getTransactionIds(address, next) { - self.request('/api/addr/' + address, function(err, res, body) { - if (err || res.statusCode != 200 || !body) return next(err || res); - next(null, JSON.parse(body).transactions); - }); - } - - async.map(addresses, getTransactionIds, function then(err, txids) { - if (err) return cb(err); - - // txids it's a list of list, let's fix that: - var txidsList = txids.reduce(function(a, r) { - return r.concat(a); - }); - - // Remove duplicated txids - txidsList = txidsList.filter(function(elem, pos, self) { - return self.indexOf(elem) == pos; - }); - - // Now get the transactions for that list of txIds - async.map(txidsList, self.getTransaction.bind(self), function then(err, txs) { - if (err) return cb(err); - cb(null, txs); - }); + this.requestPost('/api/addrs/txs', { + addrs: addresses.join(',') + }, function (err, res, txs) { + if (err || res.statusCode != 200) return cb(err || res); + cb(null, txs); }); }; diff --git a/test/blockchain.Insight.js b/test/blockchain.Insight.js index 386e16bbf..9c445e51f 100644 --- a/test/blockchain.Insight.js +++ b/test/blockchain.Insight.js @@ -229,25 +229,12 @@ describe('Insight model', function() { it('should get a set of transaction by addresses', function(done) { var blockchain = new Insight(FAKE_OPTS); - sinon.stub(blockchain, "request", function(url, cb) { - var res = {statusCode: 200}; - - if (url == '/api/addr/2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM') { - return setTimeout(function() { - var body = JSON.stringify({transactions: [1, 2]}); - cb(null, res, body); - }, 0); - } - - if (url == '/api/addr/2NE9hTCffeugo5gQtfB4owq98gyTeWC56yb') { - return setTimeout(function() { - var body = JSON.stringify({transactions: [3]}); - cb(null, res, body); - }, 0); - } - + sinon.stub(blockchain, "requestPost", function(url, data, cb) { + url.should.be.equal('/api/addrs/txs'); + data.addrs.should.be.equal('2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM,2NE9hTCffeugo5gQtfB4owq98gyTeWC56yb'); setTimeout(function() { - var body = JSON.stringify({txid: '123123'}); + var res = {statusCode: 200}; + var body = [1, 2, 3]; cb(null, res, body); }, 0); }); From 16e2194377e3fd1829c598c245e9ae6e803dfd13 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 14 Nov 2014 13:11:05 -0300 Subject: [PATCH 2/4] fix reset to defaults --- js/controllers/home.js | 2 -- js/controllers/settings.js | 5 ++--- views/settings.html | 6 ------ 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/js/controllers/home.js b/js/controllers/home.js index 7ba16d389..2e529109f 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -11,8 +11,6 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc } - - if ($rootScope.fromEmailConfirmation) { $scope.confirmedEmail = true; $rootScope.fromEmailConfirmation = false; diff --git a/js/controllers/settings.js b/js/controllers/settings.js index d84270c38..7beec08ff 100644 --- a/js/controllers/settings.js +++ b/js/controllers/settings.js @@ -103,9 +103,8 @@ angular.module('copayApp.controllers').controller('SettingsController', function $scope.reset = function() { localStorage.removeItem('config'); - $location.hash('top'); - $anchorScroll(); - $scope.message= 'Settings were reset to defaults'; + // Go home reloading the application + window.location.reload(); }; }); diff --git a/views/settings.html b/views/settings.html index 4220cd522..e5a82163f 100644 --- a/views/settings.html +++ b/views/settings.html @@ -8,12 +8,6 @@

{{title|translate}}

-

- - {{message|translate}} -

-
Language +
-
-
- - + +
- + Show Hide @@ -63,15 +55,13 @@
diff --git a/views/includes/head.html b/views/includes/head.html index 7f85fecfb..1fefbec00 100644 --- a/views/includes/head.html +++ b/views/includes/head.html @@ -27,10 +27,10 @@
  • {{'Create new wallet'|translate}}
  • -
  • - {{'Join an existent wallet'|translate}}
  • -
  • - {{'Import a backup'|translate}}
  • +
  • + {{'Join shared wallet'|translate}}
  • +
  • + {{'Import wallet'|translate}}
  • {{'Profile'|translate}}
  • diff --git a/views/includes/sidebar-mobile.html b/views/includes/sidebar-mobile.html index d8eab2f92..6e5d61498 100644 --- a/views/includes/sidebar-mobile.html +++ b/views/includes/sidebar-mobile.html @@ -89,12 +89,12 @@ {{'Create new wallet' | translate }}
  • - - {{'Join an existent wallet' | translate }} + + {{'Join shared wallet' | translate }}
  • - - {{'Import a backup' | translate }} + + {{'Import wallet' | translate }}
  • From 0da641d1b8f883f9a2029586ccd1c6bc306e9651 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 14 Nov 2014 16:00:08 -0300 Subject: [PATCH 4/4] add updateIndex to model --- js/controllers/import.js | 5 +---- js/controllers/importProfile.js | 4 ++-- js/models/Identity.js | 30 +++++++++++++++++++++--------- views/importProfile.html | 8 +++++++- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/js/controllers/import.js b/js/controllers/import.js index 33fa8df23..9c802fa0c 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -36,10 +36,7 @@ angular.module('copayApp.controllers').controller('ImportController', $scope.error = 'Could not read wallet. Please check your password'; } else { controllerUtils.installWalletHandlers($scope, wallet); - updateStatus('Importing wallet - Scanning for transactions...'); - wallet.updateIndexes(function(err) { - controllerUtils.setFocusedWallet(wallet); - }); + controllerUtils.setFocusedWallet(wallet); } } ); diff --git a/js/controllers/importProfile.js b/js/controllers/importProfile.js index 358259790..a9a841a71 100644 --- a/js/controllers/importProfile.js +++ b/js/controllers/importProfile.js @@ -28,6 +28,7 @@ angular.module('copayApp.controllers').controller('ImportProfileController', passphraseConfig: config.passphraseConfig, }, function(err, iden) { if (err && !iden) { + $scope.loading = false; $scope.error = (err.toString() || '').match('BADSTR') ? 'Bad password or corrupt profile file' : 'Unknown error'; } else { var firstWallet = iden.getLastFocusedWallet(); @@ -54,14 +55,13 @@ angular.module('copayApp.controllers').controller('ImportProfileController', }; $scope.import = function(form) { + $scope.loading = true; if (form.$invalid) { $scope.loading = false; $scope.error = 'Please enter the required fields'; return; } - $rootScope.starting = true; - var backupFile = $scope.file; var backupText = form.backupText.$modelValue; var password = form.password.$modelValue; diff --git a/js/models/Identity.js b/js/models/Identity.js index 937c8e380..f516ce1e6 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -275,6 +275,9 @@ Identity.prototype.close = function(cb) { }, cb); }; + +// TODO: Add feedback function +// Identity.prototype.importWalletFromObj = function(obj, opts, cb) { var self = this; preconditions.checkArgument(cb); @@ -288,17 +291,21 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) { var w = importFunction(obj, readOpts); if (!w) return cb(new Error('Could not decrypt')); + log.debug('Wallet decryped:' + w.getName()); self._checkVersion(w.version); - self.addWallet(w); - self.bindWallet(w); - self.storeWallet(w, function(err) { - if (err) return cb(err); - - self.store({ - noWallets: true - }, function(err) { - return cb(err, w); + log.debug('Updating Indexes for wallet:' + w.getName()); + w.updateIndexes(function(err) { + log.debug('Adding wallet to profile:' + w.getName()); + self.addWallet(w); + self.bindWallet(w); + self.storeWallet(w, function(err) { + if (err) return cb(err); + self.store({ + noWallets: true + }, function(err) { + return cb(err, w); + }); }); }); }; @@ -348,11 +355,16 @@ Identity.importFromFullJson = function(str, password, opts, cb) { opts.email = email; opts.password = password; + if (!email) + return cb('BADSTR'); + var iden = new Identity(opts); json.wallets = json.wallets || {}; async.map(json.wallets, function(walletData, callback) { + if (!walletData) + return callback(); iden.importWalletFromObj(walletData, opts, function(err, w) { if (err) return callback(err); diff --git a/views/importProfile.html b/views/importProfile.html index 67c2b587a..a0ea36cef 100644 --- a/views/importProfile.html +++ b/views/importProfile.html @@ -1,6 +1,11 @@
    +
    + {{ importStatus|translate }} +
    + +
    Copay @@ -19,7 +24,7 @@
    - Choose backup file from your computer + Choose backup file @@ -57,6 +62,7 @@
    +